summaryrefslogtreecommitdiff
path: root/include/cglm/struct/affine-post.h
blob: e155660ce8b7bd3346bc8ffb315f57cb47d23d24 (plain) (blame)
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
/*
 * 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_translated(mat4s m, vec3s v);
   CGLM_INLINE mat4s glms_translated_x(mat4s m, float x);
   CGLM_INLINE mat4s glms_translated_y(mat4s m, float y);
   CGLM_INLINE mat4s glms_translated_z(mat4s m, float z);
   CGLM_INLINE mat4s glms_rotated_x(mat4s m, float angle);
   CGLM_INLINE mat4s glms_rotated_y(mat4s m, float angle);
   CGLM_INLINE mat4s glms_rotated_z(mat4s m, float angle);
   CGLM_INLINE mat4s glms_rotated(mat4s m, float angle, vec3s axis);
   CGLM_INLINE mat4s glms_rotated_at(mat4s m, vec3s pivot, float angle, vec3s axis);
   CGLM_INLINE mat4s glms_spinned(mat4s m, float angle, vec3s axis);
 */

#ifndef cglms_affines_post_h
#define cglms_affines_post_h

#include "../common.h"
#include "../types-struct.h"
#include "../affine.h"
#include "vec3.h"
#include "vec4.h"
#include "mat4.h"

/*!
 * @brief translate existing transform matrix by v vector
 *        and stores result in same matrix
 *
 * @param[in]       m   affine transform
 * @param[in]       v   translate vector [x, y, z]
 * @returns             affine transform
 */
CGLM_INLINE
mat4s
glms_translated(mat4s m, vec3s v) {
  glm_translated(m.raw, v.raw);
  return m;
}

/*!
 * @brief translate existing transform matrix by x factor
 *
 * @param[in]       m   affine transform
 * @param[in]       x   x factor
 * @returns             affine transform
 */
CGLM_INLINE
mat4s
glms_translated_x(mat4s m, float x) {
  glm_translated_x(m.raw, x);
  return m;
}

/*!
 * @brief translate existing transform matrix by y factor
 *
 * @param[in]       m   affine transform
 * @param[in]       y   y factor
 * @returns             affine transform
 */
CGLM_INLINE
mat4s
glms_translated_y(mat4s m, float y) {
  glm_translated_y(m.raw, y);
  return m;
}

/*!
 * @brief translate existing transform matrix by z factor
 *
 * @param[in]       m   affine transform
 * @param[in]       z   z factor
 * @returns             affine transform
 */
CGLM_INLINE
mat4s
glms_translated_z(mat4s m, float z) {
  glm_translated_z(m.raw, z);
  return m;
}

/*!
 * @brief rotate existing transform matrix around X axis by angle
 *        and store result in dest
 *
 * @param[in]   m       affine transform
 * @param[in]   angle   angle (radians)
 * @returns             rotated matrix
 */
CGLM_INLINE
mat4s
glms_rotated_x(mat4s m, float angle) {
  mat4s r;
  glm_rotated_x(m.raw, angle, r.raw);
  return r;
}

/*!
 * @brief rotate existing transform matrix around Y axis by angle
 *        and store result in dest
 *
 * @param[in]   m       affine transform
 * @param[in]   angle   angle (radians)
 * @returns             rotated matrix
 */
CGLM_INLINE
mat4s
glms_rotated_y(mat4s m, float angle) {
  mat4s r;
  glm_rotated_y(m.raw, angle, r.raw);
  return r;
}

/*!
 * @brief rotate existing transform matrix around Z axis by angle
 *        and store result in dest
 *
 * @param[in]   m       affine transform
 * @param[in]   angle   angle (radians)
 * @returns             rotated matrix
 */
CGLM_INLINE
mat4s
glms_rotated_z(mat4s m, float angle) {
  mat4s r;
  glm_rotated_z(m.raw, angle, r.raw);
  return r;
}

/*!
 * @brief rotate existing transform matrix around given axis by angle
 *
 * @param[in]       m       affine transform
 * @param[in]       angle   angle (radians)
 * @param[in]       axis    axis
 * @returns                affine transform
 */
CGLM_INLINE
mat4s
glms_rotated(mat4s m, float angle, vec3s axis) {
  glm_rotated(m.raw, angle, axis.raw);
  return m;
}

/*!
 * @brief rotate existing transform
 *        around given axis by angle at given pivot point (rotation center)
 *
 * @param[in]       m       affine transform
 * @param[in]       pivot   rotation center
 * @param[in]       angle   angle (radians)
 * @param[in]       axis    axis
 * @returns                 affine transform
 */
CGLM_INLINE
mat4s
glms_rotated_at(mat4s m, vec3s pivot, float angle, vec3s axis) {
  glm_rotated_at(m.raw, pivot.raw, angle, axis.raw);
  return m;
}

/*!
 * @brief rotate existing transform matrix around given axis by angle around self (doesn't affected by position)
 *
 * @param[in]       m       affine transform
 * @param[in]       angle   angle (radians)
 * @param[in]       axis    axis
 * @returns                affine transform
 */
CGLM_INLINE
mat4s
glms_spinned(mat4s m, float angle, vec3s axis) {
  glm_spinned(m.raw, angle, axis.raw);
  return m;
}

#endif /* cglms_affines_post_h */