Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008-2011 Kristian Høgsberg |
Pekka Paalanen | 75b47ec | 2012-01-16 14:27:00 +0200 | [diff] [blame] | 3 | * Copyright © 2012 Collabora, Ltd. |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 4 | * |
| 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 | |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame^] | 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 31 | enum weston_matrix_transform_type { |
| 32 | WESTON_MATRIX_TRANSFORM_TRANSLATE = (1 << 0), |
| 33 | WESTON_MATRIX_TRANSFORM_SCALE = (1 << 1), |
| 34 | WESTON_MATRIX_TRANSFORM_ROTATE = (1 << 2), |
| 35 | WESTON_MATRIX_TRANSFORM_OTHER = (1 << 3), |
| 36 | }; |
| 37 | |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 38 | struct weston_matrix { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 39 | float d[16]; |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 40 | unsigned int type; |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct weston_vector { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 44 | float f[4]; |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | void |
| 48 | weston_matrix_init(struct weston_matrix *matrix); |
| 49 | void |
| 50 | weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n); |
| 51 | void |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 52 | weston_matrix_scale(struct weston_matrix *matrix, float x, float y, float z); |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 53 | void |
| 54 | weston_matrix_translate(struct weston_matrix *matrix, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 55 | float x, float y, float z); |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 56 | void |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 57 | weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin); |
| 58 | void |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 59 | weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v); |
| 60 | |
Pekka Paalanen | 061b747 | 2012-01-12 15:00:57 +0200 | [diff] [blame] | 61 | int |
Pekka Paalanen | d1f0ab6 | 2012-01-20 10:47:57 +0200 | [diff] [blame] | 62 | weston_matrix_invert(struct weston_matrix *inverse, |
Pekka Paalanen | 061b747 | 2012-01-12 15:00:57 +0200 | [diff] [blame] | 63 | const struct weston_matrix *matrix); |
Pekka Paalanen | d1f0ab6 | 2012-01-20 10:47:57 +0200 | [diff] [blame] | 64 | |
| 65 | #ifdef UNIT_TEST |
| 66 | # define MATRIX_TEST_EXPORT WL_EXPORT |
| 67 | |
| 68 | int |
| 69 | matrix_invert(double *A, unsigned *p, const struct weston_matrix *matrix); |
| 70 | |
Pekka Paalanen | 75b47ec | 2012-01-16 14:27:00 +0200 | [diff] [blame] | 71 | void |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 72 | inverse_transform(const double *LU, const unsigned *p, float *v); |
Pekka Paalanen | d1f0ab6 | 2012-01-20 10:47:57 +0200 | [diff] [blame] | 73 | |
| 74 | #else |
| 75 | # define MATRIX_TEST_EXPORT static |
| 76 | #endif |
Pekka Paalanen | 061b747 | 2012-01-12 15:00:57 +0200 | [diff] [blame] | 77 | |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame^] | 78 | #ifdef __cplusplus |
| 79 | } |
| 80 | #endif |
| 81 | |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 82 | #endif /* WESTON_MATRIX_H */ |