86dd63d2ac19ddd29afc9a1baaf62574d19d72a8
[gph-cmath] / src / cgmmat.inl
1 static inline void cgm_mcopy(float *dest, const float *src)
2 {
3         memcpy(dest, src, 16 * sizeof(float));
4 }
5
6 static inline void cgm_mzero(float *m)
7 {
8         static float z[16];
9         cgm_mcopy(m, z);
10 }
11
12 static inline void cgm_midentity(float *m)
13 {
14         static float id[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
15         cgm_mcopy(m, id);
16 }
17
18 static inline void cgm_msetrow_v3(float *m, int idx, const cgm_vec3 *v)
19 {
20         m[idx] = v->x;
21         m[idx + 4] = v->y;
22         m[idx + 8] = v->z;
23         m[idx + 12] = 0.0f;
24 }
25
26 static inline void cgm_msetrow_v4(float *m, int idx, const cgm_vec4 *v)
27 {
28         m[idx] = v->x;
29         m[idx + 4] = v->y;
30         m[idx + 8] = v->z;
31         m[idx + 12] = v->w;
32 }
33
34 static inline void cgm_msetcol_v3(float *m, int idx, const cgm_vec3 *v)
35 {
36         m[idx * 4] = v->x;
37         m[idx * 4 + 1] = v->y;
38         m[idx * 4 + 2] = v->z;
39         m[idx * 4 + 3] = 0.0f;
40 }
41
42 static inline void cgm_msetcol_v4(float *m, int idx, const cgm_vec4 *v)
43 {
44         m[idx * 4] = v->x;
45         m[idx * 4 + 1] = v->y;
46         m[idx * 4 + 2] = v->z;
47         m[idx * 4 + 3] = v->w;
48 }
49
50 static inline void cgm_mgetrow_v3(cgm_vec3 *v, const float *m, int idx)
51 {
52         v->x = m[idx];
53         v->y = m[idx + 4];
54         v->z = m[idx + 8];
55 }
56
57 static inline void cgm_mgetrow_v4(cgm_vec4 *v, const float *m, int idx)
58 {
59         v->x = m[idx];
60         v->y = m[idx + 4];
61         v->z = m[idx + 8];
62         v->w = m[idx + 12];
63 }
64
65 static inline void cgm_mgetcol_v3(cgm_vec3 *v, const float *m, int idx)
66 {
67         v->x = m[idx * 4];
68         v->y = m[idx * 4 + 1];
69         v->z = m[idx * 4 + 2];
70 }
71
72 static inline void cgm_mgetcol_v4(cgm_vec4 *v, const float *m, int idx)
73 {
74         v->x = m[idx * 4];
75         v->y = m[idx * 4 + 1];
76         v->z = m[idx * 4 + 2];
77         v->w = m[idx * 4 + 3];
78 }
79
80 static inline void cgm_msubmatrix(float *m, int row, int col)
81 {
82 }
83
84 static inline void cgm_mupper3(float *m)
85 {
86         m[3] = m[7] = m[11] = m[12] = m[13] = m[14] = 0.0f;
87         m[15] = 1.0f;
88 }