diff --git a/Source/Engine/Core/Math/Double2.cs b/Source/Engine/Core/Math/Double2.cs
index 02669a869..9211d2a7b 100644
--- a/Source/Engine/Core/Math/Double2.cs
+++ b/Source/Engine/Core/Math/Double2.cs
@@ -1255,6 +1255,19 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// Snaps the input position into the grid.
+ ///
+ /// The position to snap.
+ /// The size of the grid.
+ /// The position snapped to the grid.
+ public static Double2 SnapToGrid(Double2 pos, Double2 gridSize)
+ {
+ pos.X = Mathd.Ceil((pos.X - (gridSize.X * 0.5)) / gridSize.Y) * gridSize.X;
+ pos.Y = Mathd.Ceil((pos.Y - (gridSize.Y * 0.5)) / gridSize.X) * gridSize.Y;
+ return pos;
+ }
+
///
/// Adds two vectors.
///
diff --git a/Source/Engine/Core/Math/Double3.cs b/Source/Engine/Core/Math/Double3.cs
index ca5eb9cbd..ccb30d699 100644
--- a/Source/Engine/Core/Math/Double3.cs
+++ b/Source/Engine/Core/Math/Double3.cs
@@ -1536,6 +1536,20 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// Snaps the input position into the grid.
+ ///
+ /// The position to snap.
+ /// The size of the grid.
+ /// The position snapped to the grid.
+ public static Double3 SnapToGrid(Double3 pos, Double3 gridSize)
+ {
+ pos.X = Mathd.Ceil((pos.X - (gridSize.X * 0.5)) / gridSize.X) * gridSize.X;
+ pos.Y = Mathd.Ceil((pos.Y - (gridSize.Y * 0.5)) / gridSize.Y) * gridSize.Y;
+ pos.Z = Mathd.Ceil((pos.Z - (gridSize.Z * 0.5)) / gridSize.Z) * gridSize.Z;
+ return pos;
+ }
+
///
/// Adds two vectors.
///
diff --git a/Source/Engine/Core/Math/Float2.cs b/Source/Engine/Core/Math/Float2.cs
index 3ca6f51d7..ccf8384c8 100644
--- a/Source/Engine/Core/Math/Float2.cs
+++ b/Source/Engine/Core/Math/Float2.cs
@@ -1273,6 +1273,19 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// Snaps the input position into the grid.
+ ///
+ /// The position to snap.
+ /// The size of the grid.
+ /// The position snapped to the grid.
+ public static Float2 SnapToGrid(Float2 pos, Float2 gridSize)
+ {
+ pos.X = Mathf.Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.Y) * gridSize.X;
+ pos.Y = Mathf.Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.X) * gridSize.Y;
+ return pos;
+ }
+
///
/// Adds two vectors.
///
diff --git a/Source/Engine/Core/Math/Float3.cs b/Source/Engine/Core/Math/Float3.cs
index 3ea95f0d7..9ee2bbea9 100644
--- a/Source/Engine/Core/Math/Float3.cs
+++ b/Source/Engine/Core/Math/Float3.cs
@@ -1520,6 +1520,20 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// Snaps the input position into the grid.
+ ///
+ /// The position to snap.
+ /// The size of the grid.
+ /// The position snapped to the grid.
+ 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;
+ }
+
///
/// Adds two vectors.
///
diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs
index 568c51764..f8e0b6c32 100644
--- a/Source/Engine/Core/Math/Vector2.cs
+++ b/Source/Engine/Core/Math/Vector2.cs
@@ -1381,6 +1381,19 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// Snaps the input position into the grid.
+ ///
+ /// The position to snap.
+ /// The size of the grid.
+ /// The position snapped to the grid.
+ public static Vector2 SnapToGrid(Vector2 pos, Vector2 gridSize)
+ {
+ pos.X = Mathr.Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.Y) * gridSize.X;
+ pos.Y = Mathr.Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.X) * gridSize.Y;
+ return pos;
+ }
+
///
/// Adds two vectors.
///
diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs
index 280093619..554631849 100644
--- a/Source/Engine/Core/Math/Vector3.cs
+++ b/Source/Engine/Core/Math/Vector3.cs
@@ -1671,6 +1671,20 @@ namespace FlaxEngine
return result;
}
+ ///
+ /// Snaps the input position into the grid.
+ ///
+ /// The position to snap.
+ /// The size of the grid.
+ /// The position snapped to the grid.
+ public static Vector3 SnapToGrid(Vector3 pos, Vector3 gridSize)
+ {
+ pos.X = Mathr.Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X;
+ pos.Y = Mathr.Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y;
+ pos.Z = Mathr.Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z;
+ return pos;
+ }
+
///
/// Adds two vectors.
///