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,99 @@
|
|
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_sphere_h
|
9
|
+
#define cglm_sphere_h
|
10
|
+
|
11
|
+
#include "common.h"
|
12
|
+
#include "mat4.h"
|
13
|
+
|
14
|
+
/*
|
15
|
+
Sphere Representation in cglm: [center.x, center.y, center.z, radii]
|
16
|
+
|
17
|
+
You could use this representation or you can convert it to vec4 before call
|
18
|
+
any function
|
19
|
+
*/
|
20
|
+
|
21
|
+
/*!
|
22
|
+
* @brief helper for getting sphere radius
|
23
|
+
*
|
24
|
+
* @param[in] s sphere
|
25
|
+
*
|
26
|
+
* @return returns radii
|
27
|
+
*/
|
28
|
+
CGLM_INLINE
|
29
|
+
float
|
30
|
+
glm_sphere_radii(vec4 s) {
|
31
|
+
return s[3];
|
32
|
+
}
|
33
|
+
|
34
|
+
/*!
|
35
|
+
* @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3
|
36
|
+
*
|
37
|
+
* @param[in] s sphere
|
38
|
+
* @param[in] m transform matrix
|
39
|
+
* @param[out] dest transformed sphere
|
40
|
+
*/
|
41
|
+
CGLM_INLINE
|
42
|
+
void
|
43
|
+
glm_sphere_transform(vec4 s, mat4 m, vec4 dest) {
|
44
|
+
glm_mat4_mulv3(m, s, 1.0f, dest);
|
45
|
+
dest[3] = s[3];
|
46
|
+
}
|
47
|
+
|
48
|
+
/*!
|
49
|
+
* @brief merges two spheres and creates a new one
|
50
|
+
*
|
51
|
+
* two sphere must be in same space, for instance if one in world space then
|
52
|
+
* the other must be in world space too, not in local space.
|
53
|
+
*
|
54
|
+
* @param[in] s1 sphere 1
|
55
|
+
* @param[in] s2 sphere 2
|
56
|
+
* @param[out] dest merged/extended sphere
|
57
|
+
*/
|
58
|
+
CGLM_INLINE
|
59
|
+
void
|
60
|
+
glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) {
|
61
|
+
float dist, radii;
|
62
|
+
|
63
|
+
dist = glm_vec3_distance(s1, s2);
|
64
|
+
radii = dist + s1[3] + s2[3];
|
65
|
+
|
66
|
+
radii = glm_max(radii, s1[3]);
|
67
|
+
radii = glm_max(radii, s2[3]);
|
68
|
+
|
69
|
+
glm_vec3_center(s1, s2, dest);
|
70
|
+
dest[3] = radii;
|
71
|
+
}
|
72
|
+
|
73
|
+
/*!
|
74
|
+
* @brief check if two sphere intersects
|
75
|
+
*
|
76
|
+
* @param[in] s1 sphere
|
77
|
+
* @param[in] s2 other sphere
|
78
|
+
*/
|
79
|
+
CGLM_INLINE
|
80
|
+
bool
|
81
|
+
glm_sphere_sphere(vec4 s1, vec4 s2) {
|
82
|
+
return glm_vec3_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]);
|
83
|
+
}
|
84
|
+
|
85
|
+
/*!
|
86
|
+
* @brief check if sphere intersects with point
|
87
|
+
*
|
88
|
+
* @param[in] s sphere
|
89
|
+
* @param[in] point point
|
90
|
+
*/
|
91
|
+
CGLM_INLINE
|
92
|
+
bool
|
93
|
+
glm_sphere_point(vec4 s, vec3 point) {
|
94
|
+
float rr;
|
95
|
+
rr = s[3] * s[3];
|
96
|
+
return glm_vec3_distance2(point, s) <= rr;
|
97
|
+
}
|
98
|
+
|
99
|
+
#endif /* cglm_sphere_h */
|
@@ -0,0 +1,337 @@
|
|
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 mat4s glms_translate(mat4s m, vec3s v);
|
11
|
+
CGLM_INLINE mat4s glms_translate_x(mat4s m, float x);
|
12
|
+
CGLM_INLINE mat4s glms_translate_y(mat4s m, float y);
|
13
|
+
CGLM_INLINE mat4s glms_translate_z(mat4s m, float z);
|
14
|
+
CGLM_INLINE mat4s glms_translate_make(vec3s v);
|
15
|
+
CGLM_INLINE mat4s glms_scale_to(mat4s m, vec3s v);
|
16
|
+
CGLM_INLINE mat4s glms_scale_make(vec3s v);
|
17
|
+
CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v);
|
18
|
+
CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s);
|
19
|
+
CGLM_INLINE mat4s glms_rotate_x(mat4s m, float angle);
|
20
|
+
CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle);
|
21
|
+
CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle);
|
22
|
+
CGLM_INLINE mat4s glms_rotate_make(float angle, vec3s axis);
|
23
|
+
CGLM_INLINE mat4s glms_rotate(mat4s m, float angle, vec3s axis);
|
24
|
+
CGLM_INLINE mat4s glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis);
|
25
|
+
CGLM_INLINE mat4s glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis);
|
26
|
+
CGLM_INLINE vec3s glms_decompose_scalev(mat4s m);
|
27
|
+
CGLM_INLINE bool glms_uniscaled(mat4s m);
|
28
|
+
CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s * r, vec3s * s);
|
29
|
+
CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s * r, vec3s * s);
|
30
|
+
*/
|
31
|
+
|
32
|
+
#ifndef cglms_affines_h
|
33
|
+
#define cglms_affines_h
|
34
|
+
|
35
|
+
#include "../common.h"
|
36
|
+
#include "../types-struct.h"
|
37
|
+
#include "../affine.h"
|
38
|
+
#include "vec3.h"
|
39
|
+
#include "vec4.h"
|
40
|
+
#include "mat4.h"
|
41
|
+
|
42
|
+
CGLM_INLINE
|
43
|
+
mat4s
|
44
|
+
glms_mat4_mul(mat4s m1, mat4s m2);
|
45
|
+
|
46
|
+
/*!
|
47
|
+
* @brief translate existing transform matrix by v vector
|
48
|
+
* and stores result in same matrix
|
49
|
+
*
|
50
|
+
* @param[in] m affine transfrom
|
51
|
+
* @param[in] v translate vector [x, y, z]
|
52
|
+
* @returns affine transfrom
|
53
|
+
*/
|
54
|
+
CGLM_INLINE
|
55
|
+
mat4s
|
56
|
+
glms_translate(mat4s m, vec3s v) {
|
57
|
+
glm_translate(m.raw, v.raw);
|
58
|
+
return m;
|
59
|
+
}
|
60
|
+
|
61
|
+
/*!
|
62
|
+
* @brief translate existing transform matrix by x factor
|
63
|
+
*
|
64
|
+
* @param[in] m affine transfrom
|
65
|
+
* @param[in] x x factor
|
66
|
+
* @returns affine transfrom
|
67
|
+
*/
|
68
|
+
CGLM_INLINE
|
69
|
+
mat4s
|
70
|
+
glms_translate_x(mat4s m, float x) {
|
71
|
+
glm_translate_x(m.raw, x);
|
72
|
+
return m;
|
73
|
+
}
|
74
|
+
|
75
|
+
/*!
|
76
|
+
* @brief translate existing transform matrix by y factor
|
77
|
+
*
|
78
|
+
* @param[in] m affine transfrom
|
79
|
+
* @param[in] y y factor
|
80
|
+
* @returns affine transfrom
|
81
|
+
*/
|
82
|
+
CGLM_INLINE
|
83
|
+
mat4s
|
84
|
+
glms_translate_y(mat4s m, float y) {
|
85
|
+
glm_translate_y(m.raw, y);
|
86
|
+
return m;
|
87
|
+
}
|
88
|
+
|
89
|
+
/*!
|
90
|
+
* @brief translate existing transform matrix by z factor
|
91
|
+
*
|
92
|
+
* @param[in] m affine transfrom
|
93
|
+
* @param[in] z z factor
|
94
|
+
* @returns affine transfrom
|
95
|
+
*/
|
96
|
+
CGLM_INLINE
|
97
|
+
mat4s
|
98
|
+
glms_translate_z(mat4s m, float z) {
|
99
|
+
glm_translate_z(m.raw, z);
|
100
|
+
return m;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*!
|
104
|
+
* @brief creates NEW translate transform matrix by v vector
|
105
|
+
*
|
106
|
+
* @param[in] v translate vector [x, y, z]
|
107
|
+
* @returns affine transfrom
|
108
|
+
*/
|
109
|
+
CGLM_INLINE
|
110
|
+
mat4s
|
111
|
+
glms_translate_make(vec3s v) {
|
112
|
+
mat4s m;
|
113
|
+
glm_translate_make(m.raw, v.raw);
|
114
|
+
return m;
|
115
|
+
}
|
116
|
+
|
117
|
+
/*!
|
118
|
+
* @brief creates NEW scale matrix by v vector
|
119
|
+
*
|
120
|
+
* @param[in] v scale vector [x, y, z]
|
121
|
+
* @returns affine transfrom
|
122
|
+
*/
|
123
|
+
CGLM_INLINE
|
124
|
+
mat4s
|
125
|
+
glms_scale_make(vec3s v) {
|
126
|
+
mat4s m;
|
127
|
+
glm_scale_make(m.raw, v.raw);
|
128
|
+
return m;
|
129
|
+
}
|
130
|
+
|
131
|
+
/*!
|
132
|
+
* @brief scales existing transform matrix by v vector
|
133
|
+
* and stores result in same matrix
|
134
|
+
*
|
135
|
+
* @param[in] m affine transfrom
|
136
|
+
* @param[in] v scale vector [x, y, z]
|
137
|
+
* @returns affine transfrom
|
138
|
+
*/
|
139
|
+
CGLM_INLINE
|
140
|
+
mat4s
|
141
|
+
glms_scale(mat4s m, vec3s v) {
|
142
|
+
mat4s r;
|
143
|
+
glm_scale_to(m.raw, v.raw, r.raw);
|
144
|
+
return r;
|
145
|
+
}
|
146
|
+
|
147
|
+
/*!
|
148
|
+
* @brief applies uniform scale to existing transform matrix v = [s, s, s]
|
149
|
+
* and stores result in same matrix
|
150
|
+
*
|
151
|
+
* @param[in] m affine transfrom
|
152
|
+
* @param[in] s scale factor
|
153
|
+
* @returns affine transfrom
|
154
|
+
*/
|
155
|
+
CGLM_INLINE
|
156
|
+
mat4s
|
157
|
+
glms_scale_uni(mat4s m, float s) {
|
158
|
+
glm_scale_uni(m.raw, s);
|
159
|
+
return m;
|
160
|
+
}
|
161
|
+
|
162
|
+
/*!
|
163
|
+
* @brief rotate existing transform matrix around X axis by angle
|
164
|
+
* and store result in dest
|
165
|
+
*
|
166
|
+
* @param[in] m affine transfrom
|
167
|
+
* @param[in] angle angle (radians)
|
168
|
+
* @returns rotated matrix
|
169
|
+
*/
|
170
|
+
CGLM_INLINE
|
171
|
+
mat4s
|
172
|
+
glms_rotate_x(mat4s m, float angle) {
|
173
|
+
mat4s r;
|
174
|
+
glm_rotate_x(m.raw, angle, r.raw);
|
175
|
+
return r;
|
176
|
+
}
|
177
|
+
|
178
|
+
/*!
|
179
|
+
* @brief rotate existing transform matrix around Y axis by angle
|
180
|
+
* and store result in dest
|
181
|
+
*
|
182
|
+
* @param[in] m affine transfrom
|
183
|
+
* @param[in] angle angle (radians)
|
184
|
+
* @returns rotated matrix
|
185
|
+
*/
|
186
|
+
CGLM_INLINE
|
187
|
+
mat4s
|
188
|
+
glms_rotate_y(mat4s m, float angle) {
|
189
|
+
mat4s r;
|
190
|
+
glm_rotate_y(m.raw, angle, r.raw);
|
191
|
+
return r;
|
192
|
+
}
|
193
|
+
|
194
|
+
/*!
|
195
|
+
* @brief rotate existing transform matrix around Z axis by angle
|
196
|
+
* and store result in dest
|
197
|
+
*
|
198
|
+
* @param[in] m affine transfrom
|
199
|
+
* @param[in] angle angle (radians)
|
200
|
+
* @returns rotated matrix
|
201
|
+
*/
|
202
|
+
CGLM_INLINE
|
203
|
+
mat4s
|
204
|
+
glms_rotate_z(mat4s m, float angle) {
|
205
|
+
mat4s r;
|
206
|
+
glm_rotate_z(m.raw, angle, r.raw);
|
207
|
+
return r;
|
208
|
+
}
|
209
|
+
|
210
|
+
/*!
|
211
|
+
* @brief creates NEW rotation matrix by angle and axis
|
212
|
+
*
|
213
|
+
* axis will be normalized so you don't need to normalize it
|
214
|
+
*
|
215
|
+
* @param[in] angle angle (radians)
|
216
|
+
* @param[in] axis axis
|
217
|
+
* @returns affine transfrom
|
218
|
+
*/
|
219
|
+
CGLM_INLINE
|
220
|
+
mat4s
|
221
|
+
glms_rotate_make(float angle, vec3s axis) {
|
222
|
+
mat4s m;
|
223
|
+
glm_rotate_make(m.raw, angle, axis.raw);
|
224
|
+
return m;
|
225
|
+
}
|
226
|
+
|
227
|
+
/*!
|
228
|
+
* @brief rotate existing transform matrix around given axis by angle
|
229
|
+
*
|
230
|
+
* @param[in] m affine transfrom
|
231
|
+
* @param[in] angle angle (radians)
|
232
|
+
* @param[in] axis axis
|
233
|
+
* @returns affine transfrom
|
234
|
+
*/
|
235
|
+
CGLM_INLINE
|
236
|
+
mat4s
|
237
|
+
glms_rotate(mat4s m, float angle, vec3s axis) {
|
238
|
+
glm_rotate(m.raw, angle, axis.raw);
|
239
|
+
return m;
|
240
|
+
}
|
241
|
+
|
242
|
+
/*!
|
243
|
+
* @brief rotate existing transform
|
244
|
+
* around given axis by angle at given pivot point (rotation center)
|
245
|
+
*
|
246
|
+
* @param[in] m affine transfrom
|
247
|
+
* @param[in] pivot rotation center
|
248
|
+
* @param[in] angle angle (radians)
|
249
|
+
* @param[in] axis axis
|
250
|
+
* @returns affine transfrom
|
251
|
+
*/
|
252
|
+
CGLM_INLINE
|
253
|
+
mat4s
|
254
|
+
glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis) {
|
255
|
+
glm_rotate_at(m.raw, pivot.raw, angle, axis.raw);
|
256
|
+
return m;
|
257
|
+
}
|
258
|
+
|
259
|
+
/*!
|
260
|
+
* @brief creates NEW rotation matrix by angle and axis at given point
|
261
|
+
*
|
262
|
+
* this creates rotation matrix, it assumes you don't have a matrix
|
263
|
+
*
|
264
|
+
* this should work faster than glm_rotate_at because it reduces
|
265
|
+
* one glm_translate.
|
266
|
+
*
|
267
|
+
* @param[in] m affine transfrom
|
268
|
+
* @param[in] pivot rotation center
|
269
|
+
* @param[in] angle angle (radians)
|
270
|
+
* @param[in] axis axis
|
271
|
+
* @returns affine transfrom
|
272
|
+
*/
|
273
|
+
CGLM_INLINE
|
274
|
+
mat4s
|
275
|
+
glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis) {
|
276
|
+
glm_rotate_atm(m.raw, pivot.raw, angle, axis.raw);
|
277
|
+
return m;
|
278
|
+
}
|
279
|
+
|
280
|
+
/*!
|
281
|
+
* @brief decompose scale vector
|
282
|
+
*
|
283
|
+
* @param[in] m affine transform
|
284
|
+
* @returns scale vector (Sx, Sy, Sz)
|
285
|
+
*/
|
286
|
+
CGLM_INLINE
|
287
|
+
vec3s
|
288
|
+
glms_decompose_scalev(mat4s m) {
|
289
|
+
vec3s r;
|
290
|
+
glm_decompose_scalev(m.raw, r.raw);
|
291
|
+
return r;
|
292
|
+
}
|
293
|
+
|
294
|
+
/*!
|
295
|
+
* @brief returns true if matrix is uniform scaled. This is helpful for
|
296
|
+
* creating normal matrix.
|
297
|
+
*
|
298
|
+
* @param[in] m m
|
299
|
+
*
|
300
|
+
* @return boolean
|
301
|
+
*/
|
302
|
+
CGLM_INLINE
|
303
|
+
bool
|
304
|
+
glms_uniscaled(mat4s m) {
|
305
|
+
return glm_uniscaled(m.raw);
|
306
|
+
}
|
307
|
+
|
308
|
+
/*!
|
309
|
+
* @brief decompose rotation matrix (mat4) and scale vector [Sx, Sy, Sz]
|
310
|
+
* DON'T pass projected matrix here
|
311
|
+
*
|
312
|
+
* @param[in] m affine transform
|
313
|
+
* @param[out] r rotation matrix
|
314
|
+
* @param[out] s scale matrix
|
315
|
+
*/
|
316
|
+
CGLM_INLINE
|
317
|
+
void
|
318
|
+
glms_decompose_rs(mat4s m, mat4s * __restrict r, vec3s * __restrict s) {
|
319
|
+
glm_decompose_rs(m.raw, r->raw, s->raw);
|
320
|
+
}
|
321
|
+
|
322
|
+
/*!
|
323
|
+
* @brief decompose affine transform, TODO: extract shear factors.
|
324
|
+
* DON'T pass projected matrix here
|
325
|
+
*
|
326
|
+
* @param[in] m affine transfrom
|
327
|
+
* @param[out] t translation vector
|
328
|
+
* @param[out] r rotation matrix (mat4)
|
329
|
+
* @param[out] s scaling vector [X, Y, Z]
|
330
|
+
*/
|
331
|
+
CGLM_INLINE
|
332
|
+
void
|
333
|
+
glms_decompose(mat4s m, vec4s * __restrict t, mat4s * __restrict r, vec3s * __restrict s) {
|
334
|
+
glm_decompose(m.raw, t->raw, r->raw, s->raw);
|
335
|
+
}
|
336
|
+
|
337
|
+
#endif /* cglms_affines_h */
|
@@ -0,0 +1,256 @@
|
|
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_boxs_h
|
9
|
+
#define cglms_boxs_h
|
10
|
+
|
11
|
+
#include "../common.h"
|
12
|
+
#include "../types-struct.h"
|
13
|
+
#include "../box.h"
|
14
|
+
#include "vec3.h"
|
15
|
+
#include "vec4.h"
|
16
|
+
#include "mat4.h"
|
17
|
+
|
18
|
+
/*!
|
19
|
+
* @brief apply transform to Axis-Aligned Bounding Box
|
20
|
+
*
|
21
|
+
* @param[in] box bounding box
|
22
|
+
* @param[in] m transform matrix
|
23
|
+
* @param[out] dest transformed bounding box
|
24
|
+
*/
|
25
|
+
CGLM_INLINE
|
26
|
+
void
|
27
|
+
glms_aabb_transform(vec3s box[2], mat4s m, vec3s dest[2]) {
|
28
|
+
vec3 rawBox[2];
|
29
|
+
vec3 rawDest[2];
|
30
|
+
|
31
|
+
glms_vec3_unpack(rawBox, box, 2);
|
32
|
+
glm_aabb_transform(rawBox, m.raw, rawDest);
|
33
|
+
glms_vec3_pack(dest, rawDest, 2);
|
34
|
+
}
|
35
|
+
|
36
|
+
/*!
|
37
|
+
* @brief merges two AABB bounding box and creates new one
|
38
|
+
*
|
39
|
+
* two box must be in same space, if one of box is in different space then
|
40
|
+
* you should consider to convert it's space by glm_box_space
|
41
|
+
*
|
42
|
+
* @param[in] box1 bounding box 1
|
43
|
+
* @param[in] box2 bounding box 2
|
44
|
+
* @param[out] dest merged bounding box
|
45
|
+
*/
|
46
|
+
CGLM_INLINE
|
47
|
+
void
|
48
|
+
glms_aabb_merge(vec3s box1[2], vec3s box2[2], vec3s dest[2]) {
|
49
|
+
vec3 rawBox1[2];
|
50
|
+
vec3 rawBox2[2];
|
51
|
+
vec3 rawDest[2];
|
52
|
+
|
53
|
+
glms_vec3_unpack(rawBox1, box1, 2);
|
54
|
+
glms_vec3_unpack(rawBox2, box2, 2);
|
55
|
+
glm_aabb_merge(rawBox1, rawBox2, rawDest);
|
56
|
+
glms_vec3_pack(dest, rawDest, 2);
|
57
|
+
}
|
58
|
+
|
59
|
+
/*!
|
60
|
+
* @brief crops a bounding box with another one.
|
61
|
+
*
|
62
|
+
* this could be useful for gettng a bbox which fits with view frustum and
|
63
|
+
* object bounding boxes. In this case you crop view frustum box with objects
|
64
|
+
* box
|
65
|
+
*
|
66
|
+
* @param[in] box bounding box 1
|
67
|
+
* @param[in] cropBox crop box
|
68
|
+
* @param[out] dest cropped bounding box
|
69
|
+
*/
|
70
|
+
CGLM_INLINE
|
71
|
+
void
|
72
|
+
glms_aabb_crop(vec3s box[2], vec3s cropBox[2], vec3s dest[2]) {
|
73
|
+
vec3 rawBox[2];
|
74
|
+
vec3 rawCropBox[2];
|
75
|
+
vec3 rawDest[2];
|
76
|
+
|
77
|
+
glms_vec3_unpack(rawBox, box, 2);
|
78
|
+
glms_vec3_unpack(rawCropBox, cropBox, 2);
|
79
|
+
glm_aabb_crop(rawBox, rawCropBox, rawDest);
|
80
|
+
glms_vec3_pack(dest, rawDest, 2);
|
81
|
+
}
|
82
|
+
|
83
|
+
/*!
|
84
|
+
* @brief crops a bounding box with another one.
|
85
|
+
*
|
86
|
+
* this could be useful for gettng a bbox which fits with view frustum and
|
87
|
+
* object bounding boxes. In this case you crop view frustum box with objects
|
88
|
+
* box
|
89
|
+
*
|
90
|
+
* @param[in] box bounding box
|
91
|
+
* @param[in] cropBox crop box
|
92
|
+
* @param[in] clampBox miniumum box
|
93
|
+
* @param[out] dest cropped bounding box
|
94
|
+
*/
|
95
|
+
CGLM_INLINE
|
96
|
+
void
|
97
|
+
glms_aabb_crop_until(vec3s box[2],
|
98
|
+
vec3s cropBox[2],
|
99
|
+
vec3s clampBox[2],
|
100
|
+
vec3s dest[2]) {
|
101
|
+
glms_aabb_crop(box, cropBox, dest);
|
102
|
+
glms_aabb_merge(clampBox, dest, dest);
|
103
|
+
}
|
104
|
+
|
105
|
+
/*!
|
106
|
+
* @brief check if AABB intersects with frustum planes
|
107
|
+
*
|
108
|
+
* this could be useful for frustum culling using AABB.
|
109
|
+
*
|
110
|
+
* OPTIMIZATION HINT:
|
111
|
+
* if planes order is similar to LEFT, RIGHT, BOTTOM, TOP, NEAR, FAR
|
112
|
+
* then this method should run even faster because it would only use two
|
113
|
+
* planes if object is not inside the two planes
|
114
|
+
* fortunately cglm extracts planes as this order! just pass what you got!
|
115
|
+
*
|
116
|
+
* @param[in] box bounding box
|
117
|
+
* @param[in] planes frustum planes
|
118
|
+
*/
|
119
|
+
CGLM_INLINE
|
120
|
+
bool
|
121
|
+
glms_aabb_frustum(vec3s box[2], vec4s planes[6]) {
|
122
|
+
vec3 rawBox[2];
|
123
|
+
vec4 rawPlanes[6];
|
124
|
+
|
125
|
+
glms_vec3_unpack(rawBox, box, 2);
|
126
|
+
glms_vec4_unpack(rawPlanes, planes, 6);
|
127
|
+
return glm_aabb_frustum(rawBox, rawPlanes);
|
128
|
+
}
|
129
|
+
|
130
|
+
/*!
|
131
|
+
* @brief invalidate AABB min and max values
|
132
|
+
*
|
133
|
+
* @param[in, out] box bounding box
|
134
|
+
*/
|
135
|
+
CGLM_INLINE
|
136
|
+
void
|
137
|
+
glms_aabb_invalidate(vec3s box[2]) {
|
138
|
+
box[0] = glms_vec3_broadcast(FLT_MAX);
|
139
|
+
box[1] = glms_vec3_broadcast(-FLT_MAX);
|
140
|
+
}
|
141
|
+
|
142
|
+
/*!
|
143
|
+
* @brief check if AABB is valid or not
|
144
|
+
*
|
145
|
+
* @param[in] box bounding box
|
146
|
+
*/
|
147
|
+
CGLM_INLINE
|
148
|
+
bool
|
149
|
+
glms_aabb_isvalid(vec3s box[2]) {
|
150
|
+
vec3 rawBox[2];
|
151
|
+
glms_vec3_unpack(rawBox, box, 2);
|
152
|
+
return glm_aabb_isvalid(rawBox);
|
153
|
+
}
|
154
|
+
|
155
|
+
/*!
|
156
|
+
* @brief distance between of min and max
|
157
|
+
*
|
158
|
+
* @param[in] box bounding box
|
159
|
+
*/
|
160
|
+
CGLM_INLINE
|
161
|
+
float
|
162
|
+
glms_aabb_size(vec3s box[2]) {
|
163
|
+
return glm_vec3_distance(box[0].raw, box[1].raw);
|
164
|
+
}
|
165
|
+
|
166
|
+
/*!
|
167
|
+
* @brief radius of sphere which surrounds AABB
|
168
|
+
*
|
169
|
+
* @param[in] box bounding box
|
170
|
+
*/
|
171
|
+
CGLM_INLINE
|
172
|
+
float
|
173
|
+
glms_aabb_radius(vec3s box[2]) {
|
174
|
+
return glms_aabb_size(box) * 0.5f;
|
175
|
+
}
|
176
|
+
|
177
|
+
/*!
|
178
|
+
* @brief computes center point of AABB
|
179
|
+
*
|
180
|
+
* @param[in] box bounding box
|
181
|
+
* @returns center of bounding box
|
182
|
+
*/
|
183
|
+
CGLM_INLINE
|
184
|
+
vec3s
|
185
|
+
glms_aabb_center(vec3s box[2]) {
|
186
|
+
return glms_vec3_center(box[0], box[1]);
|
187
|
+
}
|
188
|
+
|
189
|
+
/*!
|
190
|
+
* @brief check if two AABB intersects
|
191
|
+
*
|
192
|
+
* @param[in] box bounding box
|
193
|
+
* @param[in] other other bounding box
|
194
|
+
*/
|
195
|
+
CGLM_INLINE
|
196
|
+
bool
|
197
|
+
glms_aabb_aabb(vec3s box[2], vec3s other[2]) {
|
198
|
+
vec3 rawBox[2];
|
199
|
+
vec3 rawOther[2];
|
200
|
+
|
201
|
+
glms_vec3_unpack(rawBox, box, 2);
|
202
|
+
glms_vec3_unpack(rawOther, other, 2);
|
203
|
+
return glm_aabb_aabb(rawBox, rawOther);
|
204
|
+
}
|
205
|
+
|
206
|
+
/*!
|
207
|
+
* @brief check if AABB intersects with sphere
|
208
|
+
*
|
209
|
+
* https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c
|
210
|
+
* Solid Box - Solid Sphere test.
|
211
|
+
*
|
212
|
+
* @param[in] box solid bounding box
|
213
|
+
* @param[in] s solid sphere
|
214
|
+
*/
|
215
|
+
CGLM_INLINE
|
216
|
+
bool
|
217
|
+
glms_aabb_sphere(vec3s box[2], vec4s s) {
|
218
|
+
vec3 rawBox[2];
|
219
|
+
|
220
|
+
glms_vec3_unpack(rawBox, box, 2);
|
221
|
+
return glm_aabb_sphere(rawBox, s.raw);
|
222
|
+
}
|
223
|
+
|
224
|
+
/*!
|
225
|
+
* @brief check if point is inside of AABB
|
226
|
+
*
|
227
|
+
* @param[in] box bounding box
|
228
|
+
* @param[in] point point
|
229
|
+
*/
|
230
|
+
CGLM_INLINE
|
231
|
+
bool
|
232
|
+
glms_aabb_point(vec3s box[2], vec3s point) {
|
233
|
+
vec3 rawBox[2];
|
234
|
+
|
235
|
+
glms_vec3_unpack(rawBox, box, 2);
|
236
|
+
return glm_aabb_point(rawBox, point.raw);
|
237
|
+
}
|
238
|
+
|
239
|
+
/*!
|
240
|
+
* @brief check if AABB contains other AABB
|
241
|
+
*
|
242
|
+
* @param[in] box bounding box
|
243
|
+
* @param[in] other other bounding box
|
244
|
+
*/
|
245
|
+
CGLM_INLINE
|
246
|
+
bool
|
247
|
+
glms_aabb_contains(vec3s box[2], vec3s other[2]) {
|
248
|
+
vec3 rawBox[2];
|
249
|
+
vec3 rawOther[2];
|
250
|
+
|
251
|
+
glms_vec3_unpack(rawBox, box, 2);
|
252
|
+
glms_vec3_unpack(rawOther, other, 2);
|
253
|
+
return glm_aabb_contains(rawBox, rawOther);
|
254
|
+
}
|
255
|
+
|
256
|
+
#endif /* cglms_boxs_h */
|