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 | * |
Bryce Harrington | 6c6164c | 2015-06-11 14:20:17 -0700 | [diff] [blame] | 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: |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 12 | * |
Bryce Harrington | 6c6164c | 2015-06-11 14:20:17 -0700 | [diff] [blame] | 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. |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #ifndef WESTON_MATRIX_H |
| 28 | #define WESTON_MATRIX_H |
| 29 | |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 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 | |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 41 | struct weston_matrix { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 42 | float d[16]; |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 43 | unsigned int type; |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct weston_vector { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 47 | float f[4]; |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 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 |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 55 | 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] | 56 | void |
| 57 | weston_matrix_translate(struct weston_matrix *matrix, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 58 | float x, float y, float z); |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 59 | void |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 60 | weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin); |
| 61 | void |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 62 | weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v); |
| 63 | |
Pekka Paalanen | 061b747 | 2012-01-12 15:00:57 +0200 | [diff] [blame] | 64 | int |
Pekka Paalanen | d1f0ab6 | 2012-01-20 10:47:57 +0200 | [diff] [blame] | 65 | weston_matrix_invert(struct weston_matrix *inverse, |
Pekka Paalanen | 061b747 | 2012-01-12 15:00:57 +0200 | [diff] [blame] | 66 | const struct weston_matrix *matrix); |
Pekka Paalanen | d1f0ab6 | 2012-01-20 10:47:57 +0200 | [diff] [blame] | 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 | |
Pekka Paalanen | 75b47ec | 2012-01-16 14:27:00 +0200 | [diff] [blame] | 74 | void |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 75 | inverse_transform(const double *LU, const unsigned *p, float *v); |
Pekka Paalanen | d1f0ab6 | 2012-01-20 10:47:57 +0200 | [diff] [blame] | 76 | |
| 77 | #else |
| 78 | # define MATRIX_TEST_EXPORT static |
| 79 | #endif |
Pekka Paalanen | 061b747 | 2012-01-12 15:00:57 +0200 | [diff] [blame] | 80 | |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 81 | #ifdef __cplusplus |
| 82 | } |
| 83 | #endif |
| 84 | |
Pekka Paalanen | 668ca37 | 2012-01-12 14:30:47 +0200 | [diff] [blame] | 85 | #endif /* WESTON_MATRIX_H */ |