Cleanup code #1795 and unify new api in vector types

This commit is contained in:
Wojtek Figat
2024-02-19 23:04:59 +01:00
parent 358220b0b5
commit 04da732da9
6 changed files with 71 additions and 46 deletions

View File

@@ -1520,6 +1520,20 @@ namespace FlaxEngine
return result;
}
/// <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>
public static Float3 SnapToGrid(Float3 pos, Float3 gridSize)
{
pos.X = Mathf.Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X;
pos.Y = Mathf.Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y;
pos.Z = Mathf.Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z;
return pos;
}
/// <summary>
/// Adds two vectors.
/// </summary>