blob: be4d4eb0deef31788aed81a214cbbca00b98f8ae [file] [log] [blame]
Pekka Paalanen668ca372012-01-12 14:30:47 +02001/*
2 * Copyright © 2008-2011 Kristian Høgsberg
Pekka Paalanen75b47ec2012-01-16 14:27:00 +02003 * Copyright © 2012 Collabora, Ltd.
Pekka Paalanen668ca372012-01-12 14:30:47 +02004 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -07005 * 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:
Pekka Paalanen668ca372012-01-12 14:30:47 +020012 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -070013 * 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.
Pekka Paalanen668ca372012-01-12 14:30:47 +020025 */
26
27#ifndef WESTON_MATRIX_H
28#define WESTON_MATRIX_H
29
Giulio Camuffo7fe01b12013-03-28 18:02:42 +010030#ifdef __cplusplus
31extern "C" {
32#endif
33
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +030034enum 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
Pekka Paalanen668ca372012-01-12 14:30:47 +020041struct weston_matrix {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020042 float d[16];
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +030043 unsigned int type;
Pekka Paalanen668ca372012-01-12 14:30:47 +020044};
45
46struct weston_vector {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020047 float f[4];
Pekka Paalanen668ca372012-01-12 14:30:47 +020048};
49
50void
51weston_matrix_init(struct weston_matrix *matrix);
52void
53weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n);
54void
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020055weston_matrix_scale(struct weston_matrix *matrix, float x, float y, float z);
Pekka Paalanen668ca372012-01-12 14:30:47 +020056void
57weston_matrix_translate(struct weston_matrix *matrix,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020058 float x, float y, float z);
Pekka Paalanen668ca372012-01-12 14:30:47 +020059void
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +030060weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin);
61void
Pekka Paalanen668ca372012-01-12 14:30:47 +020062weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
63
Pekka Paalanen061b7472012-01-12 15:00:57 +020064int
Pekka Paalanend1f0ab62012-01-20 10:47:57 +020065weston_matrix_invert(struct weston_matrix *inverse,
Pekka Paalanen061b7472012-01-12 15:00:57 +020066 const struct weston_matrix *matrix);
Pekka Paalanend1f0ab62012-01-20 10:47:57 +020067
68#ifdef UNIT_TEST
69# define MATRIX_TEST_EXPORT WL_EXPORT
70
71int
72matrix_invert(double *A, unsigned *p, const struct weston_matrix *matrix);
73
Pekka Paalanen75b47ec2012-01-16 14:27:00 +020074void
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020075inverse_transform(const double *LU, const unsigned *p, float *v);
Pekka Paalanend1f0ab62012-01-20 10:47:57 +020076
77#else
78# define MATRIX_TEST_EXPORT static
79#endif
Pekka Paalanen061b7472012-01-12 15:00:57 +020080
Giulio Camuffo7fe01b12013-03-28 18:02:42 +010081#ifdef __cplusplus
82}
83#endif
84
Pekka Paalanen668ca372012-01-12 14:30:47 +020085#endif /* WESTON_MATRIX_H */