From f6f1f0023a66731c884aed2603171be6fe106159 Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Wed, 3 Apr 2024 06:03:31 +0200 Subject: [PATCH] fixed compile errors --- Source/Engine/Core/Math/Quaternion.cpp | 12 ++++++ Source/Engine/Core/Math/Quaternion.h | 12 +----- Source/Engine/Core/Math/Vector3.cpp | 60 ++++++++++++++++++++++++++ Source/Engine/Core/Math/Vector3.h | 18 ++------ 4 files changed, 76 insertions(+), 26 deletions(-) diff --git a/Source/Engine/Core/Math/Quaternion.cpp b/Source/Engine/Core/Math/Quaternion.cpp index 03989dab5..addff7854 100644 --- a/Source/Engine/Core/Math/Quaternion.cpp +++ b/Source/Engine/Core/Math/Quaternion.cpp @@ -7,6 +7,7 @@ #include "Matrix3x3.h" #include "Math.h" #include "../Types/String.h" +#include "Engine/Core/Math/Transform.h" Quaternion Quaternion::Zero(0, 0, 0, 0); Quaternion Quaternion::One(1, 1, 1, 1); @@ -532,3 +533,14 @@ void Quaternion::RotationYawPitchRoll(float yaw, float pitch, float roll, Quater result.Y = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2; result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2; } + +Quaternion Quaternion::GetRotacionFromNormal(const Vector3& InNormal, const Transform& InRefrenceTransform) +{ + Float3 up = InRefrenceTransform.GetUp(); + auto dot = Vector3::Dot(InNormal, up); + if (Math::NearEqual(Math::Abs(dot), 1)) + { + up = InRefrenceTransform.GetRight(); + } + return Quaternion::LookRotation(InNormal, up); +} diff --git a/Source/Engine/Core/Math/Quaternion.h b/Source/Engine/Core/Math/Quaternion.h index 2f2c538a6..b0e456e9b 100644 --- a/Source/Engine/Core/Math/Quaternion.h +++ b/Source/Engine/Core/Math/Quaternion.h @@ -670,17 +670,7 @@ public: /// the normal vector /// relative to /// normal as rotacion - static Quaternion GetRotacionFromNormal(const Vector3& InNormal, const Transform& InRefrenceTransform) - { - Float3 up = InRefrenceTransform.GetUp(); - auto dot = Vector3::Dot(InNormal, up); - if (Math::NearEqual(Math::Abs(dot), 1)) - { - up = InRefrenceTransform.GetRight(); - } - return Quaternion::LookRotation(InNormal, up); - } - + static Quaternion GetRotacionFromNormal(const Vector3& InNormal, const Transform& InRefrenceTransform); }; /// diff --git a/Source/Engine/Core/Math/Vector3.cpp b/Source/Engine/Core/Math/Vector3.cpp index 3ffb2cdc9..69dad16e7 100644 --- a/Source/Engine/Core/Math/Vector3.cpp +++ b/Source/Engine/Core/Math/Vector3.cpp @@ -324,6 +324,26 @@ float Float3::Angle(const Float3& from, const Float3& to) return Math::Acos(dot); } +template<> +Float3 Float3::SnapToRotatedGridWithOffset(const Float3& InPoint, const Float3& InCenterPoint, const Float3& InOffset, const Quaternion& InOrientation, const Float3& InGridSize) +{ + return (InOrientation * (InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize) + InOffset)) + InCenterPoint; +} + +template<> +Float3 Float3::SnapToGrid(const Float3& pos, const Float3& gridSize) +{ + return Float3(Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X, + Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y, + Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z); +} + +template<> +Float3 Float3::SnapToRotatedGrid(const Float3& InPoint, const Float3& InCenterPoint, const Quaternion& InOrientation, const Float3& InGridSize) +{ + return (InOrientation * InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize)) + InCenterPoint; +} + // Double static_assert(sizeof(Double3) == 24, "Invalid Double3 type size."); @@ -638,6 +658,26 @@ double Double3::Angle(const Double3& from, const Double3& to) return Math::Acos(dot); } +template<> +Double3 Double3::SnapToRotatedGridWithOffset(const Double3& InPoint, const Double3& InCenterPoint, const Double3& InOffset, const Quaternion& InOrientation, const Double3& InGridSize) +{ + return (InOrientation * (InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize) + InOffset)) + InCenterPoint; +} + +template<> +Double3 Double3::SnapToGrid(const Double3& pos, const Double3& gridSize) +{ + return Double3(Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X, + Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y, + Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z); +} + +template<> +Double3 Double3::SnapToRotatedGrid(const Double3& InPoint, const Double3& InCenterPoint, const Quaternion& InOrientation, const Double3& InGridSize) +{ + return (InOrientation * InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize)) + InCenterPoint; +} + // Int static_assert(sizeof(Int3) == 12, "Invalid Int3 type size."); @@ -852,3 +892,23 @@ int32 Int3::Angle(const Int3& from, const Int3& to) { return 0; } + +template<> +Int3 Int3::SnapToRotatedGridWithOffset(const Int3& InPoint, const Int3& InCenterPoint, const Int3& InOffset, const Quaternion& InOrientation, const Int3& InGridSize) +{ + return (InOrientation * (InOrientation.Conjugated() * Int3::SnapToGrid((InPoint - InCenterPoint), InGridSize) + InOffset)) + InCenterPoint; +} + +template<> +Int3 Int3::SnapToGrid(const Int3& pos, const Int3& gridSize) +{ + return Double3(Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X, + Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y, + Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z); +} + +template<> +Int3 Int3::SnapToRotatedGrid(const Int3& InPoint, const Int3& InCenterPoint, const Quaternion& InOrientation, const Int3& InGridSize) +{ + return (InOrientation * InOrientation.Conjugated() * Int3::SnapToGrid((InPoint - InCenterPoint), InGridSize)) + InCenterPoint; +} diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h index b8f074b73..7850411f9 100644 --- a/Source/Engine/Core/Math/Vector3.h +++ b/Source/Engine/Core/Math/Vector3.h @@ -934,13 +934,7 @@ public: /// The position to snap. /// The size of the grid. /// The position snapped to the grid. - static Vector3 SnapToGrid(const Vector3& pos, Vector3 gridSize) - { - pos.X = Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X; - pos.Y = Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y; - pos.Z = Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z; - return pos; - } + static Vector3Base SnapToGrid(const Vector3Base& pos,const Vector3Base& gridSize); /// /// Snaps the on to rotate grid.
@@ -951,10 +945,7 @@ public: /// The rotation of the grid. /// The size of the grid. /// The position snapped to the grid. - static Vector3 SnapToRotatedGrid(const Vector3& InPoint, const Vector3& InCenterPoint, const Quaternion& InOrientation, const Vector3& InGridSize) - { - return (Vector3::SnapToGrid((InPoint - InCenterPoint) * InOrientation.Conjugated(), InGridSize) * InOrientation) + InCenterPoint; - } + static Vector3Base SnapToRotatedGrid(const Vector3Base& InPoint, const Vector3Base& InCenterPoint, const Quaternion& InOrientation, const Vector3Base& InGridSize); /// /// The same as but with local offset applied after point is spapend /// @@ -964,10 +955,7 @@ public: /// The size of the grid. /// The local grid offset to applay after snaping /// - static Vector3 SnapToRotatedGridWithOffset(const Vector3& InPoint, const Vector3& InCenterPoint, const Vector3& InOffset, const Quaternion& InOrientation, const Vector3& InGridSize) - { - return ((Vector3::SnapToGrid((InPoint - InCenterPoint) * InOrientation.Conjugated(), InGridSize) + InOffset) * InOrientation) + InCenterPoint; - } + static Vector3Base SnapToRotatedGridWithOffset(const Vector3Base& InPoint, const Vector3Base& InCenterPoint, const Vector3Base& InOffset, const Quaternion& InOrientation, const Vector3Base& InGridSize); }; template