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,970 @@
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_VEC3_ONE_INIT
11
+ GLMS_VEC3_ZERO_INIT
12
+ GLMS_VEC3_ONE
13
+ GLMS_VEC3_ZERO
14
+ GLMS_YUP
15
+ GLMS_ZUP
16
+ GLMS_XUP
17
+
18
+ Functions:
19
+ CGLM_INLINE vec3s glms_vec3(vec4s v4);
20
+ CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len);
21
+ CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len);
22
+ CGLM_INLINE vec3s glms_vec3_zero(void);
23
+ CGLM_INLINE vec3s glms_vec3_one(void);
24
+ CGLM_INLINE float glms_vec3_dot(vec3s a, vec3s b);
25
+ CGLM_INLINE float glms_vec3_norm2(vec3s v);
26
+ CGLM_INLINE float glms_vec3_norm(vec3s v);
27
+ CGLM_INLINE float glms_vec3_norm_one(vec3s v);
28
+ CGLM_INLINE float glms_vec3_norm_inf(vec3s v);
29
+ CGLM_INLINE vec3s glms_vec3_add(vec3s a, vec3s b);
30
+ CGLM_INLINE vec3s glms_vec3_adds(vec3s a, float s);
31
+ CGLM_INLINE vec3s glms_vec3_sub(vec3s a, vec3s b);
32
+ CGLM_INLINE vec3s glms_vec3_subs(vec3s a, float s);
33
+ CGLM_INLINE vec3s glms_vec3_mul(vec3s a, vec3s b);
34
+ CGLM_INLINE vec3s glms_vec3_scale(vec3s v, float s);
35
+ CGLM_INLINE vec3s glms_vec3_scale_as(vec3s v, float s);
36
+ CGLM_INLINE vec3s glms_vec3_div(vec3s a, vec3s b);
37
+ CGLM_INLINE vec3s glms_vec3_divs(vec3s a, float s);
38
+ CGLM_INLINE vec3s glms_vec3_addadd(vec3s a, vec3s b, vec3s dest);
39
+ CGLM_INLINE vec3s glms_vec3_subadd(vec3s a, vec3s b, vec3s dest);
40
+ CGLM_INLINE vec3s glms_vec3_muladd(vec3s a, vec3s b, vec3s dest);
41
+ CGLM_INLINE vec3s glms_vec3_muladds(vec3s a, float s, vec3s dest);
42
+ CGLM_INLINE vec3s glms_vec3_maxadd(vec3s a, vec3s b, vec3s dest);
43
+ CGLM_INLINE vec3s glms_vec3_minadd(vec3s a, vec3s b, vec3s dest);
44
+ CGLM_INLINE vec3s glms_vec3_flipsign(vec3s v);
45
+ CGLM_INLINE vec3s glms_vec3_negate(vec3s v);
46
+ CGLM_INLINE vec3s glms_vec3_inv(vec3s v);
47
+ CGLM_INLINE vec3s glms_vec3_normalize(vec3s v);
48
+ CGLM_INLINE vec3s glms_vec3_cross(vec3s a, vec3s b);
49
+ CGLM_INLINE vec3s glms_vec3_crossn(vec3s a, vec3s b);
50
+ CGLM_INLINE float glms_vec3_angle(vec3s a, vec3s b);
51
+ CGLM_INLINE vec3s glms_vec3_rotate(vec3s v, float angle, vec3s axis);
52
+ CGLM_INLINE vec3s glms_vec3_rotate_m4(mat4s m, vec3s v);
53
+ CGLM_INLINE vec3s glms_vec3_rotate_m3(mat3s m, vec3s v);
54
+ CGLM_INLINE vec3s glms_vec3_proj(vec3s a, vec3s b);
55
+ CGLM_INLINE vec3s glms_vec3_center(vec3s a, vec3s b);
56
+ CGLM_INLINE float glms_vec3_distance(vec3s a, vec3s b);
57
+ CGLM_INLINE float glms_vec3_distance2(vec3s a, vec3s b);
58
+ CGLM_INLINE vec3s glms_vec3_maxv(vec3s a, vec3s b);
59
+ CGLM_INLINE vec3s glms_vec3_minv(vec3s a, vec3s b);
60
+ CGLM_INLINE vec3s glms_vec3_ortho(vec3s v);
61
+ CGLM_INLINE vec3s glms_vec3_clamp(vec3s v, float minVal, float maxVal);
62
+ CGLM_INLINE vec3s glms_vec3_lerp(vec3s from, vec3s to, float t);
63
+ CGLM_INLINE vec3s glms_vec3_lerpc(vec3s from, vec3s to, float t);
64
+ CGLM_INLINE vec3s glms_vec3_mix(vec3s from, vec3s to, float t);
65
+ CGLM_INLINE vec3s glms_vec3_mixc(vec3s from, vec3s to, float t);
66
+ CGLM_INLINE vec3s glms_vec3_step_uni(float edge, vec3s x);
67
+ CGLM_INLINE vec3s glms_vec3_step(vec3s edge, vec3s x);
68
+ CGLM_INLINE vec3s glms_vec3_smoothstep_uni(float edge0, float edge1, vec3s x);
69
+ CGLM_INLINE vec3s glms_vec3_smoothstep(vec3s edge0, vec3s edge1, vec3s x);
70
+ CGLM_INLINE vec3s glms_vec3_smoothinterp(vec3s from, vec3s to, float t);
71
+ CGLM_INLINE vec3s glms_vec3_smoothinterpc(vec3s from, vec3s to, float t);
72
+ CGLM_INLINE vec3s glms_vec3_swizzle(vec3s v, int mask);
73
+
74
+ Convenient:
75
+ CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b);
76
+ CGLM_INLINE float glms_dot(vec3s a, vec3s b);
77
+ CGLM_INLINE vec3s glms_normalize(vec3s v);
78
+ */
79
+
80
+ #ifndef cglms_vec3s_h
81
+ #define cglms_vec3s_h
82
+
83
+ #include "../common.h"
84
+ #include "../types-struct.h"
85
+ #include "../util.h"
86
+ #include "../vec3.h"
87
+ #include "vec3-ext.h"
88
+
89
+ #define GLMS_VEC3_ONE_INIT {GLM_VEC3_ONE_INIT}
90
+ #define GLMS_VEC3_ZERO_INIT {GLM_VEC3_ZERO_INIT}
91
+
92
+ #define GLMS_VEC3_ONE ((vec3s)GLMS_VEC3_ONE_INIT)
93
+ #define GLMS_VEC3_ZERO ((vec3s)GLMS_VEC3_ZERO_INIT)
94
+
95
+ #define GLMS_YUP ((vec3s){{0.0f, 1.0f, 0.0f}})
96
+ #define GLMS_ZUP ((vec3s){{0.0f, 0.0f, 1.0f}})
97
+ #define GLMS_XUP ((vec3s){{1.0f, 0.0f, 0.0f}})
98
+
99
+ /*!
100
+ * @brief init vec3 using vec4
101
+ *
102
+ * @param[in] v4 vector4
103
+ * @returns destination
104
+ */
105
+ CGLM_INLINE
106
+ vec3s
107
+ glms_vec3(vec4s v4) {
108
+ vec3s r;
109
+ glm_vec3(v4.raw, r.raw);
110
+ return r;
111
+ }
112
+
113
+ /*!
114
+ * @brief pack an array of vec3 into an array of vec3s
115
+ *
116
+ * @param[out] dst array of vec3
117
+ * @param[in] src array of vec3s
118
+ * @param[in] len number of elements
119
+ */
120
+ CGLM_INLINE
121
+ void
122
+ glms_vec3_pack(vec3s dst[], vec3 src[], size_t len) {
123
+ size_t i;
124
+
125
+ for (i = 0; i < len; i++) {
126
+ glm_vec3_copy(src[i], dst[i].raw);
127
+ }
128
+ }
129
+
130
+ /*!
131
+ * @brief unpack an array of vec3s into an array of vec3
132
+ *
133
+ * @param[out] dst array of vec3s
134
+ * @param[in] src array of vec3
135
+ * @param[in] len number of elements
136
+ */
137
+ CGLM_INLINE
138
+ void
139
+ glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) {
140
+ size_t i;
141
+
142
+ for (i = 0; i < len; i++) {
143
+ glm_vec3_copy(src[i].raw, dst[i]);
144
+ }
145
+ }
146
+
147
+ /*!
148
+ * @brief make vector zero
149
+ *
150
+ * @returns zero vector
151
+ */
152
+ CGLM_INLINE
153
+ vec3s
154
+ glms_vec3_zero(void) {
155
+ vec3s r;
156
+ glm_vec3_zero(r.raw);
157
+ return r;
158
+ }
159
+
160
+ /*!
161
+ * @brief make vector one
162
+ *
163
+ * @returns one vector
164
+ */
165
+ CGLM_INLINE
166
+ vec3s
167
+ glms_vec3_one(void) {
168
+ vec3s r;
169
+ glm_vec3_one(r.raw);
170
+ return r;
171
+ }
172
+
173
+ /*!
174
+ * @brief vec3 dot product
175
+ *
176
+ * @param[in] a vector1
177
+ * @param[in] b vector2
178
+ *
179
+ * @return dot product
180
+ */
181
+ CGLM_INLINE
182
+ float
183
+ glms_vec3_dot(vec3s a, vec3s b) {
184
+ return glm_vec3_dot(a.raw, b.raw);
185
+ }
186
+
187
+ /*!
188
+ * @brief norm * norm (magnitude) of vec
189
+ *
190
+ * we can use this func instead of calling norm * norm, because it would call
191
+ * sqrtf fuction twice but with this func we can avoid func call, maybe this is
192
+ * not good name for this func
193
+ *
194
+ * @param[in] v vector
195
+ *
196
+ * @return norm * norm
197
+ */
198
+ CGLM_INLINE
199
+ float
200
+ glms_vec3_norm2(vec3s v) {
201
+ return glm_vec3_norm2(v.raw);
202
+ }
203
+
204
+ /*!
205
+ * @brief norm (magnitude) of vec3
206
+ *
207
+ * @param[in] v vector
208
+ *
209
+ * @return norm
210
+ */
211
+ CGLM_INLINE
212
+ float
213
+ glms_vec3_norm(vec3s v) {
214
+ return glm_vec3_norm(v.raw);
215
+ }
216
+
217
+ /*!
218
+ * @brief L1 norm of vec3
219
+ * Also known as Manhattan Distance or Taxicab norm.
220
+ * L1 Norm is the sum of the magnitudes of the vectors in a space.
221
+ * It is calculated as the sum of the absolute values of the vector components.
222
+ * In this norm, all the components of the vector are weighted equally.
223
+ *
224
+ * This computes:
225
+ * R = |v[0]| + |v[1]| + |v[2]|
226
+ *
227
+ * @param[in] v vector
228
+ *
229
+ * @return L1 norm
230
+ */
231
+ CGLM_INLINE
232
+ float
233
+ glms_vec3_norm_one(vec3s v) {
234
+ return glm_vec3_norm_one(v.raw);
235
+ }
236
+
237
+ /*!
238
+ * @brief Infinity norm of vec3
239
+ * Also known as Maximum norm.
240
+ * Infinity Norm is the largest magnitude among each element of a vector.
241
+ * It is calculated as the maximum of the absolute values of the vector components.
242
+ *
243
+ * This computes:
244
+ * inf norm = max(|v[0]|, |v[1]|, |v[2]|)
245
+ *
246
+ * @param[in] v vector
247
+ *
248
+ * @return Infinity norm
249
+ */
250
+ CGLM_INLINE
251
+ float
252
+ glms_vec3_norm_inf(vec3s v) {
253
+ return glm_vec3_norm_inf(v.raw);
254
+ }
255
+
256
+ /*!
257
+ * @brief add a vector to b vector store result in dest
258
+ *
259
+ * @param[in] a vector1
260
+ * @param[in] b vector2
261
+ * @returns destination vector
262
+ */
263
+ CGLM_INLINE
264
+ vec3s
265
+ glms_vec3_add(vec3s a, vec3s b) {
266
+ vec3s r;
267
+ glm_vec3_add(a.raw, b.raw, r.raw);
268
+ return r;
269
+ }
270
+
271
+ /*!
272
+ * @brief add scalar to v vector store result in dest (d = v + s)
273
+ *
274
+ * @param[in] a vector
275
+ * @param[in] s scalar
276
+ * @returns destination vector
277
+ */
278
+ CGLM_INLINE
279
+ vec3s
280
+ glms_vec3_adds(vec3s a, float s) {
281
+ vec3s r;
282
+ glm_vec3_adds(a.raw, s, r.raw);
283
+ return r;
284
+ }
285
+
286
+ /*!
287
+ * @brief subtract b vector from a vector store result in dest
288
+ *
289
+ * @param[in] a vector1
290
+ * @param[in] b vector2
291
+ * @returns destination vector
292
+ */
293
+ CGLM_INLINE
294
+ vec3s
295
+ glms_vec3_sub(vec3s a, vec3s b) {
296
+ vec3s r;
297
+ glm_vec3_sub(a.raw, b.raw, r.raw);
298
+ return r;
299
+ }
300
+
301
+ /*!
302
+ * @brief subtract scalar from v vector store result in dest (d = v - s)
303
+ *
304
+ * @param[in] a vector
305
+ * @param[in] s scalar
306
+ * @returns destination vector
307
+ */
308
+ CGLM_INLINE
309
+ vec3s
310
+ glms_vec3_subs(vec3s a, float s) {
311
+ vec3s r;
312
+ glm_vec3_subs(a.raw, s, r.raw);
313
+ return r;
314
+ }
315
+
316
+ /*!
317
+ * @brief multiply two vector (component-wise multiplication)
318
+ *
319
+ * @param a vector1
320
+ * @param b vector2
321
+ * @returns v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2])
322
+ */
323
+ CGLM_INLINE
324
+ vec3s
325
+ glms_vec3_mul(vec3s a, vec3s b) {
326
+ vec3s r;
327
+ glm_vec3_mul(a.raw, b.raw, r.raw);
328
+ return r;
329
+ }
330
+
331
+ /*!
332
+ * @brief multiply/scale vec3 vector with scalar: result = v * s
333
+ *
334
+ * @param[in] v vector
335
+ * @param[in] s scalar
336
+ * @returns destination vector
337
+ */
338
+ CGLM_INLINE
339
+ vec3s
340
+ glms_vec3_scale(vec3s v, float s) {
341
+ vec3s r;
342
+ glm_vec3_scale(v.raw, s, r.raw);
343
+ return r;
344
+ }
345
+
346
+ /*!
347
+ * @brief make vec3 vector scale as specified: result = unit(v) * s
348
+ *
349
+ * @param[in] v vector
350
+ * @param[in] s scalar
351
+ * @returns destination vector
352
+ */
353
+ CGLM_INLINE
354
+ vec3s
355
+ glms_vec3_scale_as(vec3s v, float s) {
356
+ vec3s r;
357
+ glm_vec3_scale_as(v.raw, s, r.raw);
358
+ return r;
359
+ }
360
+
361
+ /*!
362
+ * @brief div vector with another component-wise division: d = a / b
363
+ *
364
+ * @param[in] a vector 1
365
+ * @param[in] b vector 2
366
+ * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2])
367
+ */
368
+ CGLM_INLINE
369
+ vec3s
370
+ glms_vec3_div(vec3s a, vec3s b) {
371
+ vec3s r;
372
+ glm_vec3_div(a.raw, b.raw, r.raw);
373
+ return r;
374
+ }
375
+
376
+ /*!
377
+ * @brief div vector with scalar: d = v / s
378
+ *
379
+ * @param[in] a vector
380
+ * @param[in] s scalar
381
+ * @returns result = (a[0]/s, a[1]/s, a[2]/s)
382
+ */
383
+ CGLM_INLINE
384
+ vec3s
385
+ glms_vec3_divs(vec3s a, float s) {
386
+ vec3s r;
387
+ glm_vec3_divs(a.raw, s, r.raw);
388
+ return r;
389
+ }
390
+
391
+ /*!
392
+ * @brief add two vectors and add result to sum
393
+ *
394
+ * it applies += operator so dest must be initialized
395
+ *
396
+ * @param[in] a vector 1
397
+ * @param[in] b vector 2
398
+ * @returns dest += (a + b)
399
+ */
400
+ CGLM_INLINE
401
+ vec3s
402
+ glms_vec3_addadd(vec3s a, vec3s b, vec3s dest) {
403
+ glm_vec3_addadd(a.raw, b.raw, dest.raw);
404
+ return dest;
405
+ }
406
+
407
+ /*!
408
+ * @brief sub two vectors and add result to dest
409
+ *
410
+ * it applies += operator so dest must be initialized
411
+ *
412
+ * @param[in] a vector 1
413
+ * @param[in] b vector 2
414
+ * @returns dest += (a + b)
415
+ */
416
+ CGLM_INLINE
417
+ vec3s
418
+ glms_vec3_subadd(vec3s a, vec3s b, vec3s dest) {
419
+ glm_vec3_subadd(a.raw, b.raw, dest.raw);
420
+ return dest;
421
+ }
422
+
423
+ /*!
424
+ * @brief mul two vectors and add result to dest
425
+ *
426
+ * it applies += operator so dest must be initialized
427
+ *
428
+ * @param[in] a vector 1
429
+ * @param[in] b vector 2
430
+ * @returns dest += (a * b)
431
+ */
432
+ CGLM_INLINE
433
+ vec3s
434
+ glms_vec3_muladd(vec3s a, vec3s b, vec3s dest) {
435
+ glm_vec3_muladd(a.raw, b.raw, dest.raw);
436
+ return dest;
437
+ }
438
+
439
+ /*!
440
+ * @brief mul vector with scalar and add result to sum
441
+ *
442
+ * it applies += operator so dest must be initialized
443
+ *
444
+ * @param[in] a vector
445
+ * @param[in] s scalar
446
+ * @returns dest += (a * b)
447
+ */
448
+ CGLM_INLINE
449
+ vec3s
450
+ glms_vec3_muladds(vec3s a, float s, vec3s dest) {
451
+ glm_vec3_muladds(a.raw, s, dest.raw);
452
+ return dest;
453
+ }
454
+
455
+ /*!
456
+ * @brief add max of two vector to result/dest
457
+ *
458
+ * it applies += operator so dest must be initialized
459
+ *
460
+ * @param[in] a vector 1
461
+ * @param[in] b vector 2
462
+ * @returns dest += max(a, b)
463
+ */
464
+ CGLM_INLINE
465
+ vec3s
466
+ glms_vec3_maxadd(vec3s a, vec3s b, vec3s dest) {
467
+ glm_vec3_maxadd(a.raw, b.raw, dest.raw);
468
+ return dest;
469
+ }
470
+
471
+ /*!
472
+ * @brief add min of two vector to result/dest
473
+ *
474
+ * it applies += operator so dest must be initialized
475
+ *
476
+ * @param[in] a vector 1
477
+ * @param[in] b vector 2
478
+ * @returns dest += min(a, b)
479
+ */
480
+ CGLM_INLINE
481
+ vec3s
482
+ glms_vec3_minadd(vec3s a, vec3s b, vec3s dest) {
483
+ glm_vec3_minadd(a.raw, b.raw, dest.raw);
484
+ return dest;
485
+ }
486
+
487
+ /*!
488
+ * @brief negate vector components and store result in dest
489
+ *
490
+ * @param[in] v vector
491
+ * @returns result vector
492
+ */
493
+ CGLM_INLINE
494
+ vec3s
495
+ glms_vec3_flipsign(vec3s v) {
496
+ glm_vec3_flipsign(v.raw);
497
+ return v;
498
+ }
499
+
500
+ /*!
501
+ * @brief negate vector components
502
+ *
503
+ * @param[in] v vector
504
+ * @returns negated vector
505
+ */
506
+ CGLM_INLINE
507
+ vec3s
508
+ glms_vec3_negate(vec3s v) {
509
+ glm_vec3_negate(v.raw);
510
+ return v;
511
+ }
512
+
513
+ /*!
514
+ * @brief normalize vec3 and store result in same vec
515
+ *
516
+ * @param[in] v vector
517
+ * @returns normalized vector
518
+ */
519
+ CGLM_INLINE
520
+ vec3s
521
+ glms_vec3_normalize(vec3s v) {
522
+ glm_vec3_normalize(v.raw);
523
+ return v;
524
+ }
525
+
526
+ /*!
527
+ * @brief cross product of two vector (RH)
528
+ *
529
+ * @param[in] a vector 1
530
+ * @param[in] b vector 2
531
+ * @returns destination
532
+ */
533
+ CGLM_INLINE
534
+ vec3s
535
+ glms_vec3_cross(vec3s a, vec3s b) {
536
+ vec3s r;
537
+ glm_vec3_cross(a.raw, b.raw, r.raw);
538
+ return r;
539
+ }
540
+
541
+ /*!
542
+ * @brief cross product of two vector (RH) and normalize the result
543
+ *
544
+ * @param[in] a vector 1
545
+ * @param[in] b vector 2
546
+ * @returns destination
547
+ */
548
+ CGLM_INLINE
549
+ vec3s
550
+ glms_vec3_crossn(vec3s a, vec3s b) {
551
+ vec3s r;
552
+ glm_vec3_crossn(a.raw, b.raw, r.raw);
553
+ return r;
554
+ }
555
+
556
+ /*!
557
+ * @brief angle betwen two vector
558
+ *
559
+ * @param[in] a vector1
560
+ * @param[in] b vector2
561
+ *
562
+ * @return angle as radians
563
+ */
564
+ CGLM_INLINE
565
+ float
566
+ glms_vec3_angle(vec3s a, vec3s b) {
567
+ return glm_vec3_angle(a.raw, b.raw);
568
+ }
569
+
570
+ /*!
571
+ * @brief rotate vec3 around axis by angle using Rodrigues' rotation formula
572
+ *
573
+ * @param[in] v vector
574
+ * @param[in] axis axis vector (must be unit vector)
575
+ * @param[in] angle angle by radians
576
+ * @returns rotated vector
577
+ */
578
+ CGLM_INLINE
579
+ vec3s
580
+ glms_vec3_rotate(vec3s v, float angle, vec3s axis) {
581
+ glm_vec3_rotate(v.raw, angle, axis.raw);
582
+ return v;
583
+ }
584
+
585
+ /*!
586
+ * @brief apply rotation matrix to vector
587
+ *
588
+ * matrix format should be (no perspective):
589
+ * a b c x
590
+ * e f g y
591
+ * i j k z
592
+ * 0 0 0 w
593
+ *
594
+ * @param[in] m affine matrix or rot matrix
595
+ * @param[in] v vector
596
+ * @returns rotated vector
597
+ */
598
+ CGLM_INLINE
599
+ vec3s
600
+ glms_vec3_rotate_m4(mat4s m, vec3s v) {
601
+ vec3s r;
602
+ glm_vec3_rotate_m4(m.raw, v.raw, r.raw);
603
+ return r;
604
+ }
605
+
606
+ /*!
607
+ * @brief apply rotation matrix to vector
608
+ *
609
+ * @param[in] m affine matrix or rot matrix
610
+ * @param[in] v vector
611
+ * @returns rotated vector
612
+ */
613
+ CGLM_INLINE
614
+ vec3s
615
+ glms_vec3_rotate_m3(mat3s m, vec3s v) {
616
+ vec3s r;
617
+ glm_vec3_rotate_m3(m.raw, v.raw, r.raw);
618
+ return r;
619
+ }
620
+
621
+ /*!
622
+ * @brief project a vector onto b vector
623
+ *
624
+ * @param[in] a vector1
625
+ * @param[in] b vector2
626
+ * @returns projected vector
627
+ */
628
+ CGLM_INLINE
629
+ vec3s
630
+ glms_vec3_proj(vec3s a, vec3s b) {
631
+ vec3s r;
632
+ glm_vec3_proj(a.raw, b.raw, r.raw);
633
+ return r;
634
+ }
635
+
636
+ /**
637
+ * @brief find center point of two vector
638
+ *
639
+ * @param[in] a vector1
640
+ * @param[in] b vector2
641
+ * @returns center point
642
+ */
643
+ CGLM_INLINE
644
+ vec3s
645
+ glms_vec3_center(vec3s a, vec3s b) {
646
+ vec3s r;
647
+ glm_vec3_center(a.raw, b.raw, r.raw);
648
+ return r;
649
+ }
650
+
651
+ /**
652
+ * @brief distance between two vectors
653
+ *
654
+ * @param[in] a vector1
655
+ * @param[in] b vector2
656
+ * @return distance
657
+ */
658
+ CGLM_INLINE
659
+ float
660
+ glms_vec3_distance(vec3s a, vec3s b) {
661
+ return glm_vec3_distance(a.raw, b.raw);
662
+ }
663
+
664
+ /**
665
+ * @brief squared distance between two vectors
666
+ *
667
+ * @param[in] a vector1
668
+ * @param[in] b vector2
669
+ * @return squared distance (distance * distance)
670
+ */
671
+ CGLM_INLINE
672
+ float
673
+ glms_vec3_distance2(vec3s a, vec3s b) {
674
+ return glm_vec3_distance2(a.raw, b.raw);
675
+ }
676
+
677
+ /*!
678
+ * @brief max values of vectors
679
+ *
680
+ * @param[in] a vector1
681
+ * @param[in] b vector2
682
+ * @returns destination
683
+ */
684
+ CGLM_INLINE
685
+ vec3s
686
+ glms_vec3_maxv(vec3s a, vec3s b) {
687
+ vec3s r;
688
+ glm_vec3_maxv(a.raw, b.raw, r.raw);
689
+ return r;
690
+ }
691
+
692
+ /*!
693
+ * @brief min values of vectors
694
+ *
695
+ * @param[in] a vector1
696
+ * @param[in] b vector2
697
+ * @returns destination
698
+ */
699
+ CGLM_INLINE
700
+ vec3s
701
+ glms_vec3_minv(vec3s a, vec3s b) {
702
+ vec3s r;
703
+ glm_vec3_minv(a.raw, b.raw, r.raw);
704
+ return r;
705
+ }
706
+
707
+ /*!
708
+ * @brief possible orthogonal/perpendicular vector
709
+ *
710
+ * @param[in] v vector
711
+ * @returns orthogonal/perpendicular vector
712
+ */
713
+ CGLM_INLINE
714
+ vec3s
715
+ glms_vec3_ortho(vec3s v) {
716
+ vec3s r;
717
+ glm_vec3_ortho(v.raw, r.raw);
718
+ return r;
719
+ }
720
+
721
+ /*!
722
+ * @brief clamp vector's individual members between min and max values
723
+ *
724
+ * @param[in] v vector
725
+ * @param[in] minVal minimum value
726
+ * @param[in] maxVal maximum value
727
+ * @returns clamped vector
728
+ */
729
+ CGLM_INLINE
730
+ vec3s
731
+ glms_vec3_clamp(vec3s v, float minVal, float maxVal) {
732
+ glm_vec3_clamp(v.raw, minVal, maxVal);
733
+ return v;
734
+ }
735
+
736
+ /*!
737
+ * @brief linear interpolation between two vectors
738
+ *
739
+ * formula: from + s * (to - from)
740
+ *
741
+ * @param[in] from from value
742
+ * @param[in] to to value
743
+ * @param[in] t interpolant (amount)
744
+ * @returns destination
745
+ */
746
+ CGLM_INLINE
747
+ vec3s
748
+ glms_vec3_lerp(vec3s from, vec3s to, float t) {
749
+ vec3s r;
750
+ glm_vec3_lerp(from.raw, to.raw, t, r.raw);
751
+ return r;
752
+ }
753
+
754
+ /*!
755
+ * @brief linear interpolation between two vectors (clamped)
756
+ *
757
+ * formula: from + s * (to - from)
758
+ *
759
+ * @param[in] from from value
760
+ * @param[in] to to value
761
+ * @param[in] t interpolant (amount) clamped between 0 and 1
762
+ * @returns destination
763
+ */
764
+ CGLM_INLINE
765
+ vec3s
766
+ glms_vec3_lerpc(vec3s from, vec3s to, float t) {
767
+ vec3s r;
768
+ glm_vec3_lerpc(from.raw, to.raw, t, r.raw);
769
+ return r;
770
+ }
771
+
772
+ /*!
773
+ * @brief linear interpolation between two vectors
774
+ *
775
+ * formula: from + s * (to - from)
776
+ *
777
+ * @param[in] from from value
778
+ * @param[in] to to value
779
+ * @param[in] t interpolant (amount)
780
+ * @returns destination
781
+ */
782
+ CGLM_INLINE
783
+ vec3s
784
+ glms_vec3_mix(vec3s from, vec3s to, float t) {
785
+ vec3s r;
786
+ glm_vec3_mix(from.raw, to.raw, t, r.raw);
787
+ return r;
788
+ }
789
+
790
+ /*!
791
+ * @brief linear interpolation between two vectors (clamped)
792
+ *
793
+ * formula: from + s * (to - from)
794
+ *
795
+ * @param[in] from from value
796
+ * @param[in] to to value
797
+ * @param[in] t interpolant (amount) clamped between 0 and 1
798
+ * @returns destination
799
+ */
800
+ CGLM_INLINE
801
+ vec3s
802
+ glms_vec3_mixc(vec3s from, vec3s to, float t) {
803
+ vec3s r;
804
+ glm_vec3_mixc(from.raw, to.raw, t, r.raw);
805
+ return r;
806
+ }
807
+
808
+ /*!
809
+ * @brief threshold function (unidimensional)
810
+ *
811
+ * @param[in] edge threshold
812
+ * @param[in] x value to test against threshold
813
+ * @returns 0.0 if x < edge, else 1.0
814
+ */
815
+ CGLM_INLINE
816
+ vec3s
817
+ glms_vec3_step_uni(float edge, vec3s x) {
818
+ vec3s r;
819
+ glm_vec3_step_uni(edge, x.raw, r.raw);
820
+ return r;
821
+ }
822
+
823
+ /*!
824
+ * @brief threshold function
825
+ *
826
+ * @param[in] edge threshold
827
+ * @param[in] x value to test against threshold
828
+ * @returns 0.0 if x < edge, else 1.0
829
+ */
830
+ CGLM_INLINE
831
+ vec3s
832
+ glms_vec3_step(vec3s edge, vec3s x) {
833
+ vec3s r;
834
+ glm_vec3_step(edge.raw, x.raw, r.raw);
835
+ return r;
836
+ }
837
+
838
+ /*!
839
+ * @brief threshold function with a smooth transition (unidimensional)
840
+ *
841
+ * @param[in] edge0 low threshold
842
+ * @param[in] edge1 high threshold
843
+ * @param[in] x value to test against threshold
844
+ * @returns destination
845
+ */
846
+ CGLM_INLINE
847
+ vec3s
848
+ glms_vec3_smoothstep_uni(float edge0, float edge1, vec3s x) {
849
+ vec3s r;
850
+ glm_vec3_smoothstep_uni(edge0, edge1, x.raw, r.raw);
851
+ return r;
852
+ }
853
+
854
+ /*!
855
+ * @brief threshold function with a smooth transition
856
+ *
857
+ * @param[in] edge0 low threshold
858
+ * @param[in] edge1 high threshold
859
+ * @param[in] x value to test against threshold
860
+ * @returns destination
861
+ */
862
+ CGLM_INLINE
863
+ vec3s
864
+ glms_vec3_smoothstep(vec3s edge0, vec3s edge1, vec3s x) {
865
+ vec3s r;
866
+ glm_vec3_smoothstep(edge0.raw, edge1.raw, x.raw, r.raw);
867
+ return r;
868
+ }
869
+
870
+ /*!
871
+ * @brief smooth Hermite interpolation between two vectors
872
+ *
873
+ * formula: from + s * (to - from)
874
+ *
875
+ * @param[in] from from value
876
+ * @param[in] to to value
877
+ * @param[in] t interpolant (amount)
878
+ * @returns destination
879
+ */
880
+ CGLM_INLINE
881
+ vec3s
882
+ glms_vec3_smoothinterp(vec3s from, vec3s to, float t) {
883
+ vec3s r;
884
+ glm_vec3_smoothinterp(from.raw, to.raw, t, r.raw);
885
+ return r;
886
+ }
887
+
888
+ /*!
889
+ * @brief smooth Hermite interpolation between two vectors (clamped)
890
+ *
891
+ * formula: from + s * (to - from)
892
+ *
893
+ * @param[in] from from value
894
+ * @param[in] to to value
895
+ * @param[in] t interpolant (amount) clamped between 0 and 1
896
+ * @returns destination
897
+ */
898
+ CGLM_INLINE
899
+ vec3s
900
+ glms_vec3_smoothinterpc(vec3s from, vec3s to, float t) {
901
+ vec3s r;
902
+ glm_vec3_smoothinterpc(from.raw, to.raw, t, r.raw);
903
+ return r;
904
+ }
905
+
906
+ /*!
907
+ * @brief vec3 cross product
908
+ *
909
+ * this is just convenient wrapper
910
+ *
911
+ * @param[in] a source 1
912
+ * @param[in] b source 2
913
+ * @returns destination
914
+ */
915
+ CGLM_INLINE
916
+ vec3s
917
+ glms_cross(vec3s a, vec3s b) {
918
+ vec3s r;
919
+ glm_cross(a.raw, b.raw, r.raw);
920
+ return r;
921
+ }
922
+
923
+ /*!
924
+ * @brief vec3 dot product
925
+ *
926
+ * this is just convenient wrapper
927
+ *
928
+ * @param[in] a vector1
929
+ * @param[in] b vector2
930
+ * @return dot product
931
+ */
932
+ CGLM_INLINE
933
+ float
934
+ glms_dot(vec3s a, vec3s b) {
935
+ return glm_dot(a.raw, b.raw);
936
+ }
937
+
938
+ /*!
939
+ * @brief normalize vec3 and store result in same vec
940
+ *
941
+ * this is just convenient wrapper
942
+ *
943
+ * @param[in] v vector
944
+ * @returns normalized vector
945
+ */
946
+ CGLM_INLINE
947
+ vec3s
948
+ glms_normalize(vec3s v) {
949
+ glm_normalize(v.raw);
950
+ return v;
951
+ }
952
+
953
+ /*!
954
+ * @brief swizzle vector components
955
+ *
956
+ * you can use existin masks e.g. GLM_XXX, GLM_ZYX
957
+ *
958
+ * @param[in] v source
959
+ * @param[in] mask mask
960
+ * @returns swizzled vector
961
+ */
962
+ CGLM_INLINE
963
+ vec3s
964
+ glms_vec3_swizzle(vec3s v, int mask) {
965
+ vec3s dest;
966
+ glm_vec3_swizzle(v.raw, mask, dest.raw);
967
+ return dest;
968
+ }
969
+
970
+ #endif /* cglms_vec3s_h */