1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE mat4s glms_translate(mat4s m, vec3s v);
CGLM_INLINE mat4s glms_translate_x(mat4s m, float x);
CGLM_INLINE mat4s glms_translate_y(mat4s m, float y);
CGLM_INLINE mat4s glms_translate_z(mat4s m, float z);
CGLM_INLINE mat4s glms_translate_make(vec3s v);
CGLM_INLINE mat4s glms_scale_to(mat4s m, vec3s v);
CGLM_INLINE mat4s glms_scale_make(vec3s v);
CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v);
CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s);
CGLM_INLINE mat4s glms_rotate_x(mat4s m, float angle);
CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle);
CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle);
CGLM_INLINE mat4s glms_rotate_make(float angle, vec3s axis);
CGLM_INLINE mat4s glms_rotate(mat4s m, float angle, vec3s axis);
CGLM_INLINE mat4s glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis);
CGLM_INLINE mat4s glms_rotate_atm(vec3s pivot, float angle, vec3s axis);
CGLM_INLINE mat4s glms_spin(mat4s m, float angle, vec3s axis);
CGLM_INLINE vec3s glms_decompose_scalev(mat4s m);
CGLM_INLINE bool glms_uniscaled(mat4s m);
CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s * r, vec3s * s);
CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s * r, vec3s * s);
*/
#ifndef cglms_affines_h
#define cglms_affines_h
#include "../common.h"
#include "../types-struct.h"
#include "../affine.h"
#include "vec3.h"
#include "vec4.h"
#include "mat4.h"
#include "affine-mat.h"
/*!
* @brief creates NEW translate transform matrix by v vector
*
* @param[in] v translate vector [x, y, z]
* @returns affine transform
*/
CGLM_INLINE
mat4s
glms_translate_make(vec3s v) {
mat4s m;
glm_translate_make(m.raw, v.raw);
return m;
}
/*!
* @brief creates NEW scale matrix by v vector
*
* @param[in] v scale vector [x, y, z]
* @returns affine transform
*/
CGLM_INLINE
mat4s
glms_scale_make(vec3s v) {
mat4s m;
glm_scale_make(m.raw, v.raw);
return m;
}
/*!
* @brief scales existing transform matrix by v vector
* and stores result in same matrix
*
* @param[in] m affine transform
* @param[in] v scale vector [x, y, z]
* @returns affine transform
*/
CGLM_INLINE
mat4s
glms_scale(mat4s m, vec3s v) {
mat4s r;
glm_scale_to(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief applies uniform scale to existing transform matrix v = [s, s, s]
* and stores result in same matrix
*
* @param[in] m affine transform
* @param[in] s scale factor
* @returns affine transform
*/
CGLM_INLINE
mat4s
glms_scale_uni(mat4s m, float s) {
glm_scale_uni(m.raw, s);
return m;
}
/*!
* @brief creates NEW rotation matrix by angle and axis
*
* axis will be normalized so you don't need to normalize it
*
* @param[in] angle angle (radians)
* @param[in] axis axis
* @returns affine transform
*/
CGLM_INLINE
mat4s
glms_rotate_make(float angle, vec3s axis) {
mat4s m;
glm_rotate_make(m.raw, angle, axis.raw);
return m;
}
/*!
* @brief creates NEW rotation matrix by angle and axis at given point
*
* this creates rotation matrix, it assumes you don't have a matrix
*
* this should work faster than glm_rotate_at because it reduces
* one glm_translate.
*
* @param[in] pivot rotation center
* @param[in] angle angle (radians)
* @param[in] axis axis
* @returns affine transform
*/
CGLM_INLINE
mat4s
glms_rotate_atm(vec3s pivot, float angle, vec3s axis) {
mat4s m;
glm_rotate_atm(m.raw, pivot.raw, angle, axis.raw);
return m;
}
/*!
* @brief decompose scale vector
*
* @param[in] m affine transform
* @returns scale vector (Sx, Sy, Sz)
*/
CGLM_INLINE
vec3s
glms_decompose_scalev(mat4s m) {
vec3s r;
glm_decompose_scalev(m.raw, r.raw);
return r;
}
/*!
* @brief returns true if matrix is uniform scaled. This is helpful for
* creating normal matrix.
*
* @param[in] m m
*
* @return boolean
*/
CGLM_INLINE
bool
glms_uniscaled(mat4s m) {
return glm_uniscaled(m.raw);
}
/*!
* @brief decompose rotation matrix (mat4) and scale vector [Sx, Sy, Sz]
* DON'T pass projected matrix here
*
* @param[in] m affine transform
* @param[out] r rotation matrix
* @param[out] s scale matrix
*/
CGLM_INLINE
void
glms_decompose_rs(mat4s m, mat4s * __restrict r, vec3s * __restrict s) {
glm_decompose_rs(m.raw, r->raw, s->raw);
}
/*!
* @brief decompose affine transform, TODO: extract shear factors.
* DON'T pass projected matrix here
*
* @param[in] m affine transform
* @param[out] t translation vector
* @param[out] r rotation matrix (mat4)
* @param[out] s scaling vector [X, Y, Z]
*/
CGLM_INLINE
void
glms_decompose(mat4s m, vec4s * __restrict t, mat4s * __restrict r, vec3s * __restrict s) {
glm_decompose(m.raw, t->raw, r->raw, s->raw);
}
#include "affine-pre.h"
#include "affine-post.h"
#endif /* cglms_affines_h */
|