1#ifndef RAYLIB_CPP_INCLUDE_MATRIX_HPP_
2#define RAYLIB_CPP_INCLUDE_MATRIX_HPP_
4#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} {
50 : ::Matrix{m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15} {
54 GETTERSETTER(
float, M0, m0)
55 GETTERSETTER(
float, M1, m1)
56 GETTERSETTER(
float, M2, m2)
57 GETTERSETTER(
float, M3, m3)
58 GETTERSETTER(
float, M4, m4)
59 GETTERSETTER(
float, M5, m5)
60 GETTERSETTER(
float, M6, m6)
61 GETTERSETTER(
float, M7, m7)
62 GETTERSETTER(
float, M8, m8)
63 GETTERSETTER(
float, M9, m9)
64 GETTERSETTER(
float, M10, m10)
65 GETTERSETTER(
float, M11, m11)
66 GETTERSETTER(
float, M12, m12)
67 GETTERSETTER(
float, M13, m13)
68 GETTERSETTER(
float, M14, m14)
69 GETTERSETTER(
float, M15, m15)
72 if (
this != &matrix) {
79 if (
this != &matrix) {
85 bool operator==(const ::Matrix& other) {
86 return m0 == other.m0 && m1 == other.m1 && m2 == other.m2 && m3 == other.m3 && m4 == other.m4 &&
87 m5 == other.m5 && m6 == other.m6 && m7 == other.m7 && m8 == other.m8 && m9 == other.m9 &&
88 m10 == other.m10 && m11 == other.m11 && m12 == other.m12 && m13 == other.m13 && m14 == other.m14 &&
92 bool operator!=(const ::Matrix& other) {
return !(*
this == other); }
94#ifndef RAYLIB_CPP_NO_MATH
99 return ::MatrixTrace(*
this);
106 return ::MatrixTranspose(*
this);
113 return ::MatrixInvert(*
this);
120 return ::MatrixIdentity();
135 return ::MatrixAdd(*
this, right);
142 return ::MatrixAdd(*
this, matrix);
149 return ::MatrixSubtract(*
this, right);
156 return ::MatrixSubtract(*
this, matrix);
163 return ::MatrixMultiply(*
this, right);
170 return ::MatrixMultiply(*
this, matrix);
177 return ::MatrixTranslate(x, y, z);
205 return ::MatrixTranslate(translation.x, translation.y, translation.z);
212 return (*
this) *
CreateTranslate(translation.x, translation.y, translation.z);
219 return CreateTranslate(translation.x, translation.y, translation.z) * (*this);
226 return Translate(GlobalSpace, translation.x, translation.y, translation.z);
233 return ::MatrixRotate(axis, angle);
255 return Rotate(LocalSpace, axis, angle);
262 auto [axis, angle] = quat.ToAxisAngle();
285 return Rotate(LocalSpace, quat);
292 return ::MatrixRotateXYZ(angle);
350 return ::MatrixRotateX(angle);
372 return RotateX(LocalSpace, angle);
379 return ::MatrixRotateY(angle);
401 return RotateY(LocalSpace, angle);
408 return ::MatrixRotateZ(angle);
430 return RotateZ(LocalSpace, angle);
437 return ::MatrixScale(x, y, z);
459 return Scale(LocalSpace, x, y, z);
463 return Scale(LocalSpace, all, all, all);
466 static Matrix Frustum(
double left,
double right,
double bottom,
double top,
467 double near,
double far) {
468 return ::MatrixFrustum(left, right, bottom, top, near, far);
471 static Matrix Perspective(
double fovy,
double aspect,
double near,
double far) {
472 return ::MatrixPerspective(fovy, aspect, near, far);
475 static Matrix Ortho(
double left,
double right,
double bottom,
double top,
double near,
double far) {
476 return ::MatrixOrtho(left, right, bottom, top, near, far);
479 static Matrix LookAt(Vector3 eye, Vector3 target, Vector3 up) { return ::MatrixLookAt(eye, target, up); }
481 [[nodiscard]] float16 ToFloatV()
const { return ::MatrixToFloatV(*
this); }
483 operator float16()
const {
return ToFloatV(); }
489 ::SetShaderValueMatrix(shader, uniformLoc, *
this);
493 static Matrix GetCamera(const ::Camera& camera) { return ::GetCameraMatrix(camera); }
495 static Matrix GetCamera(const ::Camera2D& camera) { return ::GetCameraMatrix2D(camera); }
499 void set(const ::Matrix& mat) {
519using 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)
All raylib-cpp classes and functions appear in the raylib namespace.