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