From f6313b44277dc3e61854108fa0e54e613bc7484c Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Wed, 3 Apr 2024 04:53:11 +0200 Subject: [PATCH 01/11] Extended math lib added GetRotacionFromNormal AlignRotacionToNormalAndSnapToGrid SnapToRotatedGrid SnapToRotatedGridWithOffset --- Source/Engine/Core/Math/Quaternion.cs | 41 ++++++ Source/Engine/Core/Math/Quaternion.h | 21 +++ Source/Engine/Core/Math/Transform.cs | 181 ++++++++++++++++++++++++++ Source/Engine/Core/Math/Transform.h | 71 ++++++++++ Source/Engine/Core/Math/Vector3.cs | 74 +++++++++++ Source/Engine/Core/Math/Vector3.h | 41 ++++++ 6 files changed, 429 insertions(+) diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index 86a6e4e2d..b69df3969 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -1479,6 +1479,47 @@ namespace FlaxEngine return results; } + /// + /// Gets rotacion for normal in relation to transform
+ /// Funcion especially created for aligned with axis aligned faces + /// use full with + /// + /// Example code: + /// + /// GetRotacionFromNormalExample :
+ /// RayOrgin;
+ /// SomeObject;
+ ///
+ /// {
+ /// (.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out Hit) + /// {
+ /// position = Hit.Collider.Position; + /// transform = Hit.Collider.Transform; + /// point = Hit.Point; + /// normal = Hit.Normal; + /// rot = .GetRotacionFromNormal(normal,transform); + /// SomeObject.Position = point; + /// SomeObject.Orientation = rot; + /// } + /// } + /// } + ///
+ ///
+ ///
+ /// the normal vector + /// relative to + /// normal as rotacion + public static Quaternion GetRotacionFromNormal(Vector3 InNormal, Transform InRefrenceTransform) + { + Float3 up = InRefrenceTransform.Up; + var dot = Vector3.Dot(InNormal, up); + if (Mathf.NearEqual(Math.Abs(dot), 1)) + { + up = InRefrenceTransform.Right; + } + return Quaternion.LookRotation(InNormal, up); + } + /// /// Adds two quaternions. /// diff --git a/Source/Engine/Core/Math/Quaternion.h b/Source/Engine/Core/Math/Quaternion.h index 0790dcbfb..2f2c538a6 100644 --- a/Source/Engine/Core/Math/Quaternion.h +++ b/Source/Engine/Core/Math/Quaternion.h @@ -660,6 +660,27 @@ public: // @param roll The roll of rotation (in radians) // @param result When the method completes, contains the newly created quaternion static void RotationYawPitchRoll(float yaw, float pitch, float roll, Quaternion& result); + + + /// + /// Gets rotacion for normal in relation to transform
+ /// Funcion especially created for aligned with axis aligned faces + /// use full with + ///
+ /// 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); + } + }; /// diff --git a/Source/Engine/Core/Math/Transform.cs b/Source/Engine/Core/Math/Transform.cs index e00265f6d..844625514 100644 --- a/Source/Engine/Core/Math/Transform.cs +++ b/Source/Engine/Core/Math/Transform.cs @@ -477,6 +477,187 @@ namespace FlaxEngine Quaternion.Slerp(ref start.Orientation, ref end.Orientation, amount, out result.Orientation); Float3.Lerp(ref start.Scale, ref end.Scale, amount, out result.Scale); } + /// + /// combines funcions
+ /// ,
+ /// + /// Example code: + /// + /// AlignRotacionToObjectAndSnapToGridExample :
+ /// Offset = 50.0f;
+ /// GridSize = * 20.0f;
+ /// RayOrgin;
+ /// SomeObject;
+ ///
+ /// {
+ /// (.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out Hit) + /// {
+ /// transform = Hit.Collider.Transform; + /// point = Hit.Point; + /// normal = Hit.Normal; + /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// ( + /// point, + /// normal, + /// Offset, + /// transform, + /// SomeObject.Scale, + /// GridSize + /// ); + /// } + /// } + /// } + ///
+ ///
+ ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// return scale + /// InRefrenceTransform + /// rotated and snaped transform + public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize) + { + Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, new Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale); + } + /// + /// combines funcions
+ /// ,
+ /// + /// Example code: + /// + /// AlignRotacionToObjectAndSnapToGridExample :
+ /// Offset = 50.0f;
+ /// GridSize = * 20.0f;
+ /// RayOrgin;
+ /// SomeObject;
+ ///
+ /// {
+ /// (.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out Hit) + /// {
+ /// transform = Hit.Collider.Transform; + /// point = Hit.Point; + /// normal = Hit.Normal; + /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// ( + /// point, + /// normal, + /// Offset, + /// transform, + /// GridSize + /// ); + /// } + /// } + /// } + ///
+ ///
+ ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// InRefrenceTransform + /// rotated and snaped transform with scale + public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Vector3 InGridSize) + { + Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, new Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3.One); + } + /// + /// combines funcions
+ /// ,
+ /// + /// Example code: + /// + /// AlignRotacionToObjectAndSnapToGridExample :
+ /// Offset = new Vector3(0, 0, 50f);
+ /// GridSize = * 20.0f;
+ /// RayOrgin;
+ /// SomeObject;
+ ///
+ /// {
+ /// (.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out Hit) + /// {
+ /// transform = Hit.Collider.Transform; + /// point = Hit.Point; + /// normal = Hit.Normal; + /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// ( + /// point, + /// normal, + /// Offset, + /// transform, + /// SomeObject.Scale, + /// GridSize + /// ); + /// } + /// } + /// } + ///
+ ///
+ ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// return scale + /// InRefrenceTransform + /// rotated and snaped transform + public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize) + { + Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale); + } + + /// + /// combines funcions
+ /// ,
+ /// + /// Example code: + /// + /// AlignRotacionToObjectAndSnapToGridExample :
+ /// Offset = new Vector3(0, 0, 50f);
+ /// GridSize = * 20.0f;
+ /// RayOrgin;
+ /// SomeObject;
+ ///
+ /// {
+ /// (.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out Hit) + /// {
+ /// transform = Hit.Collider.Transform; + /// point = Hit.Point; + /// normal = Hit.Normal; + /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// ( + /// point, + /// normal, + /// Offset, + /// transform, + /// GridSize + /// ); + /// } + /// } + /// } + ///
+ ///
+ ///
+ /// The position to snap. + /// The size of the grid. + /// The local grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// InRefrenceTransform + /// rotated and snaped transform with scale + public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Vector3 InGridSize) + { + Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3.One); + } /// /// Tests for equality between two objects. diff --git a/Source/Engine/Core/Math/Transform.h b/Source/Engine/Core/Math/Transform.h index 2c51bfa4a..a54c356db 100644 --- a/Source/Engine/Core/Math/Transform.h +++ b/Source/Engine/Core/Math/Transform.h @@ -291,6 +291,77 @@ public: return result; } + /// + /// combines funcions
+ /// ,
+ /// + ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// return scale + /// InRefrenceTransform + /// rotated and snaped transform + static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) + { + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale); + } + /// + /// combines funcions
+ /// ,
+ /// + ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// InRefrenceTransform + /// rotated and snaped transform with scale + static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) + { + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3::One); + } + /// + /// combines funcions
+ /// ,
+ /// + ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// return scale + /// InRefrenceTransform + /// rotated and snaped transform + static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo,const Float3& InReturnScale,const Vector3& InGridSize) + { + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale); + } + /// + /// combines funcions
+ /// ,
+ /// + ///
+ /// The position to snap. + /// The size of the grid. + /// The local grid offset to applay after snaping + /// Normal vector + /// Realative transform + /// InRefrenceTransform + /// rotated and snaped transform with scale + static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint,const Vector3& InNormal,const Vector3& InNormalOffset, const Transform& InRelativeTo,const Vector3& InGridSize) + { + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3::One); + } + public: FORCE_INLINE Transform operator*(const Transform& other) const { diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 848a3b532..9cda11544 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1685,6 +1685,80 @@ namespace FlaxEngine return pos; } + /// + /// Snaps the on to rotate grid.
+ /// for world aligned grid snapping use instead + /// Example code: + /// + /// SnapToRotatedGridExample :
+ /// GridSize = * 20.0f;
+ /// RayOrgin;
+ /// SomeObject;
+ ///
+ /// {
+ /// (.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out Hit) + /// {
+ /// position = Hit.Collider.Position; + /// transform = Hit.Collider.Transform; + /// point = Hit.Point; + /// normal = Hit.Normal; + /// //Get rotation from normal relative to collider transform + /// rot = .GetRotacionFromNormal(normal,transform); + /// point = .SnapToRotatedGrid(point,position,rot,GridSize); + /// SomeObject.Position = point; + /// } + /// } + /// } + ///
+ ///
+ ///
+ /// The position to snap. + /// The center point. + /// The rotation of the grid. + /// The size of the grid. + /// The position snapped to the grid. + public static Vector3 SnapToRotatedGrid(Vector3 InPoint, Vector3 InCenterPoint, Quaternion InOrientation, Vector3 InGridSize) + { + Vector3 p = (InPoint - InCenterPoint) * InOrientation.Conjugated(); + return (SnapToGrid(p, InGridSize) * InOrientation) + InCenterPoint; + } + /// + /// The same as but with local offset applied after point is spapend + /// Example code: + /// + /// SnapToRotatedGridWithOffsetExample :
+ /// Offset = new Vector3(0, 0, 50f);
+ /// GridSize = * 20.0f;
+ /// RayOrgin;
+ /// SomeObject;
+ ///
+ /// {
+ /// (.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out Hit) + /// {
+ /// position = Hit.Collider.Position; + /// transform = Hit.Collider.Transform; + /// point = Hit.Point; + /// normal = Hit.Normal; + /// rot = .GetRotacionFromNormal(normal,transform); + /// point = .SnapToRotatedGridWithOffset(point,position,Offset,rot,GridSize); + /// SomeObject.Position = point; + /// } + /// } + /// } + ///
+ ///
+ ///
+ /// The position to snap. + /// The center point. + /// The rotation of the grid. + /// The size of the grid. + /// The local grid offset to applay after snaping + /// + public static Vector3 SnapToRotatedGridWithOffset(Vector3 InPoint, Vector3 InCenterPoint, Vector3 InOffset, Quaternion InOrientation, Vector3 InGridSize) + { + return ((SnapToGrid((InPoint - InCenterPoint) * InOrientation.Conjugated(), InGridSize) + InOffset) * InOrientation) + InCenterPoint; + } + /// /// Adds two vectors. /// diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h index 950d730c5..b8f074b73 100644 --- a/Source/Engine/Core/Math/Vector3.h +++ b/Source/Engine/Core/Math/Vector3.h @@ -927,6 +927,47 @@ public: /// The second vector. /// The angle (in radians). static FLAXENGINE_API T Angle(const Vector3Base& from, const Vector3Base& to); + + /// + /// Snaps the input position into the grid. + /// + /// 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; + } + + /// + /// Snaps the on to rotate grid.
+ /// for world aligned grid snapping use instead + ///
+ /// The position to snap. + /// The center point. + /// 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; + } + /// + /// The same as but with local offset applied after point is spapend + /// + /// The position to snap. + /// The center point. + /// The rotation of the grid. + /// 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; + } }; template 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 02/11] 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 From 58d4bad400e1d751fcf08a10ed4b0bb7caa8fb13 Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Wed, 3 Apr 2024 06:16:46 +0200 Subject: [PATCH 03/11] Update Vector3.cpp --- Source/Engine/Core/Math/Vector3.cpp | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cpp b/Source/Engine/Core/Math/Vector3.cpp index 69dad16e7..30247d70b 100644 --- a/Source/Engine/Core/Math/Vector3.cpp +++ b/Source/Engine/Core/Math/Vector3.cpp @@ -324,12 +324,6 @@ 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) { @@ -338,6 +332,12 @@ Float3 Float3::SnapToGrid(const Float3& pos, const Float3& gridSize) Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z); } +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::SnapToRotatedGrid(const Float3& InPoint, const Float3& InCenterPoint, const Quaternion& InOrientation, const Float3& InGridSize) { @@ -658,12 +658,6 @@ 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) { @@ -672,6 +666,12 @@ Double3 Double3::SnapToGrid(const Double3& pos, const Double3& gridSize) Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z); } +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::SnapToRotatedGrid(const Double3& InPoint, const Double3& InCenterPoint, const Quaternion& InOrientation, const Double3& InGridSize) { @@ -893,12 +893,6 @@ 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) { @@ -907,6 +901,12 @@ Int3 Int3::SnapToGrid(const Int3& pos, const Int3& gridSize) Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z); } +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::SnapToRotatedGrid(const Int3& InPoint, const Int3& InCenterPoint, const Quaternion& InOrientation, const Int3& InGridSize) { From 137a60ccef739f59ff000d9cb0311f60a2ae6a06 Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Wed, 3 Apr 2024 06:34:22 +0200 Subject: [PATCH 04/11] will it explode ? --- Source/Engine/Core/Math/Transform.cpp | 6 ++++++ Source/Engine/Core/Math/Transform.h | 27 +++++++-------------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Source/Engine/Core/Math/Transform.cpp b/Source/Engine/Core/Math/Transform.cpp index 6195dad04..7a8c4cd3d 100644 --- a/Source/Engine/Core/Math/Transform.cpp +++ b/Source/Engine/Core/Math/Transform.cpp @@ -252,3 +252,9 @@ void Transform::Lerp(const Transform& t1, const Transform& t2, float amount, Tra Quaternion::Slerp(t1.Orientation, t2.Orientation, amount, result.Orientation); Float3::Lerp(t1.Scale, t2.Scale, amount, result.Scale); } + +inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) +{ + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale); +} diff --git a/Source/Engine/Core/Math/Transform.h b/Source/Engine/Core/Math/Transform.h index a54c356db..7d76f3432 100644 --- a/Source/Engine/Core/Math/Transform.h +++ b/Source/Engine/Core/Math/Transform.h @@ -304,11 +304,8 @@ public: /// return scale /// InRefrenceTransform /// rotated and snaped transform - static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) - { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); - return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale); - } + inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize); + /// /// combines funcions
/// ,
@@ -321,11 +318,8 @@ public: /// Realative transform /// InRefrenceTransform /// rotated and snaped transform with scale - static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) - { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); - return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3::One); - } + inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize); + /// /// combines funcions
/// ,
@@ -339,11 +333,8 @@ public: /// return scale /// InRefrenceTransform /// rotated and snaped transform - static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo,const Float3& InReturnScale,const Vector3& InGridSize) - { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); - return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale); - } + inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo,const Float3& InReturnScale,const Vector3& InGridSize); + /// /// combines funcions
/// ,
@@ -356,11 +347,7 @@ public: /// Realative transform /// InRefrenceTransform /// rotated and snaped transform with scale - static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint,const Vector3& InNormal,const Vector3& InNormalOffset, const Transform& InRelativeTo,const Vector3& InGridSize) - { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); - return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3::One); - } + inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint,const Vector3& InNormal,const Vector3& InNormalOffset, const Transform& InRelativeTo,const Vector3& InGridSize); public: FORCE_INLINE Transform operator*(const Transform& other) const From bfa3507cc6439c3d2cbccc10232d145c2243a873 Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Wed, 3 Apr 2024 06:36:33 +0200 Subject: [PATCH 05/11] missing cpp funcion :shit: --- Source/Engine/Core/Math/Transform.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Source/Engine/Core/Math/Transform.cpp b/Source/Engine/Core/Math/Transform.cpp index 7a8c4cd3d..cfb1ca3b7 100644 --- a/Source/Engine/Core/Math/Transform.cpp +++ b/Source/Engine/Core/Math/Transform.cpp @@ -258,3 +258,21 @@ inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& In Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale); } + +inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) +{ + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3::One); +} + +inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) +{ + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale); +} + +inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) +{ + Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3::One); +} From 18d641e2aa6f26b021204384cfaaf19576e1bc30 Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:34:51 +0200 Subject: [PATCH 06/11] correct spelling mistakes and doc's Co-Authored-By: Menotdan <32620310+Menotdan@users.noreply.github.com> --- Source/Engine/Core/Math/Quaternion.cpp | 6 +- Source/Engine/Core/Math/Quaternion.cs | 24 +++--- Source/Engine/Core/Math/Quaternion.h | 14 ++-- Source/Engine/Core/Math/Transform.cpp | 16 ++-- Source/Engine/Core/Math/Transform.cs | 90 ++++++++++---------- Source/Engine/Core/Math/Transform.h | 112 ++++++++++++------------- Source/Engine/Core/Math/Vector3.cs | 14 ++-- Source/Engine/Core/Math/Vector3.h | 19 +++-- 8 files changed, 146 insertions(+), 149 deletions(-) diff --git a/Source/Engine/Core/Math/Quaternion.cpp b/Source/Engine/Core/Math/Quaternion.cpp index addff7854..4197fa147 100644 --- a/Source/Engine/Core/Math/Quaternion.cpp +++ b/Source/Engine/Core/Math/Quaternion.cpp @@ -534,13 +534,13 @@ void Quaternion::RotationYawPitchRoll(float yaw, float pitch, float roll, Quater result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2; } -Quaternion Quaternion::GetRotacionFromNormal(const Vector3& InNormal, const Transform& InRefrenceTransform) +Quaternion Quaternion::GetRotationFromNormal(const Vector3& InNormal, const Transform& InReferenceTransform) { - Float3 up = InRefrenceTransform.GetUp(); + Float3 up = InReferenceTransform.GetUp(); auto dot = Vector3::Dot(InNormal, up); if (Math::NearEqual(Math::Abs(dot), 1)) { - up = InRefrenceTransform.GetRight(); + up = InReferenceTransform.GetRight(); } return Quaternion::LookRotation(InNormal, up); } diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index b69df3969..a23487c19 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -1480,13 +1480,13 @@ namespace FlaxEngine } /// - /// Gets rotacion for normal in relation to transform
- /// Funcion especially created for aligned with axis aligned faces - /// use full with + /// Gets rotation from a normal in relation to a transform.
+ /// This function is especially useful for axis aligned faces, + /// and with . /// /// Example code: /// - /// GetRotacionFromNormalExample :
+ /// GetRotationFromNormalExample :
/// RayOrgin;
/// SomeObject;
///
@@ -1497,7 +1497,7 @@ namespace FlaxEngine /// transform = Hit.Collider.Transform; /// point = Hit.Point; /// normal = Hit.Normal; - /// rot = .GetRotacionFromNormal(normal,transform); + /// rot = .GetRotationFromNormal(normal,transform); /// SomeObject.Position = point; /// SomeObject.Orientation = rot; /// } @@ -1506,18 +1506,18 @@ namespace FlaxEngine ///
///
///
- /// the normal vector - /// relative to - /// normal as rotacion - public static Quaternion GetRotacionFromNormal(Vector3 InNormal, Transform InRefrenceTransform) + /// The normal vector. + /// The reference transform. + /// The rotation from the normal vector. + public static Quaternion GetRotationFromNormal(Vector3 InNormal, Transform InReferenceTransform) { - Float3 up = InRefrenceTransform.Up; + Float3 up = InReferenceTransform.Up; var dot = Vector3.Dot(InNormal, up); if (Mathf.NearEqual(Math.Abs(dot), 1)) { - up = InRefrenceTransform.Right; + up = InReferenceTransform.Right; } - return Quaternion.LookRotation(InNormal, up); + return LookRotation(InNormal, up); } /// diff --git a/Source/Engine/Core/Math/Quaternion.h b/Source/Engine/Core/Math/Quaternion.h index b0e456e9b..d841f964f 100644 --- a/Source/Engine/Core/Math/Quaternion.h +++ b/Source/Engine/Core/Math/Quaternion.h @@ -663,14 +663,14 @@ public: /// - /// Gets rotacion for normal in relation to transform
- /// Funcion especially created for aligned with axis aligned faces - /// use full with + /// Gets rotation from a normal in relation to a transform.
+ /// This function is especially useful for axis aligned faces, + /// and with . ///
- /// the normal vector - /// relative to - /// normal as rotacion - static Quaternion GetRotacionFromNormal(const Vector3& InNormal, const Transform& InRefrenceTransform); + /// The normal vector. + /// The reference transform. + /// The rotation from the normal vector. + static Quaternion GetRotationFromNormal(const Vector3& InNormal, const Transform& InReferenceTransform); }; /// diff --git a/Source/Engine/Core/Math/Transform.cpp b/Source/Engine/Core/Math/Transform.cpp index cfb1ca3b7..234b78c04 100644 --- a/Source/Engine/Core/Math/Transform.cpp +++ b/Source/Engine/Core/Math/Transform.cpp @@ -253,26 +253,26 @@ void Transform::Lerp(const Transform& t1, const Transform& t2, float amount, Tra Float3::Lerp(t1.Scale, t2.Scale, amount, result.Scale); } -inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) +inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo); return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale); } -inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) +inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo); return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3::One); } -inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) +inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize) { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo); return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale); } -inline Transform Transform::AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) +inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize) { - Quaternion rot = Quaternion::GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo); return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3::One); } diff --git a/Source/Engine/Core/Math/Transform.cs b/Source/Engine/Core/Math/Transform.cs index 844625514..ba86c1a6d 100644 --- a/Source/Engine/Core/Math/Transform.cs +++ b/Source/Engine/Core/Math/Transform.cs @@ -478,12 +478,12 @@ namespace FlaxEngine Float3.Lerp(ref start.Scale, ref end.Scale, amount, out result.Scale); } /// - /// combines funcions
+ /// Combines the functions:
/// ,
- /// + /// . /// Example code: /// - /// AlignRotacionToObjectAndSnapToGridExample :
+ /// AlignRotationToObjectAndSnapToGridExample :
/// Offset = 50.0f;
/// GridSize = * 20.0f;
/// RayOrgin;
@@ -495,7 +495,7 @@ namespace FlaxEngine /// transform = Hit.Collider.Transform; /// point = Hit.Point; /// normal = Hit.Normal; - /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// SomeObject.Transform = .AlignRotationToNormalAndSnapToGrid /// ( /// point, /// normal, @@ -512,24 +512,24 @@ namespace FlaxEngine ///
/// The position to snap. /// The size of the grid. - /// The local Z grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// return scale - /// InRefrenceTransform - /// rotated and snaped transform - public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize) + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The scale to apply to the transform. + /// The rotated and snapped transform. + public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize) { - Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo); return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, new Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale); } + /// - /// combines funcions
+ /// Combines the functions:
/// ,
- /// + /// . /// Example code: /// - /// AlignRotacionToObjectAndSnapToGridExample :
+ /// AlignRotationToObjectAndSnapToGridExample :
/// Offset = 50.0f;
/// GridSize = * 20.0f;
/// RayOrgin;
@@ -541,7 +541,7 @@ namespace FlaxEngine /// transform = Hit.Collider.Transform; /// point = Hit.Point; /// normal = Hit.Normal; - /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// SomeObject.Transform = .AlignRotationToNormalAndSnapToGrid /// ( /// point, /// normal, @@ -557,23 +557,23 @@ namespace FlaxEngine ///
/// The position to snap. /// The size of the grid. - /// The local Z grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// InRefrenceTransform - /// rotated and snaped transform with scale - public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Vector3 InGridSize) + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The rotated and snapped transform with scale . + public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Vector3 InGridSize) { - Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo); return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, new Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3.One); } + /// - /// combines funcions
+ /// Combines the functions:
/// ,
- /// + /// . /// Example code: /// - /// AlignRotacionToObjectAndSnapToGridExample :
+ /// AlignRotationToObjectAndSnapToGridExample :
/// Offset = new Vector3(0, 0, 50f);
/// GridSize = * 20.0f;
/// RayOrgin;
@@ -585,7 +585,7 @@ namespace FlaxEngine /// transform = Hit.Collider.Transform; /// point = Hit.Point; /// normal = Hit.Normal; - /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// SomeObject.Transform = .AlignRotationToNormalAndSnapToGrid /// ( /// point, /// normal, @@ -602,25 +602,24 @@ namespace FlaxEngine ///
/// The position to snap. /// The size of the grid. - /// The local Z grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// return scale - /// InRefrenceTransform - /// rotated and snaped transform - public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize) + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The scale to apply to the transform. + /// The rotated and snapped transform. + public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize) { - Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo); return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale); } /// - /// combines funcions
+ /// Combines the functions:
/// ,
- /// + /// . /// Example code: /// - /// AlignRotacionToObjectAndSnapToGridExample :
+ /// AlignRotationToObjectAndSnapToGridExample :
/// Offset = new Vector3(0, 0, 50f);
/// GridSize = * 20.0f;
/// RayOrgin;
@@ -632,7 +631,7 @@ namespace FlaxEngine /// transform = Hit.Collider.Transform; /// point = Hit.Point; /// normal = Hit.Normal; - /// SomeObject.Transform = .AlignRotacionToNormalAndSnapToGrid + /// SomeObject.Transform = .AlignRotationToNormalAndSnapToGrid /// ( /// point, /// normal, @@ -648,14 +647,13 @@ namespace FlaxEngine ///
/// The position to snap. /// The size of the grid. - /// The local grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// InRefrenceTransform - /// rotated and snaped transform with scale - public static Transform AlignRotacionToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Vector3 InGridSize) + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The rotated and snapped transform with scale . + public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Vector3 InGridSize) { - Quaternion rot = Quaternion.GetRotacionFromNormal(InNormal, InRelativeTo); + Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo); return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3.One); } diff --git a/Source/Engine/Core/Math/Transform.h b/Source/Engine/Core/Math/Transform.h index 7d76f3432..f170ce7a9 100644 --- a/Source/Engine/Core/Math/Transform.h +++ b/Source/Engine/Core/Math/Transform.h @@ -18,20 +18,20 @@ API_STRUCT() struct FLAXENGINE_API Transform /// /// The translation vector of the transform. /// - API_FIELD(Attributes="EditorOrder(10), EditorDisplay(null, \"Position\"), ValueCategory(Utils.ValueCategory.Distance)") - Vector3 Translation; + API_FIELD(Attributes = "EditorOrder(10), EditorDisplay(null, \"Position\"), ValueCategory(Utils.ValueCategory.Distance)") + Vector3 Translation; /// /// The rotation of the transform. /// - API_FIELD(Attributes="EditorOrder(20), EditorDisplay(null, \"Rotation\"), ValueCategory(Utils.ValueCategory.Angle)") - Quaternion Orientation; + API_FIELD(Attributes = "EditorOrder(20), EditorDisplay(null, \"Rotation\"), ValueCategory(Utils.ValueCategory.Angle)") + Quaternion Orientation; /// /// The scale vector of the transform. /// - API_FIELD(Attributes="EditorOrder(30), Limit(float.MinValue, float.MaxValue, 0.01f)") - Float3 Scale; + API_FIELD(Attributes = "EditorOrder(30), Limit(float.MinValue, float.MaxValue, 0.01f)") + Float3 Scale; public: /// @@ -291,63 +291,61 @@ public: return result; } - /// - /// combines funcions
- /// ,
- /// - ///
- /// The position to snap. - /// The size of the grid. - /// The local Z grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// return scale - /// InRefrenceTransform - /// rotated and snaped transform - inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize); - - /// - /// combines funcions
- /// ,
- /// - ///
- /// The position to snap. - /// The size of the grid. - /// The local Z grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// InRefrenceTransform - /// rotated and snaped transform with scale - inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize); - - /// - /// combines funcions
- /// ,
- /// - ///
- /// The position to snap. - /// The size of the grid. - /// The local Z grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// return scale - /// InRefrenceTransform - /// rotated and snaped transform - inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo,const Float3& InReturnScale,const Vector3& InGridSize); /// - /// combines funcions
+ /// Combines the functions:
/// ,
- /// + /// . ///
/// The position to snap. /// The size of the grid. - /// The local grid offset to applay after snaping - /// Normal vector - /// Realative transform - /// InRefrenceTransform - /// rotated and snaped transform with scale - inline static Transform AlignRotacionToNormalAndSnapToGrid(const Vector3& InPoint,const Vector3& InNormal,const Vector3& InNormalOffset, const Transform& InRelativeTo,const Vector3& InGridSize); + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The scale to apply to the transform. + /// The rotated and snapped transform. + static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize); + + /// + /// Combines the functions:
+ /// ,
+ /// . + ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The rotated and snapped transform with scale . + static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize); + + /// + /// Combines the functions:
+ /// ,
+ /// . + ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The scale to apply to the transform. + /// The rotated and snapped transform. + static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize); + + /// + /// Combines the functions:
+ /// ,
+ /// . + ///
+ /// The position to snap. + /// The size of the grid. + /// The local Z grid offset to apply after snapping. + /// The normal vector. + /// The relative transform. + /// The rotated and snapped transform with scale . + static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize); + public: FORCE_INLINE Transform operator*(const Transform& other) const diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 9cda11544..5e50dd07c 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1672,7 +1672,7 @@ namespace FlaxEngine } /// - /// Snaps the input position into the grid. + /// Snaps the input position onto the grid. /// /// The position to snap. /// The size of the grid. @@ -1686,8 +1686,8 @@ namespace FlaxEngine } /// - /// Snaps the on to rotate grid.
- /// for world aligned grid snapping use instead + /// Snaps the onto the rotated grid.
+ /// For world aligned grid snapping use instead. /// Example code: /// /// SnapToRotatedGridExample :
@@ -1723,7 +1723,7 @@ namespace FlaxEngine return (SnapToGrid(p, InGridSize) * InOrientation) + InCenterPoint; } /// - /// The same as but with local offset applied after point is spapend + /// The same as but with local offset applied after point is snapped. /// Example code: /// /// SnapToRotatedGridWithOffsetExample :
@@ -1739,7 +1739,7 @@ namespace FlaxEngine /// transform = Hit.Collider.Transform; /// point = Hit.Point; /// normal = Hit.Normal; - /// rot = .GetRotacionFromNormal(normal,transform); + /// rot = .GetRotationFromNormal(normal,transform); /// point = .SnapToRotatedGridWithOffset(point,position,Offset,rot,GridSize); /// SomeObject.Position = point; /// } @@ -1752,8 +1752,8 @@ namespace FlaxEngine /// The center point. /// The rotation of the grid. /// The size of the grid. - /// The local grid offset to applay after snaping - /// + /// The local grid offset to apply after snapping. + /// The position snapped to the grid, with offset applied. public static Vector3 SnapToRotatedGridWithOffset(Vector3 InPoint, Vector3 InCenterPoint, Vector3 InOffset, Quaternion InOrientation, Vector3 InGridSize) { return ((SnapToGrid((InPoint - InCenterPoint) * InOrientation.Conjugated(), InGridSize) + InOffset) * InOrientation) + InCenterPoint; diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h index 7850411f9..4160bf5d4 100644 --- a/Source/Engine/Core/Math/Vector3.h +++ b/Source/Engine/Core/Math/Vector3.h @@ -929,33 +929,34 @@ public: static FLAXENGINE_API T Angle(const Vector3Base& from, const Vector3Base& to); /// - /// Snaps the input position into the grid. + /// Snaps the input position onto the grid. /// /// The position to snap. /// The size of the grid. /// The position snapped to the grid. - static Vector3Base SnapToGrid(const Vector3Base& pos,const Vector3Base& gridSize); + static FLAXENGINE_API Vector3Base SnapToGrid(const Vector3Base& pos, const Vector3Base& gridSize); /// - /// Snaps the on to rotate grid.
- /// for world aligned grid snapping use instead + /// Snaps the onto the rotated grid.
+ /// For world aligned grid snapping use instead. ///
/// The position to snap. /// The center point. /// The rotation of the grid. /// The size of the grid. /// The position snapped to the grid. - static Vector3Base SnapToRotatedGrid(const Vector3Base& InPoint, const Vector3Base& InCenterPoint, const Quaternion& InOrientation, const Vector3Base& InGridSize); + static FLAXENGINE_API 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 + /// The same as but with local offset applied after point is snapped. /// /// The position to snap. /// The center point. /// The rotation of the grid. /// The size of the grid. - /// The local grid offset to applay after snaping - /// - static Vector3Base SnapToRotatedGridWithOffset(const Vector3Base& InPoint, const Vector3Base& InCenterPoint, const Vector3Base& InOffset, const Quaternion& InOrientation, const Vector3Base& InGridSize); + /// The local grid offset to apply after snapping. + /// The position snapped to the grid, with offset applied. + static FLAXENGINE_API Vector3Base SnapToRotatedGridWithOffset(const Vector3Base& InPoint, const Vector3Base& InCenterPoint, const Vector3Base& InOffset, const Quaternion& InOrientation, const Vector3Base& InGridSize); }; template From 92b35ab3e7ed626e8d2cf0417ce94c9a534ddd0a Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Sun, 7 Apr 2024 02:40:35 +0200 Subject: [PATCH 07/11] GetClosest for vectos --- Source/Engine/Core/Math/Vector3.cs | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 5e50dd07c..23b4b5368 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1759,6 +1759,94 @@ namespace FlaxEngine return ((SnapToGrid((InPoint - InCenterPoint) * InOrientation.Conjugated(), InGridSize) + InOffset) * InOrientation) + InCenterPoint; } + /// + /// Gets the closest vector id to + /// + /// + /// + /// index or -1 if all vectors in array are outside of + private int GetClosest(ref Vector3[] InArray, float Tolerance) + { + Vector3 self = this; + int FinalID = -1; + for (int i = 0; InArray.Length < 0; i++) + { + if (Distance(self, InArray[i]) <= Tolerance) + { + FinalID = i; + self = InArray[i]; + } + } + return FinalID; + } + + /// + /// Gets the closest vector id to + /// + /// + /// + /// index or -1 if all vectors in array are outside of + private int GetClosest(ref System.Collections.Generic.List InList, float Tolerance) + { + Vector3 self = this; + int FinalID = -1; + for (int i = 0; InList.Count < 0; i++) + { + if (Distance(self, InList[i]) <= Tolerance) + { + FinalID = i; + self = InList[i]; + } + } + return FinalID; + } + + /// + /// Gets the closest vector to + /// + /// + /// + /// + private void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref float OutDistance) + { + Vector3 self = this; + float LastDistance = float.MaxValue; + for (int i = 0; InArray.Length < 0; i++) + { + var d = Distance(self, InArray[i]); + if (d <= LastDistance) + { + self = InArray[i]; + LastDistance = d; + } + } + OutDistance = LastDistance; + OutVector = self; + } + + /// + /// Gets the closest vector to + /// + /// + /// + /// + private void GetClosest(ref System.Collections.Generic.List InList, ref Vector3 OutVector, ref float OutDistance) + { + Vector3 self = this; + float LastDistance = float.MaxValue; + for (int i = 0; InList.Count < 0; i++) + { + var d = Vector3.Distance(self, InList[i]); + if (d <= LastDistance) + { + self = InList[i]; + LastDistance = d; + } + } + OutDistance = LastDistance; + OutVector = self; + } + /// /// Adds two vectors. /// From 0b19d8639b7ee5395dd06080b07f6fccc6fb2122 Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Sun, 7 Apr 2024 03:02:47 +0200 Subject: [PATCH 08/11] changed float to Real --- Source/Engine/Core/Math/Vector3.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 23b4b5368..3cb19fbaf 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1765,7 +1765,7 @@ namespace FlaxEngine /// /// /// index or -1 if all vectors in array are outside of - private int GetClosest(ref Vector3[] InArray, float Tolerance) + private int GetClosest(ref Vector3[] InArray, Real Tolerance) { Vector3 self = this; int FinalID = -1; @@ -1786,7 +1786,7 @@ namespace FlaxEngine /// /// /// index or -1 if all vectors in array are outside of - private int GetClosest(ref System.Collections.Generic.List InList, float Tolerance) + private int GetClosest(ref System.Collections.Generic.List InList, Real Tolerance) { Vector3 self = this; int FinalID = -1; @@ -1807,7 +1807,7 @@ namespace FlaxEngine /// /// /// - private void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref float OutDistance) + private void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref Real OutDistance) { Vector3 self = this; float LastDistance = float.MaxValue; @@ -1830,7 +1830,7 @@ namespace FlaxEngine /// /// /// - private void GetClosest(ref System.Collections.Generic.List InList, ref Vector3 OutVector, ref float OutDistance) + private void GetClosest(ref System.Collections.Generic.List InList, ref Vector3 OutVector, ref Real OutDistance) { Vector3 self = this; float LastDistance = float.MaxValue; From 55be82a2c4af9e4e3710d51ca9921a4ef3aaa698 Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Sun, 7 Apr 2024 03:23:52 +0200 Subject: [PATCH 09/11] Update Vector3.cs --- Source/Engine/Core/Math/Vector3.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 3cb19fbaf..a745bc5c6 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1810,7 +1810,7 @@ namespace FlaxEngine private void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref Real OutDistance) { Vector3 self = this; - float LastDistance = float.MaxValue; + Real LastDistance = float.MaxValue; for (int i = 0; InArray.Length < 0; i++) { var d = Distance(self, InArray[i]); @@ -1833,7 +1833,7 @@ namespace FlaxEngine private void GetClosest(ref System.Collections.Generic.List InList, ref Vector3 OutVector, ref Real OutDistance) { Vector3 self = this; - float LastDistance = float.MaxValue; + Real LastDistance = float.MaxValue; for (int i = 0; InList.Count < 0; i++) { var d = Vector3.Distance(self, InList[i]); From 85f3fdd4381c4eaeec352ede64746b49ceecfb0b Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Sun, 7 Apr 2024 23:29:19 +0200 Subject: [PATCH 10/11] Update Vector3.cs --- Source/Engine/Core/Math/Vector3.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index a745bc5c6..d0974874a 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1765,7 +1765,7 @@ namespace FlaxEngine /// /// /// index or -1 if all vectors in array are outside of - private int GetClosest(ref Vector3[] InArray, Real Tolerance) + public int GetClosest(ref Vector3[] InArray, Real Tolerance) { Vector3 self = this; int FinalID = -1; @@ -1786,7 +1786,7 @@ namespace FlaxEngine /// /// /// index or -1 if all vectors in array are outside of - private int GetClosest(ref System.Collections.Generic.List InList, Real Tolerance) + public int GetClosest(ref System.Collections.Generic.List InList, Real Tolerance) { Vector3 self = this; int FinalID = -1; @@ -1807,10 +1807,10 @@ namespace FlaxEngine /// /// /// - private void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref Real OutDistance) + public void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref Real OutDistance) { Vector3 self = this; - Real LastDistance = float.MaxValue; + Real LastDistance = Real.MaxValue; for (int i = 0; InArray.Length < 0; i++) { var d = Distance(self, InArray[i]); @@ -1830,10 +1830,10 @@ namespace FlaxEngine /// /// /// - private void GetClosest(ref System.Collections.Generic.List InList, ref Vector3 OutVector, ref Real OutDistance) + public void GetClosest(ref System.Collections.Generic.List InList, ref Vector3 OutVector, ref Real OutDistance) { Vector3 self = this; - Real LastDistance = float.MaxValue; + Real LastDistance = Real.MaxValue; for (int i = 0; InList.Count < 0; i++) { var d = Vector3.Distance(self, InList[i]); From 137de0a8b22b1e6cd243864b1dcd2ba21414f7ba Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Mon, 8 Apr 2024 01:27:58 +0200 Subject: [PATCH 11/11] forgotten how to do loops :bug: :laughing: --- Source/Engine/Core/Math/Vector3.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index d0974874a..8294eaf64 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1769,7 +1769,7 @@ namespace FlaxEngine { Vector3 self = this; int FinalID = -1; - for (int i = 0; InArray.Length < 0; i++) + for (int i = 0; i < InArray.Length; i++) { if (Distance(self, InArray[i]) <= Tolerance) { @@ -1790,7 +1790,7 @@ namespace FlaxEngine { Vector3 self = this; int FinalID = -1; - for (int i = 0; InList.Count < 0; i++) + for (int i = 0; i < InList.Count; i++) { if (Distance(self, InList[i]) <= Tolerance) { @@ -1811,7 +1811,7 @@ namespace FlaxEngine { Vector3 self = this; Real LastDistance = Real.MaxValue; - for (int i = 0; InArray.Length < 0; i++) + for (int i = 0; i < InArray.Length; i++) { var d = Distance(self, InArray[i]); if (d <= LastDistance) @@ -1834,9 +1834,9 @@ namespace FlaxEngine { Vector3 self = this; Real LastDistance = Real.MaxValue; - for (int i = 0; InList.Count < 0; i++) + for (int i = 0; i < InList.Count; i++) { - var d = Vector3.Distance(self, InList[i]); + var d = Distance(self, InList[i]); if (d <= LastDistance) { self = InList[i];