1 | /* graphene-matrix.h: 4x4 matrix |
2 | * |
3 | * SPDX-License-Identifier: MIT |
4 | * |
5 | * Copyright 2014 Emmanuele Bassi |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | * of this software and associated documentation files (the "Software"), to deal |
9 | * in the Software without restriction, including without limitation the rights |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | * copies of the Software, and to permit persons to whom the Software is |
12 | * furnished to do so, subject to the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | * THE SOFTWARE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "graphene-types.h" |
29 | |
30 | GRAPHENE_BEGIN_DECLS |
31 | |
32 | /** |
33 | * graphene_matrix_t: |
34 | * |
35 | * A structure capable of holding a 4x4 matrix. |
36 | * |
37 | * The contents of the #graphene_matrix_t structure are private and |
38 | * should never be accessed directly. |
39 | */ |
40 | struct _graphene_matrix_t |
41 | { |
42 | /*< private >*/ |
43 | GRAPHENE_ALIGNED_DECL (GRAPHENE_PRIVATE_FIELD (graphene_simd4x4f_t, value), 16); |
44 | }; |
45 | |
46 | GRAPHENE_AVAILABLE_IN_1_0 |
47 | graphene_matrix_t * graphene_matrix_alloc (void); |
48 | GRAPHENE_AVAILABLE_IN_1_0 |
49 | void graphene_matrix_free (graphene_matrix_t *m); |
50 | |
51 | GRAPHENE_AVAILABLE_IN_1_0 |
52 | graphene_matrix_t * graphene_matrix_init_identity (graphene_matrix_t *m); |
53 | GRAPHENE_AVAILABLE_IN_1_0 |
54 | graphene_matrix_t * graphene_matrix_init_from_float (graphene_matrix_t *m, |
55 | const float *v); |
56 | GRAPHENE_AVAILABLE_IN_1_0 |
57 | graphene_matrix_t * graphene_matrix_init_from_vec4 (graphene_matrix_t *m, |
58 | const graphene_vec4_t *v0, |
59 | const graphene_vec4_t *v1, |
60 | const graphene_vec4_t *v2, |
61 | const graphene_vec4_t *v3); |
62 | GRAPHENE_AVAILABLE_IN_1_0 |
63 | graphene_matrix_t * graphene_matrix_init_from_matrix (graphene_matrix_t *m, |
64 | const graphene_matrix_t *src); |
65 | GRAPHENE_AVAILABLE_IN_1_0 |
66 | graphene_matrix_t * graphene_matrix_init_perspective (graphene_matrix_t *m, |
67 | float fovy, |
68 | float aspect, |
69 | float z_near, |
70 | float z_far); |
71 | GRAPHENE_AVAILABLE_IN_1_0 |
72 | graphene_matrix_t * graphene_matrix_init_ortho (graphene_matrix_t *m, |
73 | float left, |
74 | float right, |
75 | float top, |
76 | float bottom, |
77 | float z_near, |
78 | float z_far); |
79 | GRAPHENE_AVAILABLE_IN_1_0 |
80 | graphene_matrix_t * graphene_matrix_init_look_at (graphene_matrix_t *m, |
81 | const graphene_vec3_t *eye, |
82 | const graphene_vec3_t *center, |
83 | const graphene_vec3_t *up); |
84 | GRAPHENE_AVAILABLE_IN_1_2 |
85 | graphene_matrix_t * graphene_matrix_init_frustum (graphene_matrix_t *m, |
86 | float left, |
87 | float right, |
88 | float bottom, |
89 | float top, |
90 | float z_near, |
91 | float z_far); |
92 | GRAPHENE_AVAILABLE_IN_1_0 |
93 | graphene_matrix_t * graphene_matrix_init_scale (graphene_matrix_t *m, |
94 | float x, |
95 | float y, |
96 | float z); |
97 | GRAPHENE_AVAILABLE_IN_1_0 |
98 | graphene_matrix_t * graphene_matrix_init_translate (graphene_matrix_t *m, |
99 | const graphene_point3d_t *p); |
100 | GRAPHENE_AVAILABLE_IN_1_0 |
101 | graphene_matrix_t * graphene_matrix_init_rotate (graphene_matrix_t *m, |
102 | float angle, |
103 | const graphene_vec3_t *axis); |
104 | GRAPHENE_AVAILABLE_IN_1_0 |
105 | graphene_matrix_t * graphene_matrix_init_skew (graphene_matrix_t *m, |
106 | float x_skew, |
107 | float y_skew); |
108 | GRAPHENE_AVAILABLE_IN_1_0 |
109 | graphene_matrix_t * graphene_matrix_init_from_2d (graphene_matrix_t *m, |
110 | double xx, |
111 | double yx, |
112 | double xy, |
113 | double yy, |
114 | double x_0, |
115 | double y_0); |
116 | |
117 | GRAPHENE_AVAILABLE_IN_1_0 |
118 | bool graphene_matrix_is_identity (const graphene_matrix_t *m); |
119 | GRAPHENE_AVAILABLE_IN_1_0 |
120 | bool graphene_matrix_is_2d (const graphene_matrix_t *m); |
121 | GRAPHENE_AVAILABLE_IN_1_0 |
122 | bool graphene_matrix_is_backface_visible (const graphene_matrix_t *m); |
123 | GRAPHENE_AVAILABLE_IN_1_0 |
124 | bool graphene_matrix_is_singular (const graphene_matrix_t *m); |
125 | |
126 | GRAPHENE_AVAILABLE_IN_1_0 |
127 | void graphene_matrix_to_float (const graphene_matrix_t *m, |
128 | float *v); |
129 | GRAPHENE_AVAILABLE_IN_1_0 |
130 | bool graphene_matrix_to_2d (const graphene_matrix_t *m, |
131 | double *xx, |
132 | double *yx, |
133 | double *xy, |
134 | double *yy, |
135 | double *x_0, |
136 | double *y_0); |
137 | |
138 | |
139 | GRAPHENE_AVAILABLE_IN_1_0 |
140 | void graphene_matrix_get_row (const graphene_matrix_t *m, |
141 | unsigned int index_, |
142 | graphene_vec4_t *res); |
143 | GRAPHENE_AVAILABLE_IN_1_0 |
144 | float graphene_matrix_get_value (const graphene_matrix_t *m, |
145 | unsigned int row, |
146 | unsigned int col); |
147 | |
148 | GRAPHENE_AVAILABLE_IN_1_0 |
149 | void graphene_matrix_multiply (const graphene_matrix_t *a, |
150 | const graphene_matrix_t *b, |
151 | graphene_matrix_t *res); |
152 | GRAPHENE_AVAILABLE_IN_1_0 |
153 | float graphene_matrix_determinant (const graphene_matrix_t *m); |
154 | |
155 | GRAPHENE_AVAILABLE_IN_1_0 |
156 | void graphene_matrix_transform_vec4 (const graphene_matrix_t *m, |
157 | const graphene_vec4_t *v, |
158 | graphene_vec4_t *res); |
159 | GRAPHENE_AVAILABLE_IN_1_0 |
160 | void graphene_matrix_transform_vec3 (const graphene_matrix_t *m, |
161 | const graphene_vec3_t *v, |
162 | graphene_vec3_t *res); |
163 | GRAPHENE_AVAILABLE_IN_1_0 |
164 | void graphene_matrix_transform_point (const graphene_matrix_t *m, |
165 | const graphene_point_t *p, |
166 | graphene_point_t *res); |
167 | GRAPHENE_AVAILABLE_IN_1_2 |
168 | void graphene_matrix_transform_point3d (const graphene_matrix_t *m, |
169 | const graphene_point3d_t *p, |
170 | graphene_point3d_t *res); |
171 | GRAPHENE_AVAILABLE_IN_1_0 |
172 | void graphene_matrix_transform_rect (const graphene_matrix_t *m, |
173 | const graphene_rect_t *r, |
174 | graphene_quad_t *res); |
175 | GRAPHENE_AVAILABLE_IN_1_0 |
176 | void graphene_matrix_transform_bounds (const graphene_matrix_t *m, |
177 | const graphene_rect_t *r, |
178 | graphene_rect_t *res); |
179 | GRAPHENE_AVAILABLE_IN_1_2 |
180 | void graphene_matrix_transform_sphere (const graphene_matrix_t *m, |
181 | const graphene_sphere_t *s, |
182 | graphene_sphere_t *res); |
183 | GRAPHENE_AVAILABLE_IN_1_2 |
184 | void graphene_matrix_transform_box (const graphene_matrix_t *m, |
185 | const graphene_box_t *b, |
186 | graphene_box_t *res); |
187 | GRAPHENE_AVAILABLE_IN_1_4 |
188 | void graphene_matrix_transform_ray (const graphene_matrix_t *m, |
189 | const graphene_ray_t *r, |
190 | graphene_ray_t *res); |
191 | |
192 | GRAPHENE_AVAILABLE_IN_1_0 |
193 | void graphene_matrix_project_point (const graphene_matrix_t *m, |
194 | const graphene_point_t *p, |
195 | graphene_point_t *res); |
196 | GRAPHENE_AVAILABLE_IN_1_0 |
197 | void graphene_matrix_project_rect_bounds (const graphene_matrix_t *m, |
198 | const graphene_rect_t *r, |
199 | graphene_rect_t *res); |
200 | GRAPHENE_AVAILABLE_IN_1_2 |
201 | void graphene_matrix_project_rect (const graphene_matrix_t *m, |
202 | const graphene_rect_t *r, |
203 | graphene_quad_t *res); |
204 | GRAPHENE_AVAILABLE_IN_1_0 |
205 | bool graphene_matrix_untransform_point (const graphene_matrix_t *m, |
206 | const graphene_point_t *p, |
207 | const graphene_rect_t *bounds, |
208 | graphene_point_t *res); |
209 | GRAPHENE_AVAILABLE_IN_1_0 |
210 | void graphene_matrix_untransform_bounds (const graphene_matrix_t *m, |
211 | const graphene_rect_t *r, |
212 | const graphene_rect_t *bounds, |
213 | graphene_rect_t *res); |
214 | GRAPHENE_AVAILABLE_IN_1_2 |
215 | void graphene_matrix_unproject_point3d (const graphene_matrix_t *projection, |
216 | const graphene_matrix_t *modelview, |
217 | const graphene_point3d_t *point, |
218 | graphene_point3d_t *res); |
219 | |
220 | GRAPHENE_AVAILABLE_IN_1_0 |
221 | void graphene_matrix_translate (graphene_matrix_t *m, |
222 | const graphene_point3d_t *pos); |
223 | GRAPHENE_AVAILABLE_IN_1_0 |
224 | void graphene_matrix_rotate (graphene_matrix_t *m, |
225 | float angle, |
226 | const graphene_vec3_t *axis); |
227 | GRAPHENE_AVAILABLE_IN_1_0 |
228 | void graphene_matrix_rotate_x (graphene_matrix_t *m, |
229 | float angle); |
230 | GRAPHENE_AVAILABLE_IN_1_0 |
231 | void graphene_matrix_rotate_y (graphene_matrix_t *m, |
232 | float angle); |
233 | GRAPHENE_AVAILABLE_IN_1_0 |
234 | void graphene_matrix_rotate_z (graphene_matrix_t *m, |
235 | float angle); |
236 | GRAPHENE_AVAILABLE_IN_1_2 |
237 | void graphene_matrix_rotate_quaternion (graphene_matrix_t *m, |
238 | const graphene_quaternion_t *q); |
239 | GRAPHENE_AVAILABLE_IN_1_2 |
240 | void graphene_matrix_rotate_euler (graphene_matrix_t *m, |
241 | const graphene_euler_t *e); |
242 | GRAPHENE_AVAILABLE_IN_1_0 |
243 | void graphene_matrix_scale (graphene_matrix_t *m, |
244 | float factor_x, |
245 | float factor_y, |
246 | float factor_z); |
247 | GRAPHENE_AVAILABLE_IN_1_0 |
248 | void graphene_matrix_skew_xy (graphene_matrix_t *m, |
249 | float factor); |
250 | GRAPHENE_AVAILABLE_IN_1_0 |
251 | void graphene_matrix_skew_xz (graphene_matrix_t *m, |
252 | float factor); |
253 | GRAPHENE_AVAILABLE_IN_1_0 |
254 | void graphene_matrix_skew_yz (graphene_matrix_t *m, |
255 | float factor); |
256 | |
257 | GRAPHENE_AVAILABLE_IN_1_0 |
258 | void graphene_matrix_transpose (const graphene_matrix_t *m, |
259 | graphene_matrix_t *res); |
260 | GRAPHENE_AVAILABLE_IN_1_0 |
261 | bool graphene_matrix_inverse (const graphene_matrix_t *m, |
262 | graphene_matrix_t *res); |
263 | GRAPHENE_AVAILABLE_IN_1_0 |
264 | void graphene_matrix_perspective (const graphene_matrix_t *m, |
265 | float depth, |
266 | graphene_matrix_t *res); |
267 | GRAPHENE_AVAILABLE_IN_1_0 |
268 | void graphene_matrix_normalize (const graphene_matrix_t *m, |
269 | graphene_matrix_t *res); |
270 | |
271 | GRAPHENE_AVAILABLE_IN_1_10 |
272 | float graphene_matrix_get_x_translation (const graphene_matrix_t *m); |
273 | GRAPHENE_AVAILABLE_IN_1_10 |
274 | float graphene_matrix_get_y_translation (const graphene_matrix_t *m); |
275 | GRAPHENE_AVAILABLE_IN_1_10 |
276 | float graphene_matrix_get_z_translation (const graphene_matrix_t *m); |
277 | |
278 | GRAPHENE_AVAILABLE_IN_1_0 |
279 | float graphene_matrix_get_x_scale (const graphene_matrix_t *m); |
280 | GRAPHENE_AVAILABLE_IN_1_0 |
281 | float graphene_matrix_get_y_scale (const graphene_matrix_t *m); |
282 | GRAPHENE_AVAILABLE_IN_1_0 |
283 | float graphene_matrix_get_z_scale (const graphene_matrix_t *m); |
284 | |
285 | GRAPHENE_AVAILABLE_IN_1_0 |
286 | void graphene_matrix_interpolate (const graphene_matrix_t *a, |
287 | const graphene_matrix_t *b, |
288 | double factor, |
289 | graphene_matrix_t *res); |
290 | |
291 | GRAPHENE_AVAILABLE_IN_1_10 |
292 | bool graphene_matrix_near (const graphene_matrix_t *a, |
293 | const graphene_matrix_t *b, |
294 | float epsilon); |
295 | GRAPHENE_AVAILABLE_IN_1_10 |
296 | bool graphene_matrix_equal (const graphene_matrix_t *a, |
297 | const graphene_matrix_t *b); |
298 | GRAPHENE_AVAILABLE_IN_1_10 |
299 | bool graphene_matrix_equal_fast (const graphene_matrix_t *a, |
300 | const graphene_matrix_t *b); |
301 | |
302 | GRAPHENE_AVAILABLE_IN_1_0 |
303 | void graphene_matrix_print (const graphene_matrix_t *m); |
304 | |
305 | GRAPHENE_AVAILABLE_IN_1_10 |
306 | bool graphene_matrix_decompose (const graphene_matrix_t *m, |
307 | graphene_vec3_t *translate, |
308 | graphene_vec3_t *scale, |
309 | graphene_quaternion_t *rotate, |
310 | graphene_vec3_t *shear, |
311 | graphene_vec4_t *perspective); |
312 | |
313 | GRAPHENE_END_DECLS |
314 | |