Extended math lib

added
GetRotacionFromNormal
AlignRotacionToNormalAndSnapToGrid
SnapToRotatedGrid
SnapToRotatedGridWithOffset
This commit is contained in:
Norite SC
2024-04-03 04:53:11 +02:00
parent ce07edd1ec
commit f6313b4427
6 changed files with 429 additions and 0 deletions

View File

@@ -927,6 +927,47 @@ public:
/// <param name="to">The second vector.</param>
/// <returns>The angle (in radians).</returns>
static FLAXENGINE_API T Angle(const Vector3Base& from, const Vector3Base& to);
/// <summary>
/// Snaps the input position into the grid.
/// </summary>
/// <param name="pos">The position to snap.</param>
/// <param name="gridSize">The size of the grid.</param>
/// <returns>The position snapped to the grid.</returns>
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;
}
/// <summary>
/// Snaps the <paramref name="InPoint"/> on to rotate grid.<br/>
/// for world aligned grid snapping use <b><see cref="Vector3::SnapToGrid"/></b> instead
/// </summary>
/// <param name="InPoint">The position to snap.</param>
/// <param name="InCenterPoint">The center point.</param>
/// <param name="InOrientation">The rotation of the grid.</param>
/// <param name="InGridSize">The size of the grid.</param>
/// <returns>The position snapped to the grid.</returns>
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;
}
/// <summary>
/// The same as <see cref="SnapToRotatedGrid"/> but with local offset applied after point is spapend
/// </summary>
/// <param name="InPoint">The position to snap.</param>
/// <param name="InCenterPoint">The center point.</param>
/// <param name="InOrientation">The rotation of the grid.</param>
/// <param name="InGridSize">The size of the grid.</param>
/// <param name="InOffset">The local grid offset to applay after snaping</param>
/// <returns></returns>
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<typename T>