raylib-cpp
C++ object-oriented wrapper library for raylib.
Matrix.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_MATRIX_HPP_
2 #define RAYLIB_CPP_INCLUDE_MATRIX_HPP_
3 
4 #include "./raylib.hpp"
5 #include "./raylib-cpp-utils.hpp"
6 #include "./raymath.hpp"
7 
8 #ifndef RAYLIB_CPP_NO_MATH
9 #include <cmath>
10 #endif
11 
12 namespace raylib {
16 class Matrix : public ::Matrix {
17  public:
18  Matrix(const ::Matrix& mat) {
19  set(mat);
20  }
21 
22  Matrix(float M0 = 0, float M1 = 0, float M2 = 0, float M3 = 0, float M4 = 0, float M5 = 0,
23  float M6 = 0, float M7 = 0, float M8 = 0, float M9 = 0, float M10 = 0, float M11 = 0,
24  float M12 = 0, float M13 = 0, float M14 = 0, float M15 = 0) {
25  m0 = M0;
26  m1 = M1;
27  m2 = M2;
28  m3 = M3;
29  m4 = M4;
30  m5 = M5;
31  m6 = M6;
32  m7 = M7;
33  m8 = M8;
34  m9 = M9;
35  m10 = M10;
36  m11 = M11;
37  m12 = M12;
38  m13 = M13;
39  m14 = M14;
40  m15 = M15;
41  }
42 
43  GETTERSETTER(float, M0, m0)
44  GETTERSETTER(float, M1, m1)
45  GETTERSETTER(float, M2, m2)
46  GETTERSETTER(float, M3, m3)
47  GETTERSETTER(float, M4, m4)
48  GETTERSETTER(float, M5, m5)
49  GETTERSETTER(float, M6, m6)
50  GETTERSETTER(float, M7, m7)
51  GETTERSETTER(float, M8, m8)
52  GETTERSETTER(float, M9, m9)
53  GETTERSETTER(float, M10, m10)
54  GETTERSETTER(float, M11, m11)
55  GETTERSETTER(float, M12, m12)
56  GETTERSETTER(float, M13, m13)
57  GETTERSETTER(float, M14, m14)
58  GETTERSETTER(float, M15, m15)
59 
60  Matrix& operator=(const ::Matrix& matrix) {
61  set(matrix);
62  return *this;
63  }
64 
65  Matrix& operator=(const Matrix& matrix) {
66  set(matrix);
67  return *this;
68  }
69 
70  bool operator==(const ::Matrix& other) {
71  return m0 == other.m0
72  && m1 == other.m1
73  && m2 == other.m2
74  && m3 == other.m3
75  && m4 == other.m4
76  && m5 == other.m5
77  && m6 == other.m6
78  && m7 == other.m7
79  && m8 == other.m8
80  && m9 == other.m9
81  && m10 == other.m10
82  && m11 == other.m11
83  && m12 == other.m12
84  && m13 == other.m13
85  && m14 == other.m14
86  && m15 == other.m15;
87  }
88 
89 #ifndef RAYLIB_CPP_NO_MATH
90 
93  inline float Trace() const {
94  return ::MatrixTrace(*this);
95  }
96 
100  inline Matrix Transpose() const {
101  return ::MatrixTranspose(*this);
102  }
103 
104  inline Matrix Invert() const {
105  return ::MatrixInvert(*this);
106  }
107 
108  inline Matrix Normalize() const {
109  return ::MatrixNormalize(*this);
110  }
111 
112  static Matrix Identity() {
113  return ::MatrixIdentity();
114  }
115 
116  Matrix Add(const ::Matrix& right) {
117  return ::MatrixAdd(*this, right);
118  }
119 
120  Matrix operator+(const ::Matrix& matrix) {
121  return ::MatrixAdd(*this, matrix);
122  }
123 
124  Matrix Subtract(const ::Matrix& right) {
125  return ::MatrixSubtract(*this, right);
126  }
127 
128  Matrix operator-(const ::Matrix& matrix) {
129  return ::MatrixSubtract(*this, matrix);
130  }
131 
132  static Matrix Translate(float x, float y, float z) {
133  return ::MatrixTranslate(x, y, z);
134  }
135 
136  static Matrix Rotate(Vector3 axis, float angle) {
137  return ::MatrixRotate(axis, angle);
138  }
139 
140  static Matrix RotateXYZ(Vector3 angle) {
141  return ::MatrixRotateXYZ(angle);
142  }
143 
144  static Matrix RotateX(float angle) {
145  return ::MatrixRotateX(angle);
146  }
147 
148  static Matrix RotateY(float angle) {
149  return ::MatrixRotateY(angle);
150  }
151 
152  static Matrix RotateZ(float angle) {
153  return ::MatrixRotateZ(angle);
154  }
155 
156  static Matrix Scale(float x, float y, float z) {
157  return ::MatrixScale(x, y, z);
158  }
159 
160  Matrix Multiply(const ::Matrix& right) const {
161  return ::MatrixMultiply(*this, right);
162  }
163 
164  Matrix operator*(const ::Matrix& matrix) {
165  return ::MatrixMultiply(*this, matrix);
166  }
167 
168  static Matrix Frustum(double left, double right, double bottom, double top,
169  double near, double far) {
170  return ::MatrixFrustum(left, right, bottom, top, near, far);
171  }
172 
173  static Matrix Perspective(double fovy, double aspect, double near, double far) {
174  return ::MatrixPerspective(fovy, aspect, near, far);
175  }
176 
177  static Matrix Ortho(double left, double right, double bottom, double top,
178  double near, double far) {
179  return ::MatrixOrtho(left, right, bottom, top, near, far);
180  }
181 
182  static Matrix LookAt(Vector3 eye, Vector3 target, Vector3 up) {
183  return ::MatrixLookAt(eye, target, up);
184  }
185 
186  inline float16 ToFloatV() const {
187  return ::MatrixToFloatV(*this);
188  }
189 
190  operator float16() {
191  return ToFloatV();
192  }
193 
197  inline Matrix& SetShaderValue(::Shader shader, int uniformLoc) {
198  ::SetShaderValueMatrix(shader, uniformLoc, *this);
199  return *this;
200  }
201 
202 #endif
203 
204  private:
205  inline void set(const ::Matrix& mat) {
206  m0 = mat.m0;
207  m1 = mat.m1;
208  m2 = mat.m2;
209  m3 = mat.m3;
210  m4 = mat.m4;
211  m5 = mat.m5;
212  m6 = mat.m6;
213  m7 = mat.m7;
214  m8 = mat.m8;
215  m9 = mat.m9;
216  m10 = mat.m10;
217  m11 = mat.m11;
218  m12 = mat.m12;
219  m13 = mat.m13;
220  m14 = mat.m14;
221  m15 = mat.m15;
222  }
223 };
224 } // namespace raylib
225 
226 
227 #endif // RAYLIB_CPP_INCLUDE_MATRIX_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Matrix::Transpose
Matrix Transpose() const
Transposes provided matrix.
Definition: Matrix.hpp:100
raylib::Matrix
Matrix type (OpenGL style 4x4 - right handed, column major)
Definition: Matrix.hpp:16
raylib::Matrix::SetShaderValue
Matrix & SetShaderValue(::Shader shader, int uniformLoc)
Set shader uniform value (matrix 4x4)
Definition: Matrix.hpp:197
raylib::Shader
Shader type (generic)
Definition: Shader.hpp:14
raylib::Matrix::Trace
float Trace() const
Returns the trace of the matrix (sum of the values along the diagonal)
Definition: Matrix.hpp:93