blob: 47354f6a4cca8afa69e7280181a214f4ca456934 [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 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#ifndef WESTON_MATRIX_H
25#define WESTON_MATRIX_H
26
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +030027enum weston_matrix_transform_type {
28 WESTON_MATRIX_TRANSFORM_TRANSLATE = (1 << 0),
29 WESTON_MATRIX_TRANSFORM_SCALE = (1 << 1),
30 WESTON_MATRIX_TRANSFORM_ROTATE = (1 << 2),
31 WESTON_MATRIX_TRANSFORM_OTHER = (1 << 3),
32};
33
Pekka Paalanen668ca372012-01-12 14:30:47 +020034struct weston_matrix {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020035 float d[16];
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +030036 unsigned int type;
Pekka Paalanen668ca372012-01-12 14:30:47 +020037};
38
39struct weston_vector {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020040 float f[4];
Pekka Paalanen668ca372012-01-12 14:30:47 +020041};
42
43void
44weston_matrix_init(struct weston_matrix *matrix);
45void
46weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n);
47void
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020048weston_matrix_scale(struct weston_matrix *matrix, float x, float y, float z);
Pekka Paalanen668ca372012-01-12 14:30:47 +020049void
50weston_matrix_translate(struct weston_matrix *matrix,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020051 float x, float y, float z);
Pekka Paalanen668ca372012-01-12 14:30:47 +020052void
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +030053weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin);
54void
Pekka Paalanen668ca372012-01-12 14:30:47 +020055weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
56
Pekka Paalanen061b7472012-01-12 15:00:57 +020057int
Pekka Paalanend1f0ab62012-01-20 10:47:57 +020058weston_matrix_invert(struct weston_matrix *inverse,
Pekka Paalanen061b7472012-01-12 15:00:57 +020059 const struct weston_matrix *matrix);
Pekka Paalanend1f0ab62012-01-20 10:47:57 +020060
61#ifdef UNIT_TEST
62# define MATRIX_TEST_EXPORT WL_EXPORT
63
64int
65matrix_invert(double *A, unsigned *p, const struct weston_matrix *matrix);
66
Pekka Paalanen75b47ec2012-01-16 14:27:00 +020067void
John Kåre Alsaker490d02a2012-09-30 02:57:21 +020068inverse_transform(const double *LU, const unsigned *p, float *v);
Pekka Paalanend1f0ab62012-01-20 10:47:57 +020069
70#else
71# define MATRIX_TEST_EXPORT static
72#endif
Pekka Paalanen061b7472012-01-12 15:00:57 +020073
Pekka Paalanen668ca372012-01-12 14:30:47 +020074#endif /* WESTON_MATRIX_H */