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
30GRAPHENE_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 */
40struct _graphene_matrix_t
41{
42 /*< private >*/
43 GRAPHENE_ALIGNED_DECL (GRAPHENE_PRIVATE_FIELD (graphene_simd4x4f_t, value), 16);
44};
45
46GRAPHENE_AVAILABLE_IN_1_0
47graphene_matrix_t * graphene_matrix_alloc (void);
48GRAPHENE_AVAILABLE_IN_1_0
49void graphene_matrix_free (graphene_matrix_t *m);
50
51GRAPHENE_AVAILABLE_IN_1_0
52graphene_matrix_t * graphene_matrix_init_identity (graphene_matrix_t *m);
53GRAPHENE_AVAILABLE_IN_1_0
54graphene_matrix_t * graphene_matrix_init_from_float (graphene_matrix_t *m,
55 const float *v);
56GRAPHENE_AVAILABLE_IN_1_0
57graphene_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);
62GRAPHENE_AVAILABLE_IN_1_0
63graphene_matrix_t * graphene_matrix_init_from_matrix (graphene_matrix_t *m,
64 const graphene_matrix_t *src);
65GRAPHENE_AVAILABLE_IN_1_0
66graphene_matrix_t * graphene_matrix_init_perspective (graphene_matrix_t *m,
67 float fovy,
68 float aspect,
69 float z_near,
70 float z_far);
71GRAPHENE_AVAILABLE_IN_1_0
72graphene_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);
79GRAPHENE_AVAILABLE_IN_1_0
80graphene_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);
84GRAPHENE_AVAILABLE_IN_1_2
85graphene_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);
92GRAPHENE_AVAILABLE_IN_1_0
93graphene_matrix_t * graphene_matrix_init_scale (graphene_matrix_t *m,
94 float x,
95 float y,
96 float z);
97GRAPHENE_AVAILABLE_IN_1_0
98graphene_matrix_t * graphene_matrix_init_translate (graphene_matrix_t *m,
99 const graphene_point3d_t *p);
100GRAPHENE_AVAILABLE_IN_1_0
101graphene_matrix_t * graphene_matrix_init_rotate (graphene_matrix_t *m,
102 float angle,
103 const graphene_vec3_t *axis);
104GRAPHENE_AVAILABLE_IN_1_0
105graphene_matrix_t * graphene_matrix_init_skew (graphene_matrix_t *m,
106 float x_skew,
107 float y_skew);
108GRAPHENE_AVAILABLE_IN_1_0
109graphene_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
117GRAPHENE_AVAILABLE_IN_1_0
118bool graphene_matrix_is_identity (const graphene_matrix_t *m);
119GRAPHENE_AVAILABLE_IN_1_0
120bool graphene_matrix_is_2d (const graphene_matrix_t *m);
121GRAPHENE_AVAILABLE_IN_1_0
122bool graphene_matrix_is_backface_visible (const graphene_matrix_t *m);
123GRAPHENE_AVAILABLE_IN_1_0
124bool graphene_matrix_is_singular (const graphene_matrix_t *m);
125
126GRAPHENE_AVAILABLE_IN_1_0
127void graphene_matrix_to_float (const graphene_matrix_t *m,
128 float *v);
129GRAPHENE_AVAILABLE_IN_1_0
130bool 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
139GRAPHENE_AVAILABLE_IN_1_0
140void graphene_matrix_get_row (const graphene_matrix_t *m,
141 unsigned int index_,
142 graphene_vec4_t *res);
143GRAPHENE_AVAILABLE_IN_1_0
144float graphene_matrix_get_value (const graphene_matrix_t *m,
145 unsigned int row,
146 unsigned int col);
147
148GRAPHENE_AVAILABLE_IN_1_0
149void graphene_matrix_multiply (const graphene_matrix_t *a,
150 const graphene_matrix_t *b,
151 graphene_matrix_t *res);
152GRAPHENE_AVAILABLE_IN_1_0
153float graphene_matrix_determinant (const graphene_matrix_t *m);
154
155GRAPHENE_AVAILABLE_IN_1_0
156void graphene_matrix_transform_vec4 (const graphene_matrix_t *m,
157 const graphene_vec4_t *v,
158 graphene_vec4_t *res);
159GRAPHENE_AVAILABLE_IN_1_0
160void graphene_matrix_transform_vec3 (const graphene_matrix_t *m,
161 const graphene_vec3_t *v,
162 graphene_vec3_t *res);
163GRAPHENE_AVAILABLE_IN_1_0
164void graphene_matrix_transform_point (const graphene_matrix_t *m,
165 const graphene_point_t *p,
166 graphene_point_t *res);
167GRAPHENE_AVAILABLE_IN_1_2
168void graphene_matrix_transform_point3d (const graphene_matrix_t *m,
169 const graphene_point3d_t *p,
170 graphene_point3d_t *res);
171GRAPHENE_AVAILABLE_IN_1_0
172void graphene_matrix_transform_rect (const graphene_matrix_t *m,
173 const graphene_rect_t *r,
174 graphene_quad_t *res);
175GRAPHENE_AVAILABLE_IN_1_0
176void graphene_matrix_transform_bounds (const graphene_matrix_t *m,
177 const graphene_rect_t *r,
178 graphene_rect_t *res);
179GRAPHENE_AVAILABLE_IN_1_2
180void graphene_matrix_transform_sphere (const graphene_matrix_t *m,
181 const graphene_sphere_t *s,
182 graphene_sphere_t *res);
183GRAPHENE_AVAILABLE_IN_1_2
184void graphene_matrix_transform_box (const graphene_matrix_t *m,
185 const graphene_box_t *b,
186 graphene_box_t *res);
187GRAPHENE_AVAILABLE_IN_1_4
188void graphene_matrix_transform_ray (const graphene_matrix_t *m,
189 const graphene_ray_t *r,
190 graphene_ray_t *res);
191
192GRAPHENE_AVAILABLE_IN_1_0
193void graphene_matrix_project_point (const graphene_matrix_t *m,
194 const graphene_point_t *p,
195 graphene_point_t *res);
196GRAPHENE_AVAILABLE_IN_1_0
197void graphene_matrix_project_rect_bounds (const graphene_matrix_t *m,
198 const graphene_rect_t *r,
199 graphene_rect_t *res);
200GRAPHENE_AVAILABLE_IN_1_2
201void graphene_matrix_project_rect (const graphene_matrix_t *m,
202 const graphene_rect_t *r,
203 graphene_quad_t *res);
204GRAPHENE_AVAILABLE_IN_1_0
205bool 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);
209GRAPHENE_AVAILABLE_IN_1_0
210void 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);
214GRAPHENE_AVAILABLE_IN_1_2
215void 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
220GRAPHENE_AVAILABLE_IN_1_0
221void graphene_matrix_translate (graphene_matrix_t *m,
222 const graphene_point3d_t *pos);
223GRAPHENE_AVAILABLE_IN_1_0
224void graphene_matrix_rotate (graphene_matrix_t *m,
225 float angle,
226 const graphene_vec3_t *axis);
227GRAPHENE_AVAILABLE_IN_1_0
228void graphene_matrix_rotate_x (graphene_matrix_t *m,
229 float angle);
230GRAPHENE_AVAILABLE_IN_1_0
231void graphene_matrix_rotate_y (graphene_matrix_t *m,
232 float angle);
233GRAPHENE_AVAILABLE_IN_1_0
234void graphene_matrix_rotate_z (graphene_matrix_t *m,
235 float angle);
236GRAPHENE_AVAILABLE_IN_1_2
237void graphene_matrix_rotate_quaternion (graphene_matrix_t *m,
238 const graphene_quaternion_t *q);
239GRAPHENE_AVAILABLE_IN_1_2
240void graphene_matrix_rotate_euler (graphene_matrix_t *m,
241 const graphene_euler_t *e);
242GRAPHENE_AVAILABLE_IN_1_0
243void graphene_matrix_scale (graphene_matrix_t *m,
244 float factor_x,
245 float factor_y,
246 float factor_z);
247GRAPHENE_AVAILABLE_IN_1_0
248void graphene_matrix_skew_xy (graphene_matrix_t *m,
249 float factor);
250GRAPHENE_AVAILABLE_IN_1_0
251void graphene_matrix_skew_xz (graphene_matrix_t *m,
252 float factor);
253GRAPHENE_AVAILABLE_IN_1_0
254void graphene_matrix_skew_yz (graphene_matrix_t *m,
255 float factor);
256
257GRAPHENE_AVAILABLE_IN_1_0
258void graphene_matrix_transpose (const graphene_matrix_t *m,
259 graphene_matrix_t *res);
260GRAPHENE_AVAILABLE_IN_1_0
261bool graphene_matrix_inverse (const graphene_matrix_t *m,
262 graphene_matrix_t *res);
263GRAPHENE_AVAILABLE_IN_1_0
264void graphene_matrix_perspective (const graphene_matrix_t *m,
265 float depth,
266 graphene_matrix_t *res);
267GRAPHENE_AVAILABLE_IN_1_0
268void graphene_matrix_normalize (const graphene_matrix_t *m,
269 graphene_matrix_t *res);
270
271GRAPHENE_AVAILABLE_IN_1_10
272float graphene_matrix_get_x_translation (const graphene_matrix_t *m);
273GRAPHENE_AVAILABLE_IN_1_10
274float graphene_matrix_get_y_translation (const graphene_matrix_t *m);
275GRAPHENE_AVAILABLE_IN_1_10
276float graphene_matrix_get_z_translation (const graphene_matrix_t *m);
277
278GRAPHENE_AVAILABLE_IN_1_0
279float graphene_matrix_get_x_scale (const graphene_matrix_t *m);
280GRAPHENE_AVAILABLE_IN_1_0
281float graphene_matrix_get_y_scale (const graphene_matrix_t *m);
282GRAPHENE_AVAILABLE_IN_1_0
283float graphene_matrix_get_z_scale (const graphene_matrix_t *m);
284
285GRAPHENE_AVAILABLE_IN_1_0
286void graphene_matrix_interpolate (const graphene_matrix_t *a,
287 const graphene_matrix_t *b,
288 double factor,
289 graphene_matrix_t *res);
290
291GRAPHENE_AVAILABLE_IN_1_10
292bool graphene_matrix_near (const graphene_matrix_t *a,
293 const graphene_matrix_t *b,
294 float epsilon);
295GRAPHENE_AVAILABLE_IN_1_10
296bool graphene_matrix_equal (const graphene_matrix_t *a,
297 const graphene_matrix_t *b);
298GRAPHENE_AVAILABLE_IN_1_10
299bool graphene_matrix_equal_fast (const graphene_matrix_t *a,
300 const graphene_matrix_t *b);
301
302GRAPHENE_AVAILABLE_IN_1_0
303void graphene_matrix_print (const graphene_matrix_t *m);
304
305GRAPHENE_AVAILABLE_IN_1_10
306bool 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
313GRAPHENE_END_DECLS
314

source code of gtk/subprojects/graphene/include/graphene-matrix.h