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