diff --git a/objects/Grid.cs b/objects/Grid.cs index 55e4184..40e25a9 100644 --- a/objects/Grid.cs +++ b/objects/Grid.cs @@ -72,21 +72,20 @@ public partial class Grid : Area3D /// public Transform3D Snap(Transform3D transform, Vector3 normal, Item item) { - var inverseTransform = GlobalTransform.AffineInverse(); - var inverseBasis = GlobalBasis.Inverse(); - var halfSize = (Vector3)item.Size * StepSize / 2; + var halfSize = (Vector3)item.Size * StepSize / 2; // Get grid-local values of the global transform and normal. - var pos = inverseTransform * transform.Origin; - var basis = inverseBasis * transform.Basis; - normal = inverseBasis * normal; + var inverse = GlobalTransform.AffineInverse(); + var pos = inverse * transform.Origin; + var basis = inverse.Basis * transform.Basis; + normal = inverse.Basis * normal; // Snap rotation to nearest axis. basis = Basis.FromEuler(basis.GetEuler().Snapped(Tau / 4)); // Offset / "push out" by half of the item's size. - var offsetAxis = (int)(normal * basis).Abs().MaxAxisIndex(); - pos += halfSize[offsetAxis] * normal; + var axis = (normal * basis).Abs().MaxAxisIndex(); + pos += halfSize[(int)axis] * normal; // Snap the position to the grid. var halfOff = basis * halfSize.PosMod(1.0f);