From 7ffdbcbba8aa45d7ea19facdf660f07bcd221365 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Fri, 12 Dec 2014 07:34:25 -0800 Subject: [PATCH] Put in a z height snap grid of 1. Will make a menu in the future. --- PartPreviewWindow/View3D/Gui3D/UpArrow3D.cs | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/PartPreviewWindow/View3D/Gui3D/UpArrow3D.cs b/PartPreviewWindow/View3D/Gui3D/UpArrow3D.cs index 6495a9038..25e233a83 100644 --- a/PartPreviewWindow/View3D/Gui3D/UpArrow3D.cs +++ b/PartPreviewWindow/View3D/Gui3D/UpArrow3D.cs @@ -89,15 +89,26 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Vector3 delta = new Vector3(0, 0, info.hitPosition.z - zHitHeight); // move it back to where it started - Matrix4X4 totalTransfrom = Matrix4X4.CreateTranslation(new Vector3(-lastMoveDelta)); - // and move it from there to where we are now - totalTransfrom *= Matrix4X4.CreateTranslation(new Vector3(delta)); - lastMoveDelta = delta; - ScaleRotateTranslate translated = MeshViewerToDrawWith.SelectedMeshGroupTransform; - translated.translation *= totalTransfrom; + translated.translation *= Matrix4X4.CreateTranslation(new Vector3(-lastMoveDelta));; MeshViewerToDrawWith.SelectedMeshGroupTransform = translated; + // now snap this position to the grid + { + double snapGridDistance = MeshViewerToDrawWith.SnapGridDistance; + AxisAlignedBoundingBox selectedBounds = GetBoundsForSelection(); + double bottom = selectedBounds.minXYZ.z + delta.z; + + double snappedBottom = ((int)((bottom / snapGridDistance) + .5)) * snapGridDistance; + delta.z = snappedBottom - selectedBounds.minXYZ.z; + } + + // and move it from there to where we are now + translated.translation *= Matrix4X4.CreateTranslation(new Vector3(delta)); + MeshViewerToDrawWith.SelectedMeshGroupTransform = translated; + + lastMoveDelta = delta; + Invalidate(); }