cglm 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/Gemfile.lock +18 -16
  4. data/README.md +2 -0
  5. data/cglm.gemspec +3 -3
  6. data/ext/cglm/cglm-0.6.2/include/cglm/affine-mat.h +168 -0
  7. data/ext/cglm/cglm-0.6.2/include/cglm/affine.h +490 -0
  8. data/ext/cglm/cglm-0.6.2/include/cglm/applesimd.h +95 -0
  9. data/ext/cglm/cglm-0.6.2/include/cglm/bezier.h +154 -0
  10. data/ext/cglm/cglm-0.6.2/include/cglm/box.h +279 -0
  11. data/ext/cglm/cglm-0.6.2/include/cglm/call/affine.h +117 -0
  12. data/ext/cglm/cglm-0.6.2/include/cglm/call/bezier.h +31 -0
  13. data/ext/cglm/cglm-0.6.2/include/cglm/call/box.h +79 -0
  14. data/ext/cglm/cglm-0.6.2/include/cglm/call/cam.h +143 -0
  15. data/ext/cglm/cglm-0.6.2/include/cglm/call/curve.h +23 -0
  16. data/ext/cglm/cglm-0.6.2/include/cglm/call/ease.h +143 -0
  17. data/ext/cglm/cglm-0.6.2/include/cglm/call/euler.h +55 -0
  18. data/ext/cglm/cglm-0.6.2/include/cglm/call/frustum.h +41 -0
  19. data/ext/cglm/cglm-0.6.2/include/cglm/call/io.h +44 -0
  20. data/ext/cglm/cglm-0.6.2/include/cglm/call/mat3.h +86 -0
  21. data/ext/cglm/cglm-0.6.2/include/cglm/call/mat4.h +127 -0
  22. data/ext/cglm/cglm-0.6.2/include/cglm/call/plane.h +23 -0
  23. data/ext/cglm/cglm-0.6.2/include/cglm/call/project.h +33 -0
  24. data/ext/cglm/cglm-0.6.2/include/cglm/call/quat.h +159 -0
  25. data/ext/cglm/cglm-0.6.2/include/cglm/call/sphere.h +39 -0
  26. data/ext/cglm/cglm-0.6.2/include/cglm/call/vec3.h +312 -0
  27. data/ext/cglm/cglm-0.6.2/include/cglm/call/vec4.h +290 -0
  28. data/ext/cglm/cglm-0.6.2/include/cglm/call.h +36 -0
  29. data/ext/cglm/cglm-0.6.2/include/cglm/cam.h +585 -0
  30. data/ext/cglm/cglm-0.6.2/include/cglm/cglm.h +32 -0
  31. data/ext/cglm/cglm-0.6.2/include/cglm/color.h +26 -0
  32. data/ext/cglm/cglm-0.6.2/include/cglm/common.h +37 -0
  33. data/ext/cglm/cglm-0.6.2/include/cglm/curve.h +40 -0
  34. data/ext/cglm/cglm-0.6.2/include/cglm/ease.h +317 -0
  35. data/ext/cglm/cglm-0.6.2/include/cglm/euler.h +453 -0
  36. data/ext/cglm/cglm-0.6.2/include/cglm/frustum.h +255 -0
  37. data/ext/cglm/cglm-0.6.2/include/cglm/io.h +203 -0
  38. data/ext/cglm/cglm-0.6.2/include/cglm/mat3.h +422 -0
  39. data/ext/cglm/cglm-0.6.2/include/cglm/mat4.h +726 -0
  40. data/ext/cglm/cglm-0.6.2/include/cglm/plane.h +36 -0
  41. data/ext/cglm/cglm-0.6.2/include/cglm/project.h +118 -0
  42. data/ext/cglm/cglm-0.6.2/include/cglm/quat.h +828 -0
  43. data/ext/cglm/cglm-0.6.2/include/cglm/simd/arm.h +83 -0
  44. data/ext/cglm/cglm-0.6.2/include/cglm/simd/avx/affine.h +66 -0
  45. data/ext/cglm/cglm-0.6.2/include/cglm/simd/avx/mat4.h +66 -0
  46. data/ext/cglm/cglm-0.6.2/include/cglm/simd/intrin.h +90 -0
  47. data/ext/cglm/cglm-0.6.2/include/cglm/simd/neon/mat4.h +57 -0
  48. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/affine.h +111 -0
  49. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/mat3.h +59 -0
  50. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/mat4.h +405 -0
  51. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/quat.h +46 -0
  52. data/ext/cglm/cglm-0.6.2/include/cglm/simd/x86.h +192 -0
  53. data/ext/cglm/cglm-0.6.2/include/cglm/sphere.h +99 -0
  54. data/ext/cglm/cglm-0.6.2/include/cglm/struct/affine.h +337 -0
  55. data/ext/cglm/cglm-0.6.2/include/cglm/struct/box.h +256 -0
  56. data/ext/cglm/cglm-0.6.2/include/cglm/struct/cam.h +451 -0
  57. data/ext/cglm/cglm-0.6.2/include/cglm/struct/color.h +27 -0
  58. data/ext/cglm/cglm-0.6.2/include/cglm/struct/curve.h +40 -0
  59. data/ext/cglm/cglm-0.6.2/include/cglm/struct/euler.h +152 -0
  60. data/ext/cglm/cglm-0.6.2/include/cglm/struct/frustum.h +155 -0
  61. data/ext/cglm/cglm-0.6.2/include/cglm/struct/io.h +82 -0
  62. data/ext/cglm/cglm-0.6.2/include/cglm/struct/mat3.h +285 -0
  63. data/ext/cglm/cglm-0.6.2/include/cglm/struct/mat4.h +459 -0
  64. data/ext/cglm/cglm-0.6.2/include/cglm/struct/plane.h +40 -0
  65. data/ext/cglm/cglm-0.6.2/include/cglm/struct/project.h +104 -0
  66. data/ext/cglm/cglm-0.6.2/include/cglm/struct/quat.h +532 -0
  67. data/ext/cglm/cglm-0.6.2/include/cglm/struct/sphere.h +93 -0
  68. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec3-ext.h +257 -0
  69. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec3.h +970 -0
  70. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec4-ext.h +257 -0
  71. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec4.h +814 -0
  72. data/ext/cglm/cglm-0.6.2/include/cglm/struct.h +36 -0
  73. data/ext/cglm/cglm-0.6.2/include/cglm/types-struct.h +129 -0
  74. data/ext/cglm/cglm-0.6.2/include/cglm/types.h +76 -0
  75. data/ext/cglm/cglm-0.6.2/include/cglm/util.h +328 -0
  76. data/ext/cglm/cglm-0.6.2/include/cglm/vec3-ext.h +272 -0
  77. data/ext/cglm/cglm-0.6.2/include/cglm/vec3.h +1078 -0
  78. data/ext/cglm/cglm-0.6.2/include/cglm/vec4-ext.h +315 -0
  79. data/ext/cglm/cglm-0.6.2/include/cglm/vec4.h +1078 -0
  80. data/ext/cglm/cglm-0.6.2/include/cglm/version.h +15 -0
  81. data/ext/cglm/extconf.rb +2 -3
  82. data/ext/cglm/rb_cglm.h +5 -3
  83. data/ext/cglm/rb_cglm_mat3.c +3 -3
  84. data/ext/cglm/rb_cglm_mat4.c +3 -3
  85. data/ext/cglm/rb_cglm_quat.c +2 -2
  86. data/ext/cglm/rb_cglm_vec3.c +63 -61
  87. data/ext/cglm/rb_cglm_vec4.c +2 -0
  88. data/ext/cglm/ruby_pre27.h +35 -0
  89. data/lib/cglm/vec3.rb +2 -2
  90. data/lib/cglm/vec4.rb +2 -2
  91. data/lib/cglm/vector_type.rb +15 -0
  92. data/lib/cglm/version.rb +1 -1
  93. metadata +89 -13
