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