This commit is contained in:
NoriteSC
2023-10-24 19:59:47 +02:00
parent 806590d1c3
commit f287ed6c30
2 changed files with 42 additions and 0 deletions

View File

@@ -1273,6 +1273,33 @@ namespace FlaxEngine
return result;
}
/// <summary>
/// funcion for grid snaping snap to absolute world grid
/// <br>desined for snaping using a ray / draging object</br>
/// </summary>
/// <param name="Translation"></param>
/// <param name="GridSize"></param>
/// <returns>out = Ceil(((A - (GridSize * 0.5f)) / GridSize) * GridSize</returns>
public static Float2 SnapToGrid(Float2 Translation, Float2 GridSize)
{
Translation.X = Mathf.Ceil((Translation.X - (GridSize.X * 0.5f)) / GridSize.Y) * GridSize.X;
Translation.Y = Mathf.Ceil((Translation.Y - (GridSize.Y * 0.5f)) / GridSize.X) * GridSize.Y;
return Translation;
}
/// <summary>
/// funcion for grid snaping snap to absolute world grid
/// <br>desined for snaping using a ray / draging object</br>
/// </summary>
/// <param name="Translation"></param>
/// <param name="GridSize"></param>
/// <returns>out = Ceil(((A - (GridSize * 0.5f)) / GridSize) * GridSize</returns>
public static Float2 SnapToGrid(Float2 Translation, float GridSize)
{
Translation.X = Mathf.Ceil((Translation.X - (GridSize * 0.5f)) / GridSize) * GridSize;
Translation.Y = Mathf.Ceil((Translation.Y - (GridSize * 0.5f)) / GridSize) * GridSize;
return Translation;
}
/// <summary>
/// Adds two vectors.
/// </summary>