cglm 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile.lock +18 -16
- data/README.md +2 -0
- data/cglm.gemspec +3 -3
- data/ext/cglm/cglm-0.6.2/include/cglm/affine-mat.h +168 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/affine.h +490 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/applesimd.h +95 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/bezier.h +154 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/box.h +279 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/affine.h +117 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/bezier.h +31 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/box.h +79 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/cam.h +143 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/curve.h +23 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/ease.h +143 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/euler.h +55 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/frustum.h +41 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/io.h +44 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/mat3.h +86 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/mat4.h +127 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/plane.h +23 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/project.h +33 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/quat.h +159 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/sphere.h +39 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/vec3.h +312 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call/vec4.h +290 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/call.h +36 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/cam.h +585 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/cglm.h +32 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/color.h +26 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/common.h +37 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/curve.h +40 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/ease.h +317 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/euler.h +453 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/frustum.h +255 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/io.h +203 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/mat3.h +422 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/mat4.h +726 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/plane.h +36 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/project.h +118 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/quat.h +828 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/arm.h +83 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/avx/affine.h +66 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/avx/mat4.h +66 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/intrin.h +90 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/neon/mat4.h +57 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/affine.h +111 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/mat3.h +59 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/mat4.h +405 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/quat.h +46 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/simd/x86.h +192 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/sphere.h +99 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/affine.h +337 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/box.h +256 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/cam.h +451 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/color.h +27 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/curve.h +40 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/euler.h +152 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/frustum.h +155 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/io.h +82 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/mat3.h +285 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/mat4.h +459 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/plane.h +40 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/project.h +104 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/quat.h +532 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/sphere.h +93 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec3-ext.h +257 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec3.h +970 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec4-ext.h +257 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec4.h +814 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/struct.h +36 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/types-struct.h +129 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/types.h +76 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/util.h +328 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/vec3-ext.h +272 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/vec3.h +1078 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/vec4-ext.h +315 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/vec4.h +1078 -0
- data/ext/cglm/cglm-0.6.2/include/cglm/version.h +15 -0
- data/ext/cglm/extconf.rb +2 -3
- data/ext/cglm/rb_cglm.h +5 -3
- data/ext/cglm/rb_cglm_mat3.c +3 -3
- data/ext/cglm/rb_cglm_mat4.c +3 -3
- data/ext/cglm/rb_cglm_quat.c +2 -2
- data/ext/cglm/rb_cglm_vec3.c +63 -61
- data/ext/cglm/rb_cglm_vec4.c +2 -0
- data/ext/cglm/ruby_pre27.h +35 -0
- data/lib/cglm/vec3.rb +2 -2
- data/lib/cglm/vec4.rb +2 -2
- data/lib/cglm/vector_type.rb +15 -0
- data/lib/cglm/version.rb +1 -1
- metadata +89 -13
@@ -0,0 +1,490 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c), Recep Aslantas.
|
3
|
+
*
|
4
|
+
* MIT License (MIT), http://opensource.org/licenses/MIT
|
5
|
+
* Full license can be found in the LICENSE file
|
6
|
+
*/
|
7
|
+
|
8
|
+
/*
|
9
|
+
Functions:
|
10
|
+
CGLM_INLINE void glm_translate_to(mat4 m, vec3 v, mat4 dest);
|
11
|
+
CGLM_INLINE void glm_translate(mat4 m, vec3 v);
|
12
|
+
CGLM_INLINE void glm_translate_x(mat4 m, float to);
|
13
|
+
CGLM_INLINE void glm_translate_y(mat4 m, float to);
|
14
|
+
CGLM_INLINE void glm_translate_z(mat4 m, float to);
|
15
|
+
CGLM_INLINE void glm_translate_make(mat4 m, vec3 v);
|
16
|
+
CGLM_INLINE void glm_scale_to(mat4 m, vec3 v, mat4 dest);
|
17
|
+
CGLM_INLINE void glm_scale_make(mat4 m, vec3 v);
|
18
|
+
CGLM_INLINE void glm_scale(mat4 m, vec3 v);
|
19
|
+
CGLM_INLINE void glm_scale_uni(mat4 m, float s);
|
20
|
+
CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest);
|
21
|
+
CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest);
|
22
|
+
CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest);
|
23
|
+
CGLM_INLINE void glm_rotate_make(mat4 m, float angle, vec3 axis);
|
24
|
+
CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis);
|
25
|
+
CGLM_INLINE void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis);
|
26
|
+
CGLM_INLINE void glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis);
|
27
|
+
CGLM_INLINE void glm_decompose_scalev(mat4 m, vec3 s);
|
28
|
+
CGLM_INLINE bool glm_uniscaled(mat4 m);
|
29
|
+
CGLM_INLINE void glm_decompose_rs(mat4 m, mat4 r, vec3 s);
|
30
|
+
CGLM_INLINE void glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s);
|
31
|
+
*/
|
32
|
+
|
33
|
+
#ifndef cglm_affine_h
|
34
|
+
#define cglm_affine_h
|
35
|
+
|
36
|
+
#include "common.h"
|
37
|
+
#include "util.h"
|
38
|
+
#include "vec3.h"
|
39
|
+
#include "vec4.h"
|
40
|
+
#include "mat4.h"
|
41
|
+
#include "affine-mat.h"
|
42
|
+
|
43
|
+
CGLM_INLINE
|
44
|
+
void
|
45
|
+
glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest);
|
46
|
+
|
47
|
+
/*!
|
48
|
+
* @brief translate existing transform matrix by v vector
|
49
|
+
* and stores result in same matrix
|
50
|
+
*
|
51
|
+
* @param[in, out] m affine transfrom
|
52
|
+
* @param[in] v translate vector [x, y, z]
|
53
|
+
*/
|
54
|
+
CGLM_INLINE
|
55
|
+
void
|
56
|
+
glm_translate(mat4 m, vec3 v) {
|
57
|
+
#if defined( __SSE__ ) || defined( __SSE2__ )
|
58
|
+
glmm_store(m[3],
|
59
|
+
_mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(m[0]),
|
60
|
+
_mm_set1_ps(v[0])),
|
61
|
+
_mm_mul_ps(glmm_load(m[1]),
|
62
|
+
_mm_set1_ps(v[1]))),
|
63
|
+
_mm_add_ps(_mm_mul_ps(glmm_load(m[2]),
|
64
|
+
_mm_set1_ps(v[2])),
|
65
|
+
glmm_load(m[3]))))
|
66
|
+
;
|
67
|
+
#else
|
68
|
+
vec4 v1, v2, v3;
|
69
|
+
|
70
|
+
glm_vec4_scale(m[0], v[0], v1);
|
71
|
+
glm_vec4_scale(m[1], v[1], v2);
|
72
|
+
glm_vec4_scale(m[2], v[2], v3);
|
73
|
+
|
74
|
+
glm_vec4_add(v1, m[3], m[3]);
|
75
|
+
glm_vec4_add(v2, m[3], m[3]);
|
76
|
+
glm_vec4_add(v3, m[3], m[3]);
|
77
|
+
#endif
|
78
|
+
}
|
79
|
+
|
80
|
+
/*!
|
81
|
+
* @brief translate existing transform matrix by v vector
|
82
|
+
* and store result in dest
|
83
|
+
*
|
84
|
+
* source matrix will remain same
|
85
|
+
*
|
86
|
+
* @param[in] m affine transfrom
|
87
|
+
* @param[in] v translate vector [x, y, z]
|
88
|
+
* @param[out] dest translated matrix
|
89
|
+
*/
|
90
|
+
CGLM_INLINE
|
91
|
+
void
|
92
|
+
glm_translate_to(mat4 m, vec3 v, mat4 dest) {
|
93
|
+
glm_mat4_copy(m, dest);
|
94
|
+
glm_translate(dest, v);
|
95
|
+
}
|
96
|
+
|
97
|
+
/*!
|
98
|
+
* @brief translate existing transform matrix by x factor
|
99
|
+
*
|
100
|
+
* @param[in, out] m affine transfrom
|
101
|
+
* @param[in] x x factor
|
102
|
+
*/
|
103
|
+
CGLM_INLINE
|
104
|
+
void
|
105
|
+
glm_translate_x(mat4 m, float x) {
|
106
|
+
#if defined( __SSE__ ) || defined( __SSE2__ )
|
107
|
+
glmm_store(m[3],
|
108
|
+
_mm_add_ps(_mm_mul_ps(glmm_load(m[0]),
|
109
|
+
_mm_set1_ps(x)),
|
110
|
+
glmm_load(m[3])))
|
111
|
+
;
|
112
|
+
#else
|
113
|
+
vec4 v1;
|
114
|
+
glm_vec4_scale(m[0], x, v1);
|
115
|
+
glm_vec4_add(v1, m[3], m[3]);
|
116
|
+
#endif
|
117
|
+
}
|
118
|
+
|
119
|
+
/*!
|
120
|
+
* @brief translate existing transform matrix by y factor
|
121
|
+
*
|
122
|
+
* @param[in, out] m affine transfrom
|
123
|
+
* @param[in] y y factor
|
124
|
+
*/
|
125
|
+
CGLM_INLINE
|
126
|
+
void
|
127
|
+
glm_translate_y(mat4 m, float y) {
|
128
|
+
#if defined( __SSE__ ) || defined( __SSE2__ )
|
129
|
+
glmm_store(m[3],
|
130
|
+
_mm_add_ps(_mm_mul_ps(glmm_load(m[1]),
|
131
|
+
_mm_set1_ps(y)),
|
132
|
+
glmm_load(m[3])))
|
133
|
+
;
|
134
|
+
#else
|
135
|
+
vec4 v1;
|
136
|
+
glm_vec4_scale(m[1], y, v1);
|
137
|
+
glm_vec4_add(v1, m[3], m[3]);
|
138
|
+
#endif
|
139
|
+
}
|
140
|
+
|
141
|
+
/*!
|
142
|
+
* @brief translate existing transform matrix by z factor
|
143
|
+
*
|
144
|
+
* @param[in, out] m affine transfrom
|
145
|
+
* @param[in] z z factor
|
146
|
+
*/
|
147
|
+
CGLM_INLINE
|
148
|
+
void
|
149
|
+
glm_translate_z(mat4 m, float z) {
|
150
|
+
#if defined( __SSE__ ) || defined( __SSE2__ )
|
151
|
+
glmm_store(m[3],
|
152
|
+
_mm_add_ps(_mm_mul_ps(glmm_load(m[2]),
|
153
|
+
_mm_set1_ps(z)),
|
154
|
+
glmm_load(m[3])))
|
155
|
+
;
|
156
|
+
#else
|
157
|
+
vec4 v1;
|
158
|
+
glm_vec4_scale(m[2], z, v1);
|
159
|
+
glm_vec4_add(v1, m[3], m[3]);
|
160
|
+
#endif
|
161
|
+
}
|
162
|
+
|
163
|
+
/*!
|
164
|
+
* @brief creates NEW translate transform matrix by v vector
|
165
|
+
*
|
166
|
+
* @param[out] m affine transfrom
|
167
|
+
* @param[in] v translate vector [x, y, z]
|
168
|
+
*/
|
169
|
+
CGLM_INLINE
|
170
|
+
void
|
171
|
+
glm_translate_make(mat4 m, vec3 v) {
|
172
|
+
glm_mat4_identity(m);
|
173
|
+
glm_vec3_copy(v, m[3]);
|
174
|
+
}
|
175
|
+
|
176
|
+
/*!
|
177
|
+
* @brief scale existing transform matrix by v vector
|
178
|
+
* and store result in dest
|
179
|
+
*
|
180
|
+
* @param[in] m affine transfrom
|
181
|
+
* @param[in] v scale vector [x, y, z]
|
182
|
+
* @param[out] dest scaled matrix
|
183
|
+
*/
|
184
|
+
CGLM_INLINE
|
185
|
+
void
|
186
|
+
glm_scale_to(mat4 m, vec3 v, mat4 dest) {
|
187
|
+
glm_vec4_scale(m[0], v[0], dest[0]);
|
188
|
+
glm_vec4_scale(m[1], v[1], dest[1]);
|
189
|
+
glm_vec4_scale(m[2], v[2], dest[2]);
|
190
|
+
|
191
|
+
glm_vec4_copy(m[3], dest[3]);
|
192
|
+
}
|
193
|
+
|
194
|
+
/*!
|
195
|
+
* @brief creates NEW scale matrix by v vector
|
196
|
+
*
|
197
|
+
* @param[out] m affine transfrom
|
198
|
+
* @param[in] v scale vector [x, y, z]
|
199
|
+
*/
|
200
|
+
CGLM_INLINE
|
201
|
+
void
|
202
|
+
glm_scale_make(mat4 m, vec3 v) {
|
203
|
+
glm_mat4_identity(m);
|
204
|
+
m[0][0] = v[0];
|
205
|
+
m[1][1] = v[1];
|
206
|
+
m[2][2] = v[2];
|
207
|
+
}
|
208
|
+
|
209
|
+
/*!
|
210
|
+
* @brief scales existing transform matrix by v vector
|
211
|
+
* and stores result in same matrix
|
212
|
+
*
|
213
|
+
* @param[in, out] m affine transfrom
|
214
|
+
* @param[in] v scale vector [x, y, z]
|
215
|
+
*/
|
216
|
+
CGLM_INLINE
|
217
|
+
void
|
218
|
+
glm_scale(mat4 m, vec3 v) {
|
219
|
+
glm_scale_to(m, v, m);
|
220
|
+
}
|
221
|
+
|
222
|
+
/*!
|
223
|
+
* @brief applies uniform scale to existing transform matrix v = [s, s, s]
|
224
|
+
* and stores result in same matrix
|
225
|
+
*
|
226
|
+
* @param[in, out] m affine transfrom
|
227
|
+
* @param[in] s scale factor
|
228
|
+
*/
|
229
|
+
CGLM_INLINE
|
230
|
+
void
|
231
|
+
glm_scale_uni(mat4 m, float s) {
|
232
|
+
CGLM_ALIGN(8) vec3 v = { s, s, s };
|
233
|
+
glm_scale_to(m, v, m);
|
234
|
+
}
|
235
|
+
|
236
|
+
/*!
|
237
|
+
* @brief rotate existing transform matrix around X axis by angle
|
238
|
+
* and store result in dest
|
239
|
+
*
|
240
|
+
* @param[in] m affine transfrom
|
241
|
+
* @param[in] angle angle (radians)
|
242
|
+
* @param[out] dest rotated matrix
|
243
|
+
*/
|
244
|
+
CGLM_INLINE
|
245
|
+
void
|
246
|
+
glm_rotate_x(mat4 m, float angle, mat4 dest) {
|
247
|
+
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
|
248
|
+
float c, s;
|
249
|
+
|
250
|
+
c = cosf(angle);
|
251
|
+
s = sinf(angle);
|
252
|
+
|
253
|
+
t[1][1] = c;
|
254
|
+
t[1][2] = s;
|
255
|
+
t[2][1] = -s;
|
256
|
+
t[2][2] = c;
|
257
|
+
|
258
|
+
glm_mul_rot(m, t, dest);
|
259
|
+
}
|
260
|
+
|
261
|
+
/*!
|
262
|
+
* @brief rotate existing transform matrix around Y axis by angle
|
263
|
+
* and store result in dest
|
264
|
+
*
|
265
|
+
* @param[in] m affine transfrom
|
266
|
+
* @param[in] angle angle (radians)
|
267
|
+
* @param[out] dest rotated matrix
|
268
|
+
*/
|
269
|
+
CGLM_INLINE
|
270
|
+
void
|
271
|
+
glm_rotate_y(mat4 m, float angle, mat4 dest) {
|
272
|
+
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
|
273
|
+
float c, s;
|
274
|
+
|
275
|
+
c = cosf(angle);
|
276
|
+
s = sinf(angle);
|
277
|
+
|
278
|
+
t[0][0] = c;
|
279
|
+
t[0][2] = -s;
|
280
|
+
t[2][0] = s;
|
281
|
+
t[2][2] = c;
|
282
|
+
|
283
|
+
glm_mul_rot(m, t, dest);
|
284
|
+
}
|
285
|
+
|
286
|
+
/*!
|
287
|
+
* @brief rotate existing transform matrix around Z axis by angle
|
288
|
+
* and store result in dest
|
289
|
+
*
|
290
|
+
* @param[in] m affine transfrom
|
291
|
+
* @param[in] angle angle (radians)
|
292
|
+
* @param[out] dest rotated matrix
|
293
|
+
*/
|
294
|
+
CGLM_INLINE
|
295
|
+
void
|
296
|
+
glm_rotate_z(mat4 m, float angle, mat4 dest) {
|
297
|
+
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
|
298
|
+
float c, s;
|
299
|
+
|
300
|
+
c = cosf(angle);
|
301
|
+
s = sinf(angle);
|
302
|
+
|
303
|
+
t[0][0] = c;
|
304
|
+
t[0][1] = s;
|
305
|
+
t[1][0] = -s;
|
306
|
+
t[1][1] = c;
|
307
|
+
|
308
|
+
glm_mul_rot(m, t, dest);
|
309
|
+
}
|
310
|
+
|
311
|
+
/*!
|
312
|
+
* @brief creates NEW rotation matrix by angle and axis
|
313
|
+
*
|
314
|
+
* axis will be normalized so you don't need to normalize it
|
315
|
+
*
|
316
|
+
* @param[out] m affine transfrom
|
317
|
+
* @param[in] angle angle (radians)
|
318
|
+
* @param[in] axis axis
|
319
|
+
*/
|
320
|
+
CGLM_INLINE
|
321
|
+
void
|
322
|
+
glm_rotate_make(mat4 m, float angle, vec3 axis) {
|
323
|
+
CGLM_ALIGN(8) vec3 axisn, v, vs;
|
324
|
+
float c;
|
325
|
+
|
326
|
+
c = cosf(angle);
|
327
|
+
|
328
|
+
glm_vec3_normalize_to(axis, axisn);
|
329
|
+
glm_vec3_scale(axisn, 1.0f - c, v);
|
330
|
+
glm_vec3_scale(axisn, sinf(angle), vs);
|
331
|
+
|
332
|
+
glm_vec3_scale(axisn, v[0], m[0]);
|
333
|
+
glm_vec3_scale(axisn, v[1], m[1]);
|
334
|
+
glm_vec3_scale(axisn, v[2], m[2]);
|
335
|
+
|
336
|
+
m[0][0] += c; m[1][0] -= vs[2]; m[2][0] += vs[1];
|
337
|
+
m[0][1] += vs[2]; m[1][1] += c; m[2][1] -= vs[0];
|
338
|
+
m[0][2] -= vs[1]; m[1][2] += vs[0]; m[2][2] += c;
|
339
|
+
|
340
|
+
m[0][3] = m[1][3] = m[2][3] = m[3][0] = m[3][1] = m[3][2] = 0.0f;
|
341
|
+
m[3][3] = 1.0f;
|
342
|
+
}
|
343
|
+
|
344
|
+
/*!
|
345
|
+
* @brief rotate existing transform matrix around given axis by angle
|
346
|
+
*
|
347
|
+
* @param[in, out] m affine transfrom
|
348
|
+
* @param[in] angle angle (radians)
|
349
|
+
* @param[in] axis axis
|
350
|
+
*/
|
351
|
+
CGLM_INLINE
|
352
|
+
void
|
353
|
+
glm_rotate(mat4 m, float angle, vec3 axis) {
|
354
|
+
CGLM_ALIGN_MAT mat4 rot;
|
355
|
+
glm_rotate_make(rot, angle, axis);
|
356
|
+
glm_mul_rot(m, rot, m);
|
357
|
+
}
|
358
|
+
|
359
|
+
/*!
|
360
|
+
* @brief rotate existing transform
|
361
|
+
* around given axis by angle at given pivot point (rotation center)
|
362
|
+
*
|
363
|
+
* @param[in, out] m affine transfrom
|
364
|
+
* @param[in] pivot rotation center
|
365
|
+
* @param[in] angle angle (radians)
|
366
|
+
* @param[in] axis axis
|
367
|
+
*/
|
368
|
+
CGLM_INLINE
|
369
|
+
void
|
370
|
+
glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) {
|
371
|
+
CGLM_ALIGN(8) vec3 pivotInv;
|
372
|
+
|
373
|
+
glm_vec3_negate_to(pivot, pivotInv);
|
374
|
+
|
375
|
+
glm_translate(m, pivot);
|
376
|
+
glm_rotate(m, angle, axis);
|
377
|
+
glm_translate(m, pivotInv);
|
378
|
+
}
|
379
|
+
|
380
|
+
/*!
|
381
|
+
* @brief creates NEW rotation matrix by angle and axis at given point
|
382
|
+
*
|
383
|
+
* this creates rotation matrix, it assumes you don't have a matrix
|
384
|
+
*
|
385
|
+
* this should work faster than glm_rotate_at because it reduces
|
386
|
+
* one glm_translate.
|
387
|
+
*
|
388
|
+
* @param[out] m affine transfrom
|
389
|
+
* @param[in] pivot rotation center
|
390
|
+
* @param[in] angle angle (radians)
|
391
|
+
* @param[in] axis axis
|
392
|
+
*/
|
393
|
+
CGLM_INLINE
|
394
|
+
void
|
395
|
+
glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) {
|
396
|
+
CGLM_ALIGN(8) vec3 pivotInv;
|
397
|
+
|
398
|
+
glm_vec3_negate_to(pivot, pivotInv);
|
399
|
+
|
400
|
+
glm_translate_make(m, pivot);
|
401
|
+
glm_rotate(m, angle, axis);
|
402
|
+
glm_translate(m, pivotInv);
|
403
|
+
}
|
404
|
+
|
405
|
+
/*!
|
406
|
+
* @brief decompose scale vector
|
407
|
+
*
|
408
|
+
* @param[in] m affine transform
|
409
|
+
* @param[out] s scale vector (Sx, Sy, Sz)
|
410
|
+
*/
|
411
|
+
CGLM_INLINE
|
412
|
+
void
|
413
|
+
glm_decompose_scalev(mat4 m, vec3 s) {
|
414
|
+
s[0] = glm_vec3_norm(m[0]);
|
415
|
+
s[1] = glm_vec3_norm(m[1]);
|
416
|
+
s[2] = glm_vec3_norm(m[2]);
|
417
|
+
}
|
418
|
+
|
419
|
+
/*!
|
420
|
+
* @brief returns true if matrix is uniform scaled. This is helpful for
|
421
|
+
* creating normal matrix.
|
422
|
+
*
|
423
|
+
* @param[in] m m
|
424
|
+
*
|
425
|
+
* @return boolean
|
426
|
+
*/
|
427
|
+
CGLM_INLINE
|
428
|
+
bool
|
429
|
+
glm_uniscaled(mat4 m) {
|
430
|
+
CGLM_ALIGN(8) vec3 s;
|
431
|
+
glm_decompose_scalev(m, s);
|
432
|
+
return glm_vec3_eq_all(s);
|
433
|
+
}
|
434
|
+
|
435
|
+
/*!
|
436
|
+
* @brief decompose rotation matrix (mat4) and scale vector [Sx, Sy, Sz]
|
437
|
+
* DON'T pass projected matrix here
|
438
|
+
*
|
439
|
+
* @param[in] m affine transform
|
440
|
+
* @param[out] r rotation matrix
|
441
|
+
* @param[out] s scale matrix
|
442
|
+
*/
|
443
|
+
CGLM_INLINE
|
444
|
+
void
|
445
|
+
glm_decompose_rs(mat4 m, mat4 r, vec3 s) {
|
446
|
+
CGLM_ALIGN(16) vec4 t = {0.0f, 0.0f, 0.0f, 1.0f};
|
447
|
+
CGLM_ALIGN(8) vec3 v;
|
448
|
+
|
449
|
+
glm_vec4_copy(m[0], r[0]);
|
450
|
+
glm_vec4_copy(m[1], r[1]);
|
451
|
+
glm_vec4_copy(m[2], r[2]);
|
452
|
+
glm_vec4_copy(t, r[3]);
|
453
|
+
|
454
|
+
s[0] = glm_vec3_norm(m[0]);
|
455
|
+
s[1] = glm_vec3_norm(m[1]);
|
456
|
+
s[2] = glm_vec3_norm(m[2]);
|
457
|
+
|
458
|
+
glm_vec4_scale(r[0], 1.0f/s[0], r[0]);
|
459
|
+
glm_vec4_scale(r[1], 1.0f/s[1], r[1]);
|
460
|
+
glm_vec4_scale(r[2], 1.0f/s[2], r[2]);
|
461
|
+
|
462
|
+
/* Note from Apple Open Source (asume that the matrix is orthonormal):
|
463
|
+
check for a coordinate system flip. If the determinant
|
464
|
+
is -1, then negate the matrix and the scaling factors. */
|
465
|
+
glm_vec3_cross(m[0], m[1], v);
|
466
|
+
if (glm_vec3_dot(v, m[2]) < 0.0f) {
|
467
|
+
glm_vec4_negate(r[0]);
|
468
|
+
glm_vec4_negate(r[1]);
|
469
|
+
glm_vec4_negate(r[2]);
|
470
|
+
glm_vec3_negate(s);
|
471
|
+
}
|
472
|
+
}
|
473
|
+
|
474
|
+
/*!
|
475
|
+
* @brief decompose affine transform, TODO: extract shear factors.
|
476
|
+
* DON'T pass projected matrix here
|
477
|
+
*
|
478
|
+
* @param[in] m affine transfrom
|
479
|
+
* @param[out] t translation vector
|
480
|
+
* @param[out] r rotation matrix (mat4)
|
481
|
+
* @param[out] s scaling vector [X, Y, Z]
|
482
|
+
*/
|
483
|
+
CGLM_INLINE
|
484
|
+
void
|
485
|
+
glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s) {
|
486
|
+
glm_vec4_copy(m[3], t);
|
487
|
+
glm_decompose_rs(m, r, s);
|
488
|
+
}
|
489
|
+
|
490
|
+
#endif /* cglm_affine_h */
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c), Recep Aslantas.
|
3
|
+
*
|
4
|
+
* MIT License (MIT), http://opensource.org/licenses/MIT
|
5
|
+
* Full license can be found in the LICENSE file
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef cglm_applesimd_h
|
9
|
+
#define cglm_applesimd_h
|
10
|
+
#if defined(__APPLE__) \
|
11
|
+
&& defined(SIMD_COMPILER_HAS_REQUIRED_FEATURES) \
|
12
|
+
&& defined(SIMD_BASE) \
|
13
|
+
&& defined(SIMD_TYPES) \
|
14
|
+
&& defined(SIMD_VECTOR_TYPES)
|
15
|
+
|
16
|
+
#include "common.h"
|
17
|
+
|
18
|
+
/*!
|
19
|
+
* @brief converts mat4 to Apple's simd type simd_float4x4
|
20
|
+
* @return simd_float4x4
|
21
|
+
*/
|
22
|
+
CGLM_INLINE
|
23
|
+
simd_float4x4
|
24
|
+
glm_mat4_applesimd(mat4 m) {
|
25
|
+
simd_float4x4 t;
|
26
|
+
|
27
|
+
t.columns[0][0] = m[0][0];
|
28
|
+
t.columns[0][1] = m[0][1];
|
29
|
+
t.columns[0][2] = m[0][2];
|
30
|
+
t.columns[0][3] = m[0][3];
|
31
|
+
|
32
|
+
t.columns[1][0] = m[1][0];
|
33
|
+
t.columns[1][1] = m[1][1];
|
34
|
+
t.columns[1][2] = m[1][2];
|
35
|
+
t.columns[1][3] = m[1][3];
|
36
|
+
|
37
|
+
t.columns[2][0] = m[2][0];
|
38
|
+
t.columns[2][1] = m[2][1];
|
39
|
+
t.columns[2][2] = m[2][2];
|
40
|
+
t.columns[2][3] = m[2][3];
|
41
|
+
|
42
|
+
t.columns[3][0] = m[3][0];
|
43
|
+
t.columns[3][1] = m[3][1];
|
44
|
+
t.columns[3][2] = m[3][2];
|
45
|
+
t.columns[3][3] = m[3][3];
|
46
|
+
|
47
|
+
return t;
|
48
|
+
}
|
49
|
+
|
50
|
+
/*!
|
51
|
+
* @brief converts mat3 to Apple's simd type simd_float3x3
|
52
|
+
* @return simd_float3x3
|
53
|
+
*/
|
54
|
+
CGLM_INLINE
|
55
|
+
simd_float3x3
|
56
|
+
glm_mat3_applesimd(mat3 m) {
|
57
|
+
simd_float3x3 t;
|
58
|
+
|
59
|
+
t.columns[0][0] = m[0][0];
|
60
|
+
t.columns[0][1] = m[0][1];
|
61
|
+
t.columns[0][2] = m[0][2];
|
62
|
+
|
63
|
+
t.columns[1][0] = m[1][0];
|
64
|
+
t.columns[1][1] = m[1][1];
|
65
|
+
t.columns[1][2] = m[1][2];
|
66
|
+
|
67
|
+
t.columns[2][0] = m[2][0];
|
68
|
+
t.columns[2][1] = m[2][1];
|
69
|
+
t.columns[2][2] = m[2][2];
|
70
|
+
|
71
|
+
return t;
|
72
|
+
}
|
73
|
+
|
74
|
+
/*!
|
75
|
+
* @brief converts vec4 to Apple's simd type simd_float4
|
76
|
+
* @return simd_float4
|
77
|
+
*/
|
78
|
+
CGLM_INLINE
|
79
|
+
simd_float4
|
80
|
+
glm_vec4_applesimd(vec4 v) {
|
81
|
+
return (simd_float4){v[0], v[1], v[2], v[3]};
|
82
|
+
}
|
83
|
+
|
84
|
+
/*!
|
85
|
+
* @brief converts vec3 to Apple's simd type simd_float3
|
86
|
+
* @return v
|
87
|
+
*/
|
88
|
+
CGLM_INLINE
|
89
|
+
simd_float3
|
90
|
+
glm_vec3_applesimd(vec3 v) {
|
91
|
+
return (simd_float3){v[0], v[1], v[2]};
|
92
|
+
}
|
93
|
+
|
94
|
+
#endif
|
95
|
+
#endif /* cglm_applesimd_h */
|