diff --git a/Source/Engine/Core/Math/Float2.cs b/Source/Engine/Core/Math/Float2.cs
index 3ca6f51d7..4ded4cf92 100644
--- a/Source/Engine/Core/Math/Float2.cs
+++ b/Source/Engine/Core/Math/Float2.cs
@@ -1273,6 +1273,33 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// funcion for grid snaping snap to absolute world grid
+ ///
desined for snaping using a ray / draging object
+ ///
+ ///
+ ///
+ /// out = Ceil(((A - (GridSize * 0.5f)) / GridSize) * GridSize
+ 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;
+ }
+ ///
+ /// funcion for grid snaping snap to absolute world grid
+ ///
desined for snaping using a ray / draging object
+ ///
+ ///
+ ///
+ /// out = Ceil(((A - (GridSize * 0.5f)) / GridSize) * GridSize
+ 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;
+ }
+
///
/// Adds two vectors.
///
diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs
index 280093619..b7cc396ee 100644
--- a/Source/Engine/Core/Math/Vector3.cs
+++ b/Source/Engine/Core/Math/Vector3.cs
@@ -1671,6 +1671,21 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// funcion for grid snaping snap to absolute world grid
+ ///
desined for snaping using a ray / draging object
+ ///
+ ///
+ ///
+ /// out = Ceil(((A - (GridSize * 0.5f)) / GridSize) * GridSize
+ public static Vector3 SnapToGrid(Vector3 Translation, float GridSize)
+ {
+ Translation.X = Mathr.Ceil((Translation.X - (GridSize * 0.5f)) / GridSize) * GridSize;
+ Translation.Y = Mathr.Ceil((Translation.Y - (GridSize * 0.5f)) / GridSize) * GridSize;
+ Translation.Z = Mathr.Ceil((Translation.Z - (GridSize * 0.5f)) / GridSize) * GridSize;
+ return Translation;
+ }
+
///
/// Adds two vectors.
///