| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 1 | // |
| Stuart Morgan | 9d73796 | 2019-08-14 19:25:12 | [diff] [blame] | 2 | // Copyright 2014 The ANGLE Project Authors. All rights reserved. |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| Jamie Madill | ad60e8e | 2015-09-22 16:40:31 | [diff] [blame] | 6 | // Matrix: |
| 7 | // Helper class for doing matrix math. |
| 8 | // |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 9 | |
| Jamie Madill | ad60e8e | 2015-09-22 16:40:31 | [diff] [blame] | 10 | #ifndef UTIL_MATRIX_H |
| 11 | #define UTIL_MATRIX_H |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 12 | |
| Yuly Novikov | 9f088621 | 2018-12-29 20:46:15 | [diff] [blame] | 13 | #include "common/vector_utils.h" |
| Jamie Madill | ba319ba | 2018-12-29 15:29:33 | [diff] [blame] | 14 | #include "util/util_export.h" |
| Yuly Novikov | 9f088621 | 2018-12-29 20:46:15 | [diff] [blame] | 15 | |
| Jamie Madill | ba319ba | 2018-12-29 15:29:33 | [diff] [blame] | 16 | struct ANGLE_UTIL_EXPORT Matrix4 |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 17 | { |
| 18 | float data[16]; |
| 19 | |
| 20 | Matrix4(); |
| Jamie Madill | ad60e8e | 2015-09-22 16:40:31 | [diff] [blame] | 21 | Matrix4(float m00, |
| 22 | float m01, |
| 23 | float m02, |
| 24 | float m03, |
| 25 | float m10, |
| 26 | float m11, |
| 27 | float m12, |
| 28 | float m13, |
| 29 | float m20, |
| 30 | float m21, |
| 31 | float m22, |
| 32 | float m23, |
| 33 | float m30, |
| 34 | float m31, |
| 35 | float m32, |
| 36 | float m33); |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 37 | |
| 38 | static Matrix4 identity(); |
| Corentin Wallez | 922cbfc | 2016-11-25 21:23:18 | [diff] [blame] | 39 | static Matrix4 rotate(float angle, const angle::Vector3 &p); |
| 40 | static Matrix4 translate(const angle::Vector3 &t); |
| 41 | static Matrix4 scale(const angle::Vector3 &s); |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 42 | static Matrix4 frustum(float l, float r, float b, float t, float n, float f); |
| 43 | static Matrix4 perspective(float fov, float aspectRatio, float n, float f); |
| 44 | static Matrix4 ortho(float l, float r, float b, float t, float n, float f); |
| 45 | static Matrix4 rollPitchYaw(float roll, float pitch, float yaw); |
| 46 | |
| 47 | static Matrix4 invert(const Matrix4 &mat); |
| 48 | static Matrix4 transpose(const Matrix4 &mat); |
| Corentin Wallez | 922cbfc | 2016-11-25 21:23:18 | [diff] [blame] | 49 | static angle::Vector3 transform(const Matrix4 &mat, const angle::Vector3 &pt); |
| 50 | static angle::Vector3 transform(const Matrix4 &mat, const angle::Vector4 &pt); |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 51 | }; |
| 52 | |
| Jamie Madill | ba319ba | 2018-12-29 15:29:33 | [diff] [blame] | 53 | ANGLE_UTIL_EXPORT Matrix4 operator*(const Matrix4 &a, const Matrix4 &b); |
| 54 | ANGLE_UTIL_EXPORT Matrix4 &operator*=(Matrix4 &a, const Matrix4 &b); |
| 55 | ANGLE_UTIL_EXPORT Matrix4 operator*(const Matrix4 &a, float b); |
| 56 | ANGLE_UTIL_EXPORT Matrix4 &operator*=(Matrix4 &a, float b); |
| 57 | ANGLE_UTIL_EXPORT angle::Vector4 operator*(const Matrix4 &a, const angle::Vector4 &b); |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 58 | |
| Jamie Madill | ba319ba | 2018-12-29 15:29:33 | [diff] [blame] | 59 | ANGLE_UTIL_EXPORT bool operator==(const Matrix4 &a, const Matrix4 &b); |
| 60 | ANGLE_UTIL_EXPORT bool operator!=(const Matrix4 &a, const Matrix4 &b); |
| Geoff Lang | f613935 | 2014-03-03 21:44:56 | [diff] [blame] | 61 | |
| Jamie Madill | ad60e8e | 2015-09-22 16:40:31 | [diff] [blame] | 62 | #endif // UTIL_MATRIX_H |