From 3bea7f518d73e61fe1d9227263b5fd85f0f37da1 Mon Sep 17 00:00:00 2001 From: Lam Wei Lun Date: Mon, 2 Mar 2026 22:46:15 +0800 Subject: [PATCH] Added MatrixUnit and MatrixMultiplyValue (#5613) --- src/raymath.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/raymath.h b/src/raymath.h index ab1be1409..b0b8dd199 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1765,6 +1765,18 @@ RMAPI Matrix MatrixMultiply(Matrix left, Matrix right) return result; } +RMAPI Matrix MatrixMultiplyValue(Matrix left, float value) +{ + Matrix result = { + left.m0 * value, left.m4 * value, left.m8 * value, left.m12 * value, + left.m1 * value, left.m5 * value, left.m9 * value, left.m13 * value, + left.m2 * value, left.m6 * value, left.m10 * value, left.m14 * value, + left.m3 * value, left.m7 * value, left.m11 * value, left.m15 * value + }; + + return result; +} + // Get translation matrix RMAPI Matrix MatrixTranslate(float x, float y, float z) { @@ -3079,6 +3091,11 @@ inline const Quaternion& operator *= (Quaternion& lhs, const Matrix& rhs) } // Matrix operators +static constexpr Matrix MatrixUnit = { 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 }; + inline Matrix operator + (const Matrix& lhs, const Matrix& rhs) { return MatrixAdd(lhs, rhs); @@ -3111,6 +3128,18 @@ inline const Matrix& operator *= (Matrix& lhs, const Matrix& rhs) lhs = MatrixMultiply(lhs, rhs); return lhs; } + +inline Matrix operator * (const Matrix& lhs, const float value) +{ + return MatrixMultiplyValue(lhs, value); +} + +inline const Matrix& operator *= (Matrix& lhs, const float value) +{ + lhs = MatrixMultiplyValue(lhs, value); + return lhs; +} + //------------------------------------------------------------------------------- #endif // C++ operators