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
|
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLMS_MAT3_IDENTITY_INIT
GLMS_MAT3_ZERO_INIT
GLMS_MAT3_IDENTITY
GLMS_MAT3_ZERO
Functions:
CGLM_INLINE mat3s glms_mat3_copy(mat3s mat);
CGLM_INLINE mat3s glms_mat3_identity(void);
CGLM_INLINE void glms_mat3_identity_array(mat3s * __restrict mat, size_t count);
CGLM_INLINE mat3s glms_mat3_zero(void);
CGLM_INLINE mat3s glms_mat3_mul(mat3s m1, mat3s m2);
CGLM_INLINE ma3s glms_mat3_transpose(mat3s m);
CGLM_INLINE vec3s glms_mat3_mulv(mat3s m, vec3s v);
CGLM_INLINE float glms_mat3_trace(mat3s m);
CGLM_INLINE versor glms_mat3_quat(mat3s m);
CGLM_INLINE mat3s glms_mat3_scale(mat3s m, float s);
CGLM_INLINE float glms_mat3_det(mat3s mat);
CGLM_INLINE mat3s glms_mat3_inv(mat3s mat);
CGLM_INLINE mat3s glms_mat3_swap_col(mat3s mat, int col1, int col2);
CGLM_INLINE mat3s glms_mat3_swap_row(mat3s mat, int row1, int row2);
CGLM_INLINE float glms_mat3_rmc(vec3s r, mat3s m, vec3s c);
CGLM_INLINE mat3s glms_mat3_make(const float * __restrict src);
CGLM_INLINE mat3s glms_mat3_textrans(float sx, float sy, float rot, float tx, float ty);
*/
#ifndef cglms_mat3s_h
#define cglms_mat3s_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat3.h"
#include "vec3.h"
/* api definition */
#define glms_mat3_(NAME) CGLM_STRUCTAPI(mat3, NAME)
#define GLMS_MAT3_IDENTITY_INIT {GLM_MAT3_IDENTITY_INIT}
#define GLMS_MAT3_ZERO_INIT {GLM_MAT3_ZERO_INIT}
/* for C only */
#define GLMS_MAT3_IDENTITY ((mat3s)GLMS_MAT3_IDENTITY_INIT)
#define GLMS_MAT3_ZERO ((mat3s)GLMS_MAT3_ZERO_INIT)
/*!
* @brief copy all members of [mat] to [dest]
*
* @param[in] mat source
* @returns destination
*/
CGLM_INLINE
mat3s
glms_mat3_(copy)(mat3s mat) {
mat3s r;
glm_mat3_copy(mat.raw, r.raw);
return r;
}
/*!
* @brief make given matrix identity. It is identical with below,
* but it is more easy to do that with this func especially for members
* e.g. glm_mat3_identity(aStruct->aMatrix);
*
* @code
* glm_mat3_copy(GLM_MAT3_IDENTITY, mat); // C only
*
* // or
* mat3 mat = GLM_MAT3_IDENTITY_INIT;
* @endcode
*
* @returns destination
*/
CGLM_INLINE
mat3s
glms_mat3_(identity)(void) {
mat3s r;
glm_mat3_identity(r.raw);
return r;
}
/*!
* @brief make given matrix array's each element identity matrix
*
* @param[in, out] mat matrix array (must be aligned (16/32)
* if alignment is not disabled)
*
* @param[in] count count of matrices
*/
CGLM_INLINE
void
glms_mat3_(identity_array)(mat3s * __restrict mat, size_t count) {
CGLM_ALIGN_MAT mat3s t = GLMS_MAT3_IDENTITY_INIT;
size_t i;
for (i = 0; i < count; i++) {
glm_mat3_copy(t.raw, mat[i].raw);
}
}
/*!
* @brief make given matrix zero.
*
* @returns matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(zero)(void) {
mat3s r;
glm_mat3_zero(r.raw);
return r;
}
/*!
* @brief multiply m1 and m2 to dest
*
* m1, m2 and dest matrices can be same matrix, it is possible to write this:
*
* @code
* mat3 m = GLM_MAT3_IDENTITY_INIT;
* r = glms_mat3_mul(m, m);
* @endcode
*
* @param[in] m1 left matrix
* @param[in] m2 right matrix
* @returns destination matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(mul)(mat3s m1, mat3s m2) {
mat3s r;
glm_mat3_mul(m1.raw, m2.raw, r.raw);
return r;
}
/*!
* @brief transpose mat3 and store result in same matrix
*
* @param[in, out] m source and dest
*/
CGLM_INLINE
mat3s
glms_mat3_(transpose)(mat3s m) {
glm_mat3_transpose(m.raw);
return m;
}
/*!
* @brief multiply mat3 with vec3 (column vector) and store in dest vector
*
* @param[in] m mat3 (left)
* @param[in] v vec3 (right, column vector)
* @returns vec3 (result, column vector)
*/
CGLM_INLINE
vec3s
glms_mat3_(mulv)(mat3s m, vec3s v) {
vec3s r;
glm_mat3_mulv(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief trace of matrix
*
* sum of the elements on the main diagonal from upper left to the lower right
*
* @param[in] m matrix
*/
CGLM_INLINE
float
glms_mat3_(trace)(mat3s m) {
return glm_mat3_trace(m.raw);
}
/*!
* @brief convert mat3 to quaternion
*
* @param[in] m rotation matrix
* @returns destination quaternion
*/
CGLM_INLINE
versors
glms_mat3_(quat)(mat3s m) {
versors r;
glm_mat3_quat(m.raw, r.raw);
return r;
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in] m matrix
* @param[in] s scalar
* @returns scaled matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(scale)(mat3s m, float s) {
glm_mat3_scale(m.raw, s);
return m;
}
/*!
* @brief mat3 determinant
*
* @param[in] mat matrix
*
* @return determinant
*/
CGLM_INLINE
float
glms_mat3_(det)(mat3s mat) {
return glm_mat3_det(mat.raw);
}
/*!
* @brief inverse mat3 and store in dest
*
* @param[in] mat matrix
* @returns inverse matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(inv)(mat3s mat) {
mat3s r;
glm_mat3_inv(mat.raw, r.raw);
return r;
}
/*!
* @brief swap two matrix columns
*
* @param[in] mat matrix
* @param[in] col1 col1
* @param[in] col2 col2
* @returns matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(swap_col)(mat3s mat, int col1, int col2) {
glm_mat3_swap_col(mat.raw, col1, col2);
return mat;
}
/*!
* @brief swap two matrix rows
*
* @param[in] mat matrix
* @param[in] row1 row1
* @param[in] row2 row2
* @returns matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(swap_row)(mat3s mat, int row1, int row2) {
glm_mat3_swap_row(mat.raw, row1, row2);
return mat;
}
/*!
* @brief helper for R (row vector) * M (matrix) * C (column vector)
*
* rmc stands for Row * Matrix * Column
*
* the result is scalar because R * M = Matrix1x3 (row vector),
* then Matrix1x3 * Vec3 (column vector) = Matrix1x1 (Scalar)
*
* @param[in] r row vector or matrix1x3
* @param[in] m matrix3x3
* @param[in] c column vector or matrix3x1
*
* @return scalar value e.g. Matrix1x1
*/
CGLM_INLINE
float
glms_mat3_(rmc)(vec3s r, mat3s m, vec3s c) {
return glm_mat3_rmc(r.raw, m.raw, c.raw);
}
/*!
* @brief Create mat3 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat3s
glms_mat3_(make)(const float * __restrict src) {
mat3s r;
glm_mat3_make(src, r.raw);
return r;
}
/*!
* @brief Create mat3 matrix from texture transform parameters
*
* @param[in] sx scale x
* @param[in] sy scale y
* @param[in] rot rotation in radians CCW/RH
* @param[in] tx translate x
* @param[in] ty translate y
* @return texture transform matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(textrans)(float sx, float sy, float rot, float tx, float ty) {
mat3s r;
glm_mat3_textrans(sx, sy, rot, tx, ty, r.raw);
return r;
}
#endif /* cglms_mat3s_h */
|