diff --git a/Source/Engine/Core/Math/Float2.cs b/Source/Engine/Core/Math/Float2.cs
index 3ca6f51d7..38fb7534a 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..ad1797644 100644
--- a/Source/Engine/Core/Math/Vector3.cs
+++ b/Source/Engine/Core/Math/Vector3.cs
@@ -1671,6 +1671,35 @@ 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;
+ }
+ ///
+ /// 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, Float3 gridSize)
+ {
+ translation.X = Mathr.Ceil((translation.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X;
+ translation.Y = Mathr.Ceil((translation.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y;
+ translation.Z = Mathr.Ceil((translation.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z;
+ return translation;
+ }
+
///
/// Adds two vectors.
///