1#ifndef RAYLIB_CPP_INCLUDE_MATRIX_HPP_
2#define RAYLIB_CPP_INCLUDE_MATRIX_HPP_
5#include "./raylib-cpp-utils.hpp"
6#include "./raymath.hpp"
7#include "./RadiansDegrees.hpp"
8#include "./Vector4.hpp"
10#ifndef RAYLIB_CPP_NO_MATH
20 struct LocalSpace_t {};
21 constexpr static LocalSpace_t LocalSpace{};
22 struct GlobalSpace_t {};
23 constexpr static GlobalSpace_t GlobalSpace{};
25 Matrix(const ::Matrix& mat) : ::Matrix{
26 mat.m0, mat.m4, mat.m8, mat.m12,
27 mat.m1, mat.m5, mat.m9, mat.m13,
28 mat.m2, mat.m6, mat.m10, mat.m14,
29 mat.m3, mat.m7, mat.m11, mat.m15} {
34 float m0 = 0,
float m4 = 0,
float m8 = 0,
float m12 = 0,
35 float m1 = 0,
float m5 = 0,
float m9 = 0,
float m13 = 0,
36 float m2 = 0,
float m6 = 0,
float m10 = 0,
float m14 = 0,
37 float m3 = 0,
float m7 = 0,
float m11 = 0,
float m15 = 0) :
46 GETTERSETTER(
float, M0, m0)
47 GETTERSETTER(
float, M1, m1)
48 GETTERSETTER(
float, M2, m2)
49 GETTERSETTER(
float, M3, m3)
50 GETTERSETTER(
float, M4, m4)
51 GETTERSETTER(
float, M5, m5)
52 GETTERSETTER(
float, M6, m6)
53 GETTERSETTER(
float, M7, m7)
54 GETTERSETTER(
float, M8, m8)
55 GETTERSETTER(
float, M9, m9)
56 GETTERSETTER(
float, M10, m10)
57 GETTERSETTER(
float, M11, m11)
58 GETTERSETTER(
float, M12, m12)
59 GETTERSETTER(
float, M13, m13)
60 GETTERSETTER(
float, M14, m14)
61 GETTERSETTER(
float, M15, m15)
73 bool operator==(const ::Matrix& other) {
92 bool operator!=(const ::Matrix& other) {
93 return !(*
this == other);
96#ifndef RAYLIB_CPP_NO_MATH
101 return ::MatrixTrace(*
this);
108 return ::MatrixTranspose(*
this);
115 return ::MatrixInvert(*
this);
122 return ::MatrixIdentity();
137 return ::MatrixAdd(*
this, right);
144 return ::MatrixAdd(*
this, matrix);
151 return ::MatrixSubtract(*
this, right);
158 return ::MatrixSubtract(*
this, matrix);
165 return ::MatrixMultiply(*
this, right);
172 return ::MatrixMultiply(*
this, matrix);
179 return ::MatrixTranslate(x, y, z);
207 return ::MatrixTranslate(translation.x, translation.y, translation.z);
214 return (*
this) *
CreateTranslate(translation.x, translation.y, translation.z);
221 return CreateTranslate(translation.x, translation.y, translation.z) * (*this);
228 return Translate(GlobalSpace, translation.x, translation.y, translation.z);
235 return ::MatrixRotate(axis, angle);
257 return Rotate(LocalSpace, axis, angle);
264 auto [axis, angle] = quat.ToAxisAngle();
287 return Rotate(LocalSpace, quat);
294 return ::MatrixRotateXYZ(angle);
352 return ::MatrixRotateX(angle);
374 return RotateX(LocalSpace, angle);
381 return ::MatrixRotateY(angle);
403 return RotateY(LocalSpace, angle);
410 return ::MatrixRotateZ(angle);
432 return RotateZ(LocalSpace, angle);
439 return ::MatrixScale(x, y, z);
448 inline Matrix Scale(GlobalSpace_t,
float all)
const {
449 return Scale(GlobalSpace, all, all, all);
459 inline Matrix Scale(LocalSpace_t,
float all)
const {
460 return Scale(LocalSpace, all, all, all);
467 return Scale(LocalSpace, x, y, z);
470 return Scale(LocalSpace, all);
473 static Matrix Frustum(
double left,
double right,
double bottom,
double top,
474 double near,
double far) {
475 return ::MatrixFrustum(left, right, bottom, top, near, far);
478 static Matrix Perspective(
double fovy,
double aspect,
double near,
double far) {
479 return ::MatrixPerspective(fovy, aspect, near, far);
482 static Matrix Ortho(
double left,
double right,
double bottom,
double top,
483 double near,
double far) {
484 return ::MatrixOrtho(left, right, bottom, top, near, far);
487 static Matrix LookAt(Vector3 eye, Vector3 target, Vector3 up) {
488 return ::MatrixLookAt(eye, target, up);
491 float16 ToFloatV()
const {
492 return ::MatrixToFloatV(*
this);
503 ::SetShaderValueMatrix(shader, uniformLoc, *
this);
507 static Matrix GetCamera(const ::Camera& camera) {
508 return ::GetCameraMatrix(camera);
511 static Matrix GetCamera(const ::Camera2D& camera) {
512 return ::GetCameraMatrix2D(camera);
518 void set(const ::Matrix& mat) {
538using Transform = Matrix;
Matrix type (OpenGL style 4x4 - right handed, column major)
Matrix RotateZ(Radian angle) const
Rotates the current matrix in local space around the Z axis.
Matrix operator+(const ::Matrix &matrix) const
Elementwise matrix addition.
static Matrix CreateRotate(Quaternion quat)
Creates a rotation matrix around the given quaternion.
Matrix Rotate(GlobalSpace_t, Quaternion quat) const
Rotates the current matrix in global space around the given quaternion.
Matrix Translate(float x, float y, float z) const
Translates the current matrix in global space.
static Matrix CreateRotate(Vector3 axis, Radian angle)
Creates a rotation matrix around the given axis.
Matrix Translate(LocalSpace_t, Vector3 translation) const
Translates the current matrix in local space.
Matrix RotateZ(LocalSpace_t, Radian angle) const
Rotates the current matrix in local space around the Z axis.
static Matrix CreateTranslate(float x, float y, float z)
Creates a translation matrix.
Matrix RotateZ(GlobalSpace_t, Radian angle) const
Rotates the current matrix in global space around the Z axis.
Matrix Rotate(GlobalSpace_t, Vector3 axis, Radian angle) const
Rotates the current matrix in global space around the given axis.
static Matrix CreateTranslate(Vector3 translation)
Creates a translation matrix.
static Matrix CreateRotateY(Radian angle)
Creates a rotation matrix around the Y axis.
Matrix Translate(GlobalSpace_t, float x, float y, float z) const
Translates the current matrix in global space.
static Matrix CreateScale(float x, float y, float z)
Creates a scale matrix.
Matrix TranslateToOrigin() const
Creates a matrix that when multiplied by the current matrix will translate back to the origin (New fu...
Matrix RotateY(GlobalSpace_t, Radian angle) const
Rotates the current matrix in global space around the Y axis.
Matrix Rotate(LocalSpace_t, Quaternion quat) const
Rotates the current matrix in local space around the given quaternion.
Matrix Rotate(Vector3 axis, Radian angle) const
Rotates the current matrix in local space around the given axis.
static Matrix CreateRotateXYZ(Radian x, Radian y, Radian z)
Creates a rotation matrix using the provided euler angles.
Matrix Translate(GlobalSpace_t, Vector3 translation) const
Translates the current matrix in global space.
Matrix RotateY(LocalSpace_t, Radian angle) const
Rotates the current matrix in local space around the Y axis.
Matrix Rotate(Quaternion quat) const
Rotates the current matrix in local space around the given quaternion.
Matrix RotateXYZ(Radian x, Radian y, Radian z) const
Rotates the current matrix using the provided euler angles in local space.
Matrix RotateXYZ(GlobalSpace_t, Radian x, Radian y, Radian z) const
Rotates the current matrix using the provided euler angles in global space.
Matrix RotateY(Radian angle) const
Rotates the current matrix in local space around the Y axis.
Matrix RotateXYZ(Vector3 angle) const
Rotates the current matrix using the provided euler angles in local space.
Matrix RotateXYZ(LocalSpace_t, Radian x, Radian y, Radian z) const
Rotates the current matrix using the provided euler angles in local space.
Matrix & SetShaderValue(const ::Shader &shader, int uniformLoc)
Set shader uniform value (matrix 4x4)
Matrix Scale(LocalSpace_t, float x, float y, float z) const
Scales the current matrix in local space.
float Trace() const
Returns the trace of the matrix (sum of the values along the diagonal)
Matrix Transpose() const
Transposes provided matrix.
static Matrix CreateRotateX(Radian angle)
Creates a rotation matrix around the X axis.
Matrix Scale(GlobalSpace_t, float x, float y, float z) const
Scales the current matrix in global space.
Matrix operator-(const ::Matrix &matrix) const
Elementwise matrix subtraction.
Matrix Add(const ::Matrix &right) const
Elementwise matrix addition.
Matrix Translate(Vector3 translation) const
Translates the current matrix in global space.
Matrix Invert() const
Inverts provided matrix.
static Matrix Identity()
Creates an identity matrix.
Matrix Translate(LocalSpace_t, float x, float y, float z) const
Translates the current matrix in local space.
Matrix operator*(const ::Matrix &matrix) const
Matrix multiplication.
static Matrix CreateRotateXYZ(Vector3 angle)
Creates a rotation matrix using the provided euler angles.
Matrix RotateX(LocalSpace_t, Radian angle) const
Rotates the current matrix in local space around the X axis.
Matrix RotateX(GlobalSpace_t, Radian angle) const
Rotates the current matrix in global space around the X axis.
Matrix RotateXYZ(LocalSpace_t, Vector3 angle) const
Rotates the current matrix using the provided euler angles in local space.
Matrix Scale(float x, float y, float z) const
Scales the current matrix in local space.
Matrix RotateXYZ(GlobalSpace_t, Vector3 angle) const
Rotates the current matrix using the provided euler angles in global space.
Matrix Rotate(LocalSpace_t, Vector3 axis, Radian angle) const
Rotates the current matrix in local space around the given axis.
Matrix Subtract(const ::Matrix &right) const
Elementwise matrix subtraction.
static Matrix CreateRotateZ(Radian angle)
Creates a rotation matrix around the given axis.
Matrix Multiply(const ::Matrix &right) const
Matrix multiplication.
Matrix RotateX(Radian angle) const
Rotates the current matrix in local space around the X axis.
Radian type (allows automatic worry free conversion between radians and degrees)