diff --git a/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs b/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs index 6b52e8f58..7837ce634 100644 --- a/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs @@ -237,6 +237,13 @@ namespace MatterHackers.MatterControl.DesignTools var transform = Matrix4X4.CreateScale(distBetweenPixelsWorldSpace) * world.RotationMatrix.Inverted * Matrix4X4.CreateTranslation(start); var theme = ApplicationController.Instance.MenuTheme; graphics2DOpenGL.RenderTransformedPath(transform, new Ellipse(0, 0, 5, 5), theme.PrimaryAccentColor, false); + + var hitPlane = tracedPositionControl?.HitPlane; + if (hitPlane != null) + { + world.RenderPlane(hitPlane.Plane, Color.Red, true, 30, 3); + //world.RenderPlane(initialHitPosition, hitPlane.Plane.Normal, Color.Red, true, 30, 3); + } } private void CreateWidgetIfRequired(Object3DControlsLayer controlLayer) @@ -283,8 +290,10 @@ namespace MatterHackers.MatterControl.DesignTools if (tracedPositionControl != null && !tracedPositionControl.DownOnControl) { + tracedPositionControl.ResetHitPlane(); mouseDownPosition = Position; - widgetDownPosition = e.Position; + var widget = (GuiWidget)sender; + widgetDownPosition = widget.TransformToScreenSpace(e.Position); mouseDownOnWidget = true; } } @@ -294,9 +303,14 @@ namespace MatterHackers.MatterControl.DesignTools if (mouseDownOnWidget) { var screenStart = controlLayer.World.GetScreenPosition(mouseDownPosition); - var delta = e.Position - widgetDownPosition; - tracedPositionControl.MoveToScreenPosition(screenStart + delta); - widgetDownPosition = e.Position; + var widget = (GuiWidget)sender; + var ePosition = widget.TransformToScreenSpace(e.Position); + var delta = ePosition - widgetDownPosition; + if (delta.LengthSquared > 0) + { + tracedPositionControl.MoveToScreenPosition(screenStart + delta); + // widgetDownPosition = ePosition; + } } } diff --git a/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs b/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs index 76e472538..72d5ad873 100644 --- a/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs +++ b/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs @@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.DesignTools private Mesh shape; private bool mouseOver; - private PlaneShape hitPlane; + public PlaneShape HitPlane { get; private set; } public bool DownOnControl { get; private set; } public TracedPositionObject3DControl(IObject3DControlContext object3DControlContext, @@ -104,7 +104,7 @@ namespace MatterHackers.MatterControl.DesignTools GLHelper.Render(shape, color.WithAlpha(e.Alpha0to255), ShapeMatrix(), RenderTypes.Shaded); - if (hitPlane != null) + if (HitPlane != null) { //Object3DControlContext.World.RenderPlane(hitPlane.Plane, Color.Red, true, 30, 3); //Object3DControlContext.World.RenderPlane(initialHitPosition, hitPlane.Plane.Normal, Color.Red, true, 30, 3); @@ -130,6 +130,13 @@ namespace MatterHackers.MatterControl.DesignTools public void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { DownOnControl = true; + // Make sure we always get a new hit plane + ResetHitPlane(); + } + + public void ResetHitPlane() + { + HitPlane = null; } public void OnMouseMove(Mouse3DEventArgs mouseEvent3D, bool mouseIsOver) @@ -158,12 +165,12 @@ namespace MatterHackers.MatterControl.DesignTools var rayNormal = (oldPosition - world.EyePosition).GetNormal(); if (intersectionInfo == null) { - if (hitPlane == null) + if (HitPlane == null) { - hitPlane = new PlaneShape(new Plane(rayNormal, oldPosition), null); + HitPlane = new PlaneShape(new Plane(rayNormal, oldPosition), null); } - intersectionInfo = hitPlane.GetClosestIntersection(ray); + intersectionInfo = HitPlane.GetClosestIntersection(ray); if (intersectionInfo != null) { newPosition = intersectionInfo.HitPosition; @@ -171,7 +178,7 @@ namespace MatterHackers.MatterControl.DesignTools } else { - hitPlane = new PlaneShape(new Plane(rayNormal, oldPosition), null); + HitPlane = new PlaneShape(new Plane(rayNormal, oldPosition), null); foreach (var object3D in scene.Children) {