@@ -0,0 +1,532 @@
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
+ Macros:
10
+ GLMS_QUAT_IDENTITY_INIT
11
+ GLMS_QUAT_IDENTITY
12
+
13
+ Functions:
14
+ CGLM_INLINE versors glms_quat_identity(void)
15
+ CGLM_INLINE void glms_quat_identity_array(versor *q, size_t count)
16
+ CGLM_INLINE versors glms_quat_init(float x, float y, float z, float w)
17
+ CGLM_INLINE versors glms_quatv(float angle, vec3s axis)
18
+ CGLM_INLINE versors glms_quat(float angle, float x, float y, float z)
19
+ CGLM_INLINE float glms_quat_norm(versors q)
20
+ CGLM_INLINE versors glms_quat_normalize(versors q)
21
+ CGLM_INLINE float glms_quat_dot(versors p, versors q)
22
+ CGLM_INLINE versors glms_quat_conjugate(versors q)
23
+ CGLM_INLINE versors glms_quat_inv(versors q)
24
+ CGLM_INLINE versors glms_quat_add(versors p, versors q)
25
+ CGLM_INLINE versors glms_quat_sub(versors p, versors q)
26
+ CGLM_INLINE vec3s glms_quat_imagn(versors q)
27
+ CGLM_INLINE float glms_quat_imaglen(versors q)
28
+ CGLM_INLINE float glms_quat_angle(versors q)
29
+ CGLM_INLINE vec3s glms_quat_axis(versors q)
30
+ CGLM_INLINE versors glms_quat_mul(versors p, versors q)
31
+ CGLM_INLINE mat4s glms_quat_mat4(versors q)
32
+ CGLM_INLINE mat4s glms_quat_mat4t(versors q)
33
+ CGLM_INLINE mat3s glms_quat_mat3(versors q)
34
+ CGLM_INLINE mat3s glms_quat_mat3t(versors q)
35
+ CGLM_INLINE versors glms_quat_lerp(versors from, versors to, float t)
36
+ CGLM_INLINE versors glms_quat_lerpc(versors from, versors to, float t)
37
+ CGLM_INLINE versors glms_quat_slerp(versors from, versors to, float t)
38
+ CGLM_INLINE mat4s. glms_quat_look(vec3s eye, versors ori)
39
+ CGLM_INLINE versors glms_quat_for(vec3s dir, vec3s fwd, vec3s up)
40
+ CGLM_INLINE versors glms_quat_forp(vec3s from, vec3s to, vec3s fwd, vec3s up)
41
+ CGLM_INLINE vec3s glms_quat_rotatev(versors q, vec3s v)
42
+ CGLM_INLINE mat4s glms_quat_rotate(mat4s m, versors q)
43
+ CGLM_INLINE mat4s glms_quat_rotate_at(mat4s m, versors q, vec3s pivot)
44
+ CGLM_INLINE mat4s glms_quat_rotate_atm(versors q, vec3s pivot)
45
+ */
46
+
47
+ #ifndef cglms_quat_h
48
+ #define cglms_quat_h
49
+
50
+ #include "../common.h"
51
+ #include "../types-struct.h"
52
+ #include "../plane.h"
53
+ #include "../quat.h"
54
+
55
+ /*
56
+ * IMPORTANT:
57
+ * ----------------------------------------------------------------------------
58
+ * cglm stores quat as [x, y, z, w] since v0.3.6
59
+ *
60
+ * it was [w, x, y, z] before v0.3.6 it has been changed to [x, y, z, w]
61
+ * with v0.3.6 version.
62
+ * ----------------------------------------------------------------------------
63
+ */
64
+
65
+ #define GLMS_QUAT_IDENTITY_INIT {GLM_QUAT_IDENTITY_INIT}
66
+ #define GLMS_QUAT_IDENTITY ((versors)GLMS_QUAT_IDENTITY_INIT)
67
+
68
+ /*!
69
+ * @brief makes given quat to identity
70
+ *
71
+ * @returns identity quaternion
72
+ */
73
+ CGLM_INLINE
74
+ versors
75
+ glms_quat_identity(void) {
76
+ versors dest;
77
+ glm_quat_identity(dest.raw);
78
+ return dest;
79
+ }
80
+
81
+ /*!
82
+ * @brief make given quaternion array's each element identity quaternion
83
+ *
84
+ * @param[in, out] q quat array (must be aligned (16)
85
+ * if alignment is not disabled)
86
+ *
87
+ * @param[in] count count of quaternions
88
+ */
89
+ CGLM_INLINE
90
+ void
91
+ glms_quat_identity_array(versors * __restrict q, size_t count) {
92
+ CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT;
93
+ size_t i;
94
+
95
+ for (i = 0; i < count; i++) {
96
+ glm_vec4_copy(v, q[i].raw);
97
+ }
98
+ }
99
+
100
+ /*!
101
+ * @brief inits quaterion with raw values
102
+ *
103
+ * @param[in] x x
104
+ * @param[in] y y
105
+ * @param[in] z z
106
+ * @param[in] w w (real part)
107
+ * @returns quaternion
108
+ */
109
+ CGLM_INLINE
110
+ versors
111
+ glms_quat_init(float x, float y, float z, float w) {
112
+ versors dest;
113
+ glm_quat_init(dest.raw, x, y, z, w);
114
+ return dest;
115
+ }
116
+
117
+ /*!
118
+ * @brief creates NEW quaternion with axis vector
119
+ *
120
+ * @param[in] angle angle (radians)
121
+ * @param[in] axis axis
122
+ * @returns quaternion
123
+ */
124
+ CGLM_INLINE
125
+ versors
126
+ glms_quatv(float angle, vec3s axis) {
127
+ versors dest;
128
+ glm_quatv(dest.raw, angle, axis.raw);
129
+ return dest;
130
+ }
131
+
132
+ /*!
133
+ * @brief creates NEW quaternion with individual axis components
134
+ *
135
+ * @param[in] angle angle (radians)
136
+ * @param[in] x axis.x
137
+ * @param[in] y axis.y
138
+ * @param[in] z axis.z
139
+ * @returns quaternion
140
+ */
141
+ CGLM_INLINE
142
+ versors
143
+ glms_quat(float angle, float x, float y, float z) {
144
+ versors dest;
145
+ glm_quat(dest.raw, angle, x, y, z);
146
+ return dest;
147
+ }
148
+
149
+ /*!
150
+ * @brief returns norm (magnitude) of quaternion
151
+ *
152
+ * @param[out] q quaternion
153
+ */
154
+ CGLM_INLINE
155
+ float
156
+ glms_quat_norm(versors q) {
157
+ return glm_quat_norm(q.raw);
158
+ }
159
+
160
+ /*!
161
+ * @brief normalize quaternion
162
+ *
163
+ * @param[in] q quaternion
164
+ * @returns quaternion
165
+ */
166
+ CGLM_INLINE
167
+ versors
168
+ glms_quat_normalize(versors q) {
169
+ versors dest;
170
+ glm_quat_normalize_to(q.raw, dest.raw);
171
+ return dest;
172
+ }
173
+
174
+ /*!
175
+ * @brief dot product of two quaternion
176
+ *
177
+ * @param[in] p quaternion 1
178
+ * @param[in] q quaternion 2
179
+ * @returns dot product
180
+ */
181
+ CGLM_INLINE
182
+ float
183
+ glms_quat_dot(versors p, versors q) {
184
+ return glm_quat_dot(p.raw, q.raw);
185
+ }
186
+
187
+ /*!
188
+ * @brief conjugate of quaternion
189
+ *
190
+ * @param[in] q quaternion
191
+ * @returns conjugate
192
+ */
193
+ CGLM_INLINE
194
+ versors
195
+ glms_quat_conjugate(versors q) {
196
+ versors dest;
197
+ glm_quat_conjugate(q.raw, dest.raw);
198
+ return dest;
199
+ }
200
+
201
+ /*!
202
+ * @brief inverse of non-zero quaternion
203
+ *
204
+ * @param[in] q quaternion
205
+ * @returns inverse quaternion
206
+ */
207
+ CGLM_INLINE
208
+ versors
209
+ glms_quat_inv(versors q) {
210
+ versors dest;
211
+ glm_quat_inv(q.raw, dest.raw);
212
+ return dest;
213
+ }
214
+
215
+ /*!
216
+ * @brief add (componentwise) two quaternions and store result in dest
217
+ *
218
+ * @param[in] p quaternion 1
219
+ * @param[in] q quaternion 2
220
+ * @returns result quaternion
221
+ */
222
+ CGLM_INLINE
223
+ versors
224
+ glms_quat_add(versors p, versors q) {
225
+ versors dest;
226
+ glm_quat_add(p.raw, q.raw, dest.raw);
227
+ return dest;
228
+ }
229
+
230
+ /*!
231
+ * @brief subtract (componentwise) two quaternions and store result in dest
232
+ *
233
+ * @param[in] p quaternion 1
234
+ * @param[in] q quaternion 2
235
+ * @returns result quaternion
236
+ */
237
+ CGLM_INLINE
238
+ versors
239
+ glms_quat_sub(versors p, versors q) {
240
+ versors dest;
241
+ glm_quat_sub(p.raw, q.raw, dest.raw);
242
+ return dest;
243
+ }
244
+
245
+ /*!
246
+ * @brief returns normalized imaginary part of quaternion
247
+ *
248
+ * @param[in] q quaternion
249
+ */
250
+ CGLM_INLINE
251
+ vec3s
252
+ glms_quat_imagn(versors q) {
253
+ vec3s dest;
254
+ glm_normalize_to(q.raw, dest.raw);
255
+ return dest;
256
+ }
257
+
258
+ /*!
259
+ * @brief returns length of imaginary part of quaternion
260
+ *
261
+ * @param[in] q quaternion
262
+ */
263
+ CGLM_INLINE
264
+ float
265
+ glms_quat_imaglen(versors q) {
266
+ return glm_quat_imaglen(q.raw);
267
+ }
268
+
269
+ /*!
270
+ * @brief returns angle of quaternion
271
+ *
272
+ * @param[in] q quaternion
273
+ */
274
+ CGLM_INLINE
275
+ float
276
+ glms_quat_angle(versors q) {
277
+ return glm_quat_angle(q.raw);
278
+ }
279
+
280
+ /*!
281
+ * @brief axis of quaternion
282
+ *
283
+ * @param[in] q quaternion
284
+ * @returns axis of quaternion
285
+ */
286
+ CGLM_INLINE
287
+ vec3s
288
+ glms_quat_axis(versors q) {
289
+ vec3s dest;
290
+ glm_quat_axis(q.raw, dest.raw);
291
+ return dest;
292
+ }
293
+
294
+ /*!
295
+ * @brief multiplies two quaternion and stores result in dest
296
+ * this is also called Hamilton Product
297
+ *
298
+ * According to WikiPedia:
299
+ * The product of two rotation quaternions [clarification needed] will be
300
+ * equivalent to the rotation q followed by the rotation p
301
+ *
302
+ * @param[in] p quaternion 1
303
+ * @param[in] q quaternion 2
304
+ * @returns result quaternion
305
+ */
306
+ CGLM_INLINE
307
+ versors
308
+ glms_quat_mul(versors p, versors q) {
309
+ versors dest;
310
+ glm_quat_mul(p.raw, q.raw, dest.raw);
311
+ return dest;
312
+ }
313
+
314
+ /*!
315
+ * @brief convert quaternion to mat4
316
+ *
317
+ * @param[in] q quaternion
318
+ * @returns result matrix
319
+ */
320
+ CGLM_INLINE
321
+ mat4s
322
+ glms_quat_mat4(versors q) {
323
+ mat4s dest;
324
+ glm_quat_mat4(q.raw, dest.raw);
325
+ return dest;
326
+ }
327
+
328
+ /*!
329
+ * @brief convert quaternion to mat4 (transposed)
330
+ *
331
+ * @param[in] q quaternion
332
+ * @returns result matrix as transposed
333
+ */
334
+ CGLM_INLINE
335
+ mat4s
336
+ glms_quat_mat4t(versors q) {
337
+ mat4s dest;
338
+ glm_quat_mat4t(q.raw, dest.raw);
339
+ return dest;
340
+ }
341
+
342
+ /*!
343
+ * @brief convert quaternion to mat3
344
+ *
345
+ * @param[in] q quaternion
346
+ * @returns result matrix
347
+ */
348
+ CGLM_INLINE
349
+ mat3s
350
+ glms_quat_mat3(versors q) {
351
+ mat3s dest;
352
+ glm_quat_mat3(q.raw, dest.raw);
353
+ return dest;
354
+ }
355
+
356
+ /*!
357
+ * @brief convert quaternion to mat3 (transposed)
358
+ *
359
+ * @param[in] q quaternion
360
+ * @returns result matrix
361
+ */
362
+ CGLM_INLINE
363
+ mat3s
364
+ glms_quat_mat3t(versors q) {
365
+ mat3s dest;
366
+ glm_quat_mat3t(q.raw, dest.raw);
367
+ return dest;
368
+ }
369
+
370
+ /*!
371
+ * @brief interpolates between two quaternions
372
+ * using linear interpolation (LERP)
373
+ *
374
+ * @param[in] from from
375
+ * @param[in] to to
376
+ * @param[in] t interpolant (amount)
377
+ * @returns result quaternion
378
+ */
379
+ CGLM_INLINE
380
+ versors
381
+ glms_quat_lerp(versors from, versors to, float t) {
382
+ versors dest;
383
+ glm_quat_lerp(from.raw, to.raw, t, dest.raw);
384
+ return dest;
385
+ }
386
+
387
+ /*!
388
+ * @brief interpolates between two quaternions
389
+ * using linear interpolation (LERP)
390
+ *
391
+ * @param[in] from from
392
+ * @param[in] to to
393
+ * @param[in] t interpolant (amount) clamped between 0 and 1
394
+ * @returns result quaternion
395
+ */
396
+ CGLM_INLINE
397
+ versors
398
+ glms_quat_lerpc(versors from, versors to, float t) {
399
+ versors dest;
400
+ glm_quat_lerpc(from.raw, to.raw, t, dest.raw);
401
+ return dest;
402
+ }
403
+
404
+ /*!
405
+ * @brief interpolates between two quaternions
406
+ * using spherical linear interpolation (SLERP)
407
+ *
408
+ * @param[in] from from
409
+ * @param[in] to to
410
+ * @param[in] t amout
411
+ * @returns result quaternion
412
+ */
413
+ CGLM_INLINE
414
+ versors
415
+ glms_quat_slerp(versors from, versors to, float t) {
416
+ versors dest;
417
+ glm_quat_slerp(from.raw, to.raw, t, dest.raw);
418
+ return dest;
419
+ }
420
+
421
+ /*!
422
+ * @brief creates view matrix using quaternion as camera orientation
423
+ *
424
+ * @param[in] eye eye
425
+ * @param[in] ori orientation in world space as quaternion
426
+ * @returns view matrix
427
+ */
428
+ CGLM_INLINE
429
+ mat4s
430
+ glms_quat_look(vec3s eye, versors ori) {
431
+ mat4s dest;
432
+ glm_quat_look(eye.raw, ori.raw, dest.raw);
433
+ return dest;
434
+ }
435
+
436
+ /*!
437
+ * @brief creates look rotation quaternion
438
+ *
439
+ * @param[in] dir direction to look
440
+ * @param[in] fwd forward vector
441
+ * @param[in] up up vector
442
+ * @returns destination quaternion
443
+ */
444
+ CGLM_INLINE
445
+ versors
446
+ glms_quat_for(vec3s dir, vec3s fwd, vec3s up) {
447
+ versors dest;
448
+ glm_quat_for(dir.raw, fwd.raw, up.raw, dest.raw);
449
+ return dest;
450
+ }
451
+
452
+ /*!
453
+ * @brief creates look rotation quaternion using source and
454
+ * destination positions p suffix stands for position
455
+ *
456
+ * @param[in] from source point
457
+ * @param[in] to destination point
458
+ * @param[in] fwd forward vector
459
+ * @param[in] up up vector
460
+ * @returns destination quaternion
461
+ */
462
+ CGLM_INLINE
463
+ versors
464
+ glms_quat_forp(vec3s from, vec3s to, vec3s fwd, vec3s up) {
465
+ versors dest;
466
+ glm_quat_forp(from.raw, to.raw, fwd.raw, up.raw, dest.raw);
467
+ return dest;
468
+ }
469
+
470
+ /*!
471
+ * @brief rotate vector using using quaternion
472
+ *
473
+ * @param[in] q quaternion
474
+ * @param[in] v vector to rotate
475
+ * @returns rotated vector
476
+ */
477
+ CGLM_INLINE
478
+ vec3s
479
+ glms_quat_rotatev(versors q, vec3s v) {
480
+ vec3s dest;
481
+ glm_quat_rotatev(q.raw, v.raw, dest.raw);
482
+ return dest;
483
+ }
484
+
485
+ /*!
486
+ * @brief rotate existing transform matrix using quaternion
487
+ *
488
+ * @param[in] m existing transform matrix
489
+ * @param[in] q quaternion
490
+ * @returns rotated matrix/transform
491
+ */
492
+ CGLM_INLINE
493
+ mat4s
494
+ glms_quat_rotate(mat4s m, versors q) {
495
+ glm_quat_rotate(m.raw, q.raw, m.raw);
496
+ return m;
497
+ }
498
+
499
+ /*!
500
+ * @brief rotate existing transform matrix using quaternion at pivot point
501
+ *
502
+ * @param[in, out] m existing transform matrix
503
+ * @param[in] q quaternion
504
+ * @returns pivot
505
+ */
506
+ CGLM_INLINE
507
+ mat4s
508
+ glms_quat_rotate_at(mat4s m, versors q, vec3s pivot) {
509
+ glm_quat_rotate_at(m.raw, q.raw, pivot.raw);
510
+ return m;
511
+ }
512
+
513
+ /*!
514
+ * @brief rotate NEW transform matrix using quaternion at pivot point
515
+ *
516
+ * this creates rotation matrix, it assumes you don't have a matrix
517
+ *
518
+ * this should work faster than glm_quat_rotate_at because it reduces
519
+ * one glm_translate.
520
+ *
521
+ * @param[in] q quaternion
522
+ * @returns pivot
523
+ */
524
+ CGLM_INLINE
525
+ mat4s
526
+ glms_quat_rotate_atm(versors q, vec3s pivot) {
527
+ mat4s dest;
528
+ glm_quat_rotate_atm(dest.raw, q.raw, pivot.raw);
529
+ return dest;
530
+ }
531
+
532
+ #endif /* cglms_quat_h */
@@ -0,0 +1,93 @@
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 cglms_spheres_h
9
+ #define cglms_spheres_h
10
+
11
+ #include "../common.h"
12
+ #include "../types-struct.h"
13
+ #include "../sphere.h"
14
+ #include "mat4.h"
15
+
16
+ /*
17
+ Sphere Representation in cglm: [center.x, center.y, center.z, radii]
18
+
19
+ You could use this representation or you can convert it to vec4 before call
20
+ any function
21
+ */
22
+
23
+ /*!
24
+ * @brief helper for getting sphere radius
25
+ *
26
+ * @param[in] s sphere
27
+ *
28
+ * @return returns radii
29
+ */
30
+ CGLM_INLINE
31
+ float
32
+ glms_sphere_radii(vec4s s) {
33
+ return glm_sphere_radii(s.raw);
34
+ }
35
+
36
+ /*!
37
+ * @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3
38
+ *
39
+ * @param[in] s sphere
40
+ * @param[in] m transform matrix
41
+ * @returns transformed sphere
42
+ */
43
+ CGLM_INLINE
44
+ vec4s
45
+ glms_sphere_transform(vec4s s, mat4 m) {
46
+ vec4s r;
47
+ glm_sphere_transform(s.raw, m, r.raw);
48
+ return r;
49
+ }
50
+
51
+ /*!
52
+ * @brief merges two spheres and creates a new one
53
+ *
54
+ * two sphere must be in same space, for instance if one in world space then
55
+ * the other must be in world space too, not in local space.
56
+ *
57
+ * @param[in] s1 sphere 1
58
+ * @param[in] s2 sphere 2
59
+ * returns merged/extended sphere
60
+ */
61
+ CGLM_INLINE
62
+ vec4s
63
+ glms_sphere_merge(vec4s s1, vec4s s2) {
64
+ vec4s r;
65
+ glm_sphere_merge(s1.raw, s2.raw, r.raw);
66
+ return r;
67
+ }
68
+
69
+ /*!
70
+ * @brief check if two sphere intersects
71
+ *
72
+ * @param[in] s1 sphere
73
+ * @param[in] s2 other sphere
74
+ */
75
+ CGLM_INLINE
76
+ bool
77
+ glms_sphere_sphere(vec4s s1, vec4s s2) {
78
+ return glm_sphere_sphere(s1.raw, s2.raw);
79
+ }
80
+
81
+ /*!
82
+ * @brief check if sphere intersects with point
83
+ *
84
+ * @param[in] s sphere
85
+ * @param[in] point point
86
+ */
87
+ CGLM_INLINE
88
+ bool
89
+ glms_sphere_point(vec4s s, vec3s point) {
90
+ return glm_sphere_point(s.raw, point.raw);
91
+ }
92
+
93
+ #endif /* cglms_spheres_h */