-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_linalg.h
612 lines (526 loc) · 13.9 KB
/
fix_linalg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
/* fix_linalg.h
* License: Public Domain or zlib
*
* To use this library, just include the header
* All functions are declared static inline
* #include "fix_linalg.h"
*
* Linear Algebra structs and functions (plus a bit more)
* This is mainly oriented towards gamedev
*
* TODO
* - mat2x2
* - mat3x3
* - mat4x4
* - quaternions
*/
#ifndef FIX_LINALG_H
#define FIX_LINALG_H
#ifdef _cplusplus
extern "C" {
#endif //_cplusplus
#ifndef FIX_LINALG_CUSTOM_MATH
#include <math.h>
#define fix_fabsf fabsf
#define fix_sqrtf sqrtf
#define fix_sinf sinf
#define fix_cosf cosf
#ifdef __USE_GNU
#define fix_PIf M_PIf
#else //__USE_GNU
#define fix_PIf ((float)M_PI)
#endif //__USE_GNU
#endif //FIX_LINALG_CUSTOM_MATH
// Extra
// DEG-RAD conversion
static inline float fix_deg2rad(float degrees)
{
return degrees * (fix_PIf / 180.0f);
}
static inline float fix_rad2deg(float radians)
{
return radians * (180.0f / fix_PIf);
}
// Vec2
union fix_vec2_u
{
struct {float x, y;};
struct {float w, h;};
struct {float u, v;};
struct {float s, t;};
float axes[2];
};
typedef union fix_vec2_u fix_vec2;
static inline fix_vec2 fix_vec2_add(fix_vec2 lhs, fix_vec2 rhs)
{
return (fix_vec2)
{{
lhs.x + rhs.x,
lhs.y + rhs.y
}};
}
static inline fix_vec2 fix_vec2_sub(fix_vec2 lhs, fix_vec2 rhs)
{
return (fix_vec2)
{{
lhs.x - rhs.x,
lhs.y - rhs.y
}};
}
static inline fix_vec2 fix_vec2_mul(fix_vec2 lhs, fix_vec2 rhs)
{
return (fix_vec2)
{{
lhs.x * rhs.x,
lhs.y * rhs.y
}};
}
static inline fix_vec2 fix_vec2_mulf(fix_vec2 lhs, float rhs)
{
return (fix_vec2)
{{
lhs.x * rhs,
lhs.y * rhs
}};
}
#define fix_vec2_scale fix_vec2_mulf
static inline fix_vec2 fix_vec2_div(fix_vec2 lhs, fix_vec2 rhs)
{
return (fix_vec2)
{{
lhs.x / rhs.x,
lhs.y / rhs.y
}};
}
static inline float fix_vec2_dot(fix_vec2 lhs, fix_vec2 rhs)
{
return lhs.x * rhs.x + lhs.y * rhs.y;
}
static inline fix_vec2 fix_vec2_normalise(fix_vec2 vec)
{
return fix_vec2_mulf(vec, 1.0f / fix_sqrtf(vec.x * vec.x + vec.y * vec.y));
}
static inline float fix_vec2_mag(fix_vec2 vec)
{
return fix_sqrtf(vec.x * vec.x + vec.y * vec.y);
}
#define fix_vec2_len fix_vec2_mag
static inline float fix_vec2_distance(fix_vec2 lhs, fix_vec2 rhs)
{
return fix_vec2_mag(fix_vec2_sub(rhs, lhs));
}
static inline fix_vec2 fix_vec2_rot(fix_vec2 vec, float angle)
{
float sin_angle = fix_sinf(angle);
float cos_angle = fix_cosf(angle);
return (fix_vec2)
{{
vec.x * cos_angle - vec.y * sin_angle,
vec.x * sin_angle + vec.y * cos_angle
}};
}
// Vec3
union fix_vec3_u
{
struct {float x, y, z;};
struct {float u, v, w;};
struct {float r, g, b;};
struct {fix_vec2 xy; float _z;};
struct {float _x; fix_vec2 yz;};
struct {fix_vec2 uv; float _w;};
struct {float _u; fix_vec2 vw;};
struct {fix_vec2 rg; float _b;};
struct {float _r; fix_vec2 gb;};
float axes[3];
};
typedef union fix_vec3_u fix_vec3;
typedef union fix_vec3_u fix_rgb;
static inline fix_vec3 fix_vec3_add(fix_vec3 lhs, fix_vec3 rhs)
{
return (fix_vec3)
{{
lhs.x + rhs.x,
lhs.y + rhs.y,
lhs.z + rhs.z
}};
}
static inline fix_vec3 fix_vec3_sub(fix_vec3 lhs, fix_vec3 rhs)
{
return (fix_vec3)
{{
lhs.x - rhs.x,
lhs.y - rhs.y,
lhs.z - rhs.z
}};
}
static inline fix_vec3 fix_vec3_mul(fix_vec3 lhs, fix_vec3 rhs)
{
return (fix_vec3)
{{
lhs.x * rhs.x,
lhs.y * rhs.y,
lhs.z * rhs.z
}};
}
static inline fix_vec3 fix_vec3_mulf(fix_vec3 lhs, float rhs)
{
return (fix_vec3)
{{
lhs.x * rhs,
lhs.y * rhs,
lhs.z * rhs
}};
}
#define fix_vec3_scale fix_vec3_mulf
static inline fix_vec3 fix_vec3_div(fix_vec3 lhs, fix_vec3 rhs)
{
return (fix_vec3)
{{
lhs.x / rhs.x,
lhs.y / rhs.y,
lhs.z / rhs.z
}};
}
static inline float fix_vec3_dot(fix_vec3 lhs, fix_vec3 rhs)
{
return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
}
static inline fix_vec3 fix_vec3_normalise(fix_vec3 vec)
{
return fix_vec3_mulf(vec, 1.0f / fix_sqrtf(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z));
}
static inline float fix_vec3_mag(fix_vec3 vec)
{
return fix_sqrtf(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
}
#define fix_vec3_len fix_vec3_mag
static inline float fix_vec3_distance(fix_vec3 lhs, fix_vec3 rhs)
{
return fix_vec3_mag(fix_vec3_sub(rhs, lhs));
}
static inline fix_vec3 fix_vec3_cross(fix_vec3 lhs, fix_vec3 rhs)
{
return (fix_vec3)
{{
lhs.y * rhs.z - lhs.z * rhs.y,
lhs.z * rhs.x - lhs.x * rhs.z,
lhs.x * rhs.y - lhs.y * rhs.y,
}};
}
// Vec4
union fix_vec4_u
{
struct {float x, y, z, w;};
struct {float r, g, b, a;};
struct {fix_vec2 xy; fix_vec2 zw;};
struct {float _x; fix_vec2 yz; float _w;};
struct {fix_vec3 xyz; float __w;};
struct {float __x; fix_vec3 yzw;};
struct {fix_vec3 rgb; float _a;};
struct {fix_vec2 rg; fix_vec2 ba;};
struct {float _r; fix_vec2 gb; float __a;};
float axes[4];
};
typedef union fix_vec4_u fix_vec4;
typedef union fix_vec4_u fix_rgba;
static inline fix_vec4 fix_vec4_add(fix_vec4 lhs, fix_vec4 rhs)
{
return (fix_vec4)
{{
lhs.x + rhs.x,
lhs.y + rhs.y,
lhs.z + rhs.z,
lhs.w + rhs.w
}};
}
static inline fix_vec4 fix_vec4_sub(fix_vec4 lhs, fix_vec4 rhs)
{
return (fix_vec4)
{{
lhs.x - rhs.x,
lhs.y - rhs.y,
lhs.z - rhs.z,
lhs.w - rhs.w
}};
}
static inline fix_vec4 fix_vec4_mul(fix_vec4 lhs, fix_vec4 rhs)
{
return (fix_vec4)
{{
lhs.x * rhs.x,
lhs.y * rhs.y,
lhs.z * rhs.z,
lhs.w * rhs.w
}};
}
static inline fix_vec4 fix_vec4_mulf(fix_vec4 lhs, float rhs)
{
return (fix_vec4)
{{
lhs.x * rhs,
lhs.y * rhs,
lhs.z * rhs,
lhs.w * rhs,
}};
}
#define fix_vec4_scale fix_vec4_mulf
static inline fix_vec4 fix_vec4_div(fix_vec4 lhs, fix_vec4 rhs)
{
return (fix_vec4)
{{
lhs.x / rhs.x,
lhs.y / rhs.y,
lhs.z / rhs.z,
lhs.w / rhs.w
}};
}
static inline float fix_vec4_dot(fix_vec4 lhs, fix_vec4 rhs)
{
return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z + lhs.w * rhs.w;
}
static inline fix_vec4 fix_vec4_normalise(fix_vec4 vec)
{
return fix_vec4_mulf(vec, 1.0f / fix_sqrtf(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + vec.w * vec.w));
}
static inline float fix_vec4_mag(fix_vec4 vec)
{
return fix_sqrtf(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + vec.w * vec.w);
}
#define fix_vec4_len fix_vec4_mag
static inline float fix_vec4_distance(fix_vec4 lhs, fix_vec4 rhs)
{
return fix_vec4_mag(fix_vec4_sub(rhs, lhs));
}
// Mat2
union fix_mat2x2_u
{
struct {float m1, m2,
m3, m4;};
fix_vec2 columns[2];
float fields[2][2];
float m[2 * 2];
};
typedef union fix_mat2x2_u fix_mat2x2;
typedef union fix_mat2x2_u fix_mat2;
static inline fix_mat2 fix_mat2_add(fix_mat2 lhs, fix_mat2 rhs)
{
return (fix_mat2)
{{
lhs.m[0] + rhs.m[0], lhs.m[1] + rhs.m[1],
lhs.m[2] + rhs.m[2], lhs.m[3] + rhs.m[3],
}};
}
static inline fix_mat2 fix_mat2_sub(fix_mat2 lhs, fix_mat2 rhs)
{
return (fix_mat2)
{{
lhs.m[0] - rhs.m[0], lhs.m[1] - rhs.m[1],
lhs.m[2] - rhs.m[2], lhs.m[3] - rhs.m[3],
}};
}
static inline fix_mat2 fix_mat2_mul(fix_mat2 lhs, fix_mat2 rhs)
{
return (fix_mat2)
{{
lhs.m[0] * rhs.m[0] + lhs.m[1] * rhs.m[2],
lhs.m[0] * rhs.m[1] + lhs.m[1] * rhs.m[3],
lhs.m[2] * rhs.m[0] + lhs.m[3] * rhs.m[2],
lhs.m[2] * rhs.m[1] + lhs.m[3] * rhs.m[3],
}};
}
static inline fix_mat2 fix_mat2_mulf(fix_mat2 lhs, float rhs)
{
return (fix_mat2)
{{
lhs.m[0] * rhs, lhs.m[1] * rhs,
lhs.m[2] * rhs, lhs.m[3] * rhs,
}};
}
#define fix_mat2_scale fix_mat2_mulf
// Mat3
union fix_mat3x3_u
{
struct {float m1, m2, m3,
m4, m5, m6,
m7, m8, m9;};
fix_vec3 columns[3];
float fields[3][3];
float m[3 * 3];
};
typedef union fix_mat3x3_u fix_mat3x3;
typedef union fix_mat3x3_u fix_mat3;
static inline fix_mat3 fix_mat3_add(fix_mat3 lhs, fix_mat3 rhs)
{
return (fix_mat3)
{{
lhs.m[0] + rhs.m[0], lhs.m[1] + rhs.m[1], lhs.m[2] + rhs.m[2],
lhs.m[3] + rhs.m[3], lhs.m[4] + rhs.m[4], lhs.m[5] + rhs.m[5],
lhs.m[6] + rhs.m[6], lhs.m[7] + rhs.m[7], lhs.m[8] + rhs.m[8],
}};
}
static inline fix_mat3 fix_mat3_sub(fix_mat3 lhs, fix_mat3 rhs)
{
return (fix_mat3)
{{
lhs.m[0] - rhs.m[0], lhs.m[1] - rhs.m[1], lhs.m[2] - rhs.m[2],
lhs.m[3] - rhs.m[3], lhs.m[4] - rhs.m[4], lhs.m[5] - rhs.m[5],
lhs.m[6] - rhs.m[6], lhs.m[7] - rhs.m[7], lhs.m[8] - rhs.m[8],
}};
}
static inline fix_mat3 fix_mat3_mul(fix_mat3 lhs, fix_mat3 rhs)
{
return (fix_mat3)
{{
lhs.m[0] * rhs.m[0] + lhs.m[1] * rhs.m[3] + lhs.m[2] * rhs.m[6],
lhs.m[0] * rhs.m[1] + lhs.m[1] * rhs.m[4] + lhs.m[2] * rhs.m[7],
lhs.m[0] * rhs.m[2] + lhs.m[1] * rhs.m[5] + lhs.m[2] * rhs.m[8],
lhs.m[3] * rhs.m[0] + lhs.m[4] * rhs.m[3] + lhs.m[5] * rhs.m[6],
lhs.m[3] * rhs.m[1] + lhs.m[4] * rhs.m[4] + lhs.m[5] * rhs.m[7],
lhs.m[3] * rhs.m[2] + lhs.m[4] * rhs.m[5] + lhs.m[5] * rhs.m[8],
lhs.m[6] * rhs.m[0] + lhs.m[7] * rhs.m[3] + lhs.m[8] * rhs.m[6],
lhs.m[6] * rhs.m[1] + lhs.m[7] * rhs.m[4] + lhs.m[8] * rhs.m[7],
lhs.m[6] * rhs.m[2] + lhs.m[7] * rhs.m[5] + lhs.m[8] * rhs.m[8],
}};
}
static inline fix_mat3 fix_mat3_mulf(fix_mat3 lhs, float rhs)
{
return (fix_mat3)
{{
lhs.m[0] * rhs, lhs.m[1] * rhs, lhs.m[2] * rhs,
lhs.m[3] * rhs, lhs.m[4] * rhs, lhs.m[5] * rhs,
lhs.m[6] * rhs, lhs.m[7] * rhs, lhs.m[8] * rhs,
}};
}
#define fix_mat3_scale fix_mat3_mulf
// Mat4
union fix_mat4x4_u
{
struct {float m1, m2, m3, m4,
m5, m6, m7, m8,
m9, m10, m11, m12,
m13, m14, m15, m16;};
fix_vec4 columns[4];
float fields[4][4];
float m[4 * 4];
};
typedef union fix_mat4x4_u fix_mat4x4;
typedef union fix_mat4x4_u fix_mat4;
static inline fix_mat4 fix_mat4_add(fix_mat4 lhs, fix_mat4 rhs)
{
return (fix_mat4)
{{
lhs.m[0] + rhs.m[0], lhs.m[1] + rhs.m[1], lhs.m[2] + rhs.m[2], lhs.m[3] + rhs.m[3],
lhs.m[4] + rhs.m[4], lhs.m[5] + rhs.m[5], lhs.m[6] + rhs.m[6], lhs.m[7] + rhs.m[7],
lhs.m[8] + rhs.m[8], lhs.m[9] + rhs.m[9], lhs.m[10] + rhs.m[10], lhs.m[11] + rhs.m[11],
lhs.m[12] + rhs.m[12], lhs.m[13] + rhs.m[13], lhs.m[14] + rhs.m[14], lhs.m[15] + rhs.m[15],
}};
}
static inline fix_mat4 fix_mat4_sub(fix_mat4 lhs, fix_mat4 rhs)
{
return (fix_mat4)
{{
lhs.m[0] - rhs.m[0], lhs.m[1] - rhs.m[1], lhs.m[2] - rhs.m[2], lhs.m[3] - rhs.m[3],
lhs.m[4] - rhs.m[4], lhs.m[5] - rhs.m[5], lhs.m[6] - rhs.m[6], lhs.m[7] - rhs.m[7],
lhs.m[8] - rhs.m[8], lhs.m[9] - rhs.m[9], lhs.m[10] - rhs.m[10], lhs.m[11] - rhs.m[11],
lhs.m[12] - rhs.m[12], lhs.m[13] - rhs.m[13], lhs.m[14] - rhs.m[14], lhs.m[15] - rhs.m[15],
}};
}
static inline fix_mat4 fix_mat4_mul(fix_mat4 lhs, fix_mat4 rhs)
{
return (fix_mat4)
{{
lhs.m[0] * rhs.m[0] + lhs.m[1] * rhs.m[4] + lhs.m[2] * rhs.m[8] + lhs.m[3] * rhs.m[12],
lhs.m[0] * rhs.m[1] + lhs.m[1] * rhs.m[5] + lhs.m[2] * rhs.m[9] + lhs.m[3] * rhs.m[13],
lhs.m[0] * rhs.m[2] + lhs.m[1] * rhs.m[6] + lhs.m[2] * rhs.m[10] + lhs.m[3] * rhs.m[14],
lhs.m[0] * rhs.m[3] + lhs.m[1] * rhs.m[7] + lhs.m[2] * rhs.m[11] + lhs.m[3] * rhs.m[15],
lhs.m[4] * rhs.m[0] + lhs.m[5] * rhs.m[4] + lhs.m[6] * rhs.m[8] + lhs.m[7] * rhs.m[12],
lhs.m[4] * rhs.m[1] + lhs.m[5] * rhs.m[5] + lhs.m[6] * rhs.m[9] + lhs.m[7] * rhs.m[13],
lhs.m[4] * rhs.m[2] + lhs.m[5] * rhs.m[6] + lhs.m[6] * rhs.m[10] + lhs.m[7] * rhs.m[14],
lhs.m[4] * rhs.m[3] + lhs.m[5] * rhs.m[7] + lhs.m[6] * rhs.m[11] + lhs.m[7] * rhs.m[15],
lhs.m[8] * rhs.m[0] + lhs.m[9] * rhs.m[4] + lhs.m[10] * rhs.m[8] + lhs.m[11] * rhs.m[12],
lhs.m[8] * rhs.m[1] + lhs.m[9] * rhs.m[5] + lhs.m[10] * rhs.m[9] + lhs.m[11] * rhs.m[13],
lhs.m[8] * rhs.m[2] + lhs.m[9] * rhs.m[6] + lhs.m[10] * rhs.m[10] + lhs.m[11] * rhs.m[14],
lhs.m[8] * rhs.m[3] + lhs.m[9] * rhs.m[7] + lhs.m[10] * rhs.m[11] + lhs.m[11] * rhs.m[15],
lhs.m[12] * rhs.m[0] + lhs.m[13] * rhs.m[4] + lhs.m[14] * rhs.m[8] + lhs.m[15] * rhs.m[12],
lhs.m[12] * rhs.m[1] + lhs.m[13] * rhs.m[5] + lhs.m[14] * rhs.m[9] + lhs.m[15] * rhs.m[13],
lhs.m[12] * rhs.m[2] + lhs.m[13] * rhs.m[6] + lhs.m[14] * rhs.m[10] + lhs.m[15] * rhs.m[14],
lhs.m[12] * rhs.m[3] + lhs.m[13] * rhs.m[7] + lhs.m[14] * rhs.m[11] + lhs.m[15] * rhs.m[15],
}};
}
static inline fix_mat4 fix_mat4_mulf(fix_mat4 lhs, float rhs)
{
return (fix_mat4)
{{
lhs.m[0] * rhs, lhs.m[1] * rhs, lhs.m[2] * rhs, lhs.m[3] * rhs,
lhs.m[4] * rhs, lhs.m[5] * rhs, lhs.m[6] * rhs, lhs.m[7] * rhs,
lhs.m[8] * rhs, lhs.m[9] * rhs, lhs.m[10] * rhs, lhs.m[11] * rhs,
lhs.m[12] * rhs, lhs.m[13] * rhs, lhs.m[14] * rhs, lhs.m[15] * rhs,
}};
}
#define fix_mat4_scale fix_mat4_mulf
static inline fix_mat4 fix_mat4_ortho(float left, float right, float bottom, float top, float near, float far)
{
return (fix_mat4)
{{
2.0f / (right - left), 0.0f, 0.0f, -(right + left) / (right - left),
0.0f, 2.0f / (top - bottom), 0.0f, -(top + bottom) / (top - bottom),
0.0f, 0.0f, -2.0f / (far - near), -(far + near) / (far - near),
0.0f, 0.0f, 0.0f, 1.0f,
}};
}
static inline fix_mat4 fix_mat4_perspective(float fov_y, float aspect, float near, float far)
{
float f = 1.0f / tanf(fov_y / 2.0f);
return (fix_mat4)
{{
f / aspect, 0.0f, 0.0f, 0.0f,
0.0f, f, 0.0f, 0.0f,
0.0f, 0.0f, (near + far) / (near - far), -2.0f * ((near * far) / (near - far)),
0.0f, 0.0f, -1.0f, 0.0f,
}};
}
// Extras
//Rect
union fix_rect_u
{
struct {float x, y, w, h;};
struct { fix_vec2 pos; fix_vec2 size;};
};
typedef union fix_rect_u fix_rect;
static inline int fix_rect_aabb_check(fix_rect first, fix_rect second)
{
return first.x < second.x + second.w &&
first.x + first.w > second.x &&
first.y < second.y + second.h &&
first.y + first.h > second.y;
}
static inline fix_vec2 rect_centre(fix_rect rect)
{
return (fix_vec2)
{{
(rect.x + rect.x + rect.w) * 0.5f,
(rect.y + rect.y + rect.h) * 0.5f
}};
}
// Color Conversion
#include <stdint.h>
static inline uint32_t fix_rgba2rgba32(fix_rgba c)
{
int r = c.r * 255;
int g = c.g * 255;
int b = c.b * 255;
int a = c.a * 255;
return a + (b >> 8) + (g >> 16) + (r >> 24);
}
static inline uint32_t fix_rgba2abgr32(fix_rgba c)
{
int r = c.r * 255;
int g = c.g * 255;
int b = c.b * 255;
int a = c.a * 255;
return r + (g >> 8) + (b >> 16) + (a >> 24);
}
#ifdef _cplusplus
}
#endif //_cplusplus
#endif //FIX_LINALG_H