1 /*
2  * Copyright © 2008-2011 Kristian Høgsberg
3  * Copyright © 2012 Collabora, Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
27 #ifndef WESTON_MATRIX_H
28 #define WESTON_MATRIX_H
29 
30 #ifdef  __cplusplus
31 extern "C" {
32 #endif
33 
34 enum weston_matrix_transform_type {
35 	WESTON_MATRIX_TRANSFORM_TRANSLATE	= (1 << 0),
36 	WESTON_MATRIX_TRANSFORM_SCALE		= (1 << 1),
37 	WESTON_MATRIX_TRANSFORM_ROTATE		= (1 << 2),
38 	WESTON_MATRIX_TRANSFORM_OTHER		= (1 << 3),
39 };
40 
41 struct weston_matrix {
42 	float d[16];
43 	unsigned int type;
44 };
45 
46 struct weston_vector {
47 	float f[4];
48 };
49 
50 void
51 weston_matrix_init(struct weston_matrix *matrix);
52 void
53 weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n);
54 void
55 weston_matrix_scale(struct weston_matrix *matrix, float x, float y, float z);
56 void
57 weston_matrix_translate(struct weston_matrix *matrix,
58 			float x, float y, float z);
59 void
60 weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin);
61 void
62 weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
63 
64 int
65 weston_matrix_invert(struct weston_matrix *inverse,
66 		     const struct weston_matrix *matrix);
67 
68 #ifdef UNIT_TEST
69 #  define MATRIX_TEST_EXPORT WL_EXPORT
70 
71 int
72 matrix_invert(double *A, unsigned *p, const struct weston_matrix *matrix);
73 
74 void
75 inverse_transform(const double *LU, const unsigned *p, float *v);
76 
77 #else
78 #  define MATRIX_TEST_EXPORT static
79 #endif
80 
81 #ifdef  __cplusplus
82 }
83 #endif
84 
85 #endif /* WESTON_MATRIX_H */
86