From 07aafea5afec90bdc957bf5757de1183dd003aa6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 26 Nov 2024 14:54:11 +0100 Subject: [PATCH] Fix `Forward` and `Backward` in `Matrix` and `Matrix3x3` #3078 --- Source/Engine/Core/Math/Matrix.cs | 30 +++++++++++++------------- Source/Engine/Core/Math/Matrix.h | 30 +++++++++++++------------- Source/Engine/Core/Math/Matrix3x3.cs | 14 +++++------- Source/Engine/Core/Math/Matrix3x3.h | 32 ++++++++++++++-------------- 4 files changed, 51 insertions(+), 55 deletions(-) diff --git a/Source/Engine/Core/Math/Matrix.cs b/Source/Engine/Core/Math/Matrix.cs index c065379d3..71edef415 100644 --- a/Source/Engine/Core/Math/Matrix.cs +++ b/Source/Engine/Core/Math/Matrix.cs @@ -215,23 +215,9 @@ namespace FlaxEngine } /// - /// Gets or sets the forward of the matrix; that is -M31, -M32, and -M33. + /// Gets or sets the forward of the matrix; that is M31, M32, and M33. /// public Float3 Forward - { - get => new Float3(-M31, -M32, -M33); - set - { - M31 = -value.X; - M32 = -value.Y; - M33 = -value.Z; - } - } - - /// - /// Gets or sets the backward of the matrix; that is M31, M32, and M33. - /// - public Float3 Backward { get => new Float3(M31, M32, M33); set @@ -242,6 +228,20 @@ namespace FlaxEngine } } + /// + /// Gets or sets the backward of the matrix; that is -M31, -M32, and -M33. + /// + public Float3 Backward + { + get => new Float3(-M31, -M32, -M33); + set + { + M31 = -value.X; + M32 = -value.Y; + M33 = -value.Z; + } + } + /// /// Initializes a new instance of the struct. /// diff --git a/Source/Engine/Core/Math/Matrix.h b/Source/Engine/Core/Math/Matrix.h index 0eddc173b..e71da993a 100644 --- a/Source/Engine/Core/Math/Matrix.h +++ b/Source/Engine/Core/Math/Matrix.h @@ -210,31 +210,31 @@ public: // Gets the forward Float3 of the matrix; that is -M31, -M32, and -M33. Float3 GetForward() const { - return -Float3(M31, M32, M33); + return Float3(M31, M32, M33); } // Sets the forward Float3 of the matrix; that is -M31, -M32, and -M33. void SetForward(const Float3& value) - { - M31 = -value.X; - M32 = -value.Y; - M33 = -value.Z; - } - - // Gets the backward Float3 of the matrix; that is M31, M32, and M33. - Float3 GetBackward() const - { - return Float3(M31, M32, M33); - } - - // Sets the backward Float3 of the matrix; that is M31, M32, and M33. - void SetBackward(const Float3& value) { M31 = value.X; M32 = value.Y; M33 = value.Z; } + // Gets the backward Float3 of the matrix; that is -M31, -M32, and -M33. + Float3 GetBackward() const + { + return Float3(-M31, -M32, -M33); + } + + // Sets the backward Float3 of the matrix; that is -M31, -M32, and -M33. + void SetBackward(const Float3& value) + { + M31 = -value.X; + M32 = -value.Y; + M33 = -value.Z; + } + // Gets the first row in the matrix; that is M11, M12, M13, and M14. Float4 GetRow1() const { diff --git a/Source/Engine/Core/Math/Matrix3x3.cs b/Source/Engine/Core/Math/Matrix3x3.cs index b19d80490..970ec6cec 100644 --- a/Source/Engine/Core/Math/Matrix3x3.cs +++ b/Source/Engine/Core/Math/Matrix3x3.cs @@ -303,9 +303,6 @@ namespace FlaxEngine /// /// Gets a value indicating whether this instance is an identity Matrix3x3. /// - /// - /// true if this instance is an identity Matrix3x3; otherwise, false. - /// public bool IsIdentity => Equals(Identity); /// @@ -566,19 +563,19 @@ namespace FlaxEngine /// public bool DecomposeUniformScale(out float scale, out Quaternion rotation) { - //Scaling is the length of the rows. ( just take one row since this is a uniform matrix) + // Scaling is the length of the rows. ( just take one row since this is a uniform matrix) scale = (float)Math.Sqrt((M11 * M11) + (M12 * M12) + (M13 * M13)); var invScale = 1f / scale; - //If any of the scaling factors are zero, then the rotation matrix can not exist. + // If any of the scaling factors are zero, then the rotation matrix can not exist if (Math.Abs(scale) < Mathf.Epsilon) { rotation = Quaternion.Identity; return false; } - //The rotation is the left over matrix after dividing out the scaling. - Matrix3x3 rotationmatrix = new Matrix3x3 + // The rotation is the leftover matrix after dividing out the scaling + var rotationMatrix = new Matrix3x3 { M11 = M11 * invScale, M12 = M12 * invScale, @@ -590,8 +587,7 @@ namespace FlaxEngine M32 = M32 * invScale, M33 = M33 * invScale }; - - Quaternion.RotationMatrix(ref rotationmatrix, out rotation); + Quaternion.RotationMatrix(ref rotationMatrix, out rotation); return true; } diff --git a/Source/Engine/Core/Math/Matrix3x3.h b/Source/Engine/Core/Math/Matrix3x3.h index f5f8cd998..cb5ae04a2 100644 --- a/Source/Engine/Core/Math/Matrix3x3.h +++ b/Source/Engine/Core/Math/Matrix3x3.h @@ -175,34 +175,34 @@ public: M13 = -value.Z; } - // Gets the forward Float3 of the matrix; that is -M31, -M32, and -M33. + // Gets the forward Float3 of the matrix; that is M31, M32, and M33. Float3 GetForward() const { return -Float3(M31, M32, M33); } - // Sets the forward Float3 of the matrix; that is -M31, -M32, and -M33. + // Sets the forward Float3 of the matrix; that is M31, M32, and M33. void SetForward(const Float3& value) - { - M31 = -value.X; - M32 = -value.Y; - M33 = -value.Z; - } - - // Gets the backward Float3 of the matrix; that is M31, M32, and M33. - Float3 GetBackward() const - { - return Float3(M31, M32, M33); - } - - // Sets the backward Float3 of the matrix; that is M31, M32, and M33. - void SetBackward(const Float3& value) { M31 = value.X; M32 = value.Y; M33 = value.Z; } + // Gets the backward Float3 of the matrix; that is -M31, -M32, and -M33. + Float3 GetBackward() const + { + return Float3(-M31, -M32, -M33); + } + + // Sets the backward Float3 of the matrix; that is -M31, -M32, and -M33. + void SetBackward(const Float3& value) + { + M31 = -value.X; + M32 = -value.Y; + M33 = -value.Z; + } + // Gets the first row in the matrix; that is M11, M12 and M13. Float3 GetRow1() const {