Making the description draggable
This commit is contained in:
parent
c9353b125d
commit
e3da5e84c1
12 changed files with 196 additions and 118 deletions
|
|
@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
private Mesh shape;
|
||||
private bool mouseOver;
|
||||
private PlaneShape hitPlane;
|
||||
private bool downOnControl;
|
||||
public bool DownOnControl { get; private set; }
|
||||
|
||||
public TracedPositionObject3DControl(IObject3DControlContext object3DControlContext,
|
||||
IObject3D owner,
|
||||
|
|
@ -129,8 +129,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public void OnMouseDown(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
hitPlane = new PlaneShape(new Plane(mouseEvent3D.MouseRay.directionNormal, mouseEvent3D.info.HitPosition), null);
|
||||
downOnControl = true;
|
||||
DownOnControl = true;
|
||||
}
|
||||
|
||||
public void OnMouseMove(Mouse3DEventArgs mouseEvent3D, bool mouseIsOver)
|
||||
|
|
@ -141,51 +140,68 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
context.GuiSurface.Invalidate();
|
||||
}
|
||||
|
||||
if (downOnControl)
|
||||
if (DownOnControl)
|
||||
{
|
||||
var ray = context.World.GetRayForLocalBounds(mouseEvent3D.MouseEvent2D.Position);
|
||||
var scene = context.Scene;
|
||||
var intersectionInfo = scene.GetBVHData().GetClosestIntersection(ray);
|
||||
UpdatePosition(mouseEvent3D.MouseEvent2D.Position);
|
||||
}
|
||||
}
|
||||
|
||||
var oldPosition = getPosition();
|
||||
var newPosition = oldPosition;
|
||||
if (intersectionInfo == null)
|
||||
private void UpdatePosition(Vector2 screenPosition)
|
||||
{
|
||||
var ray = context.World.GetRayForLocalBounds(screenPosition);
|
||||
var scene = context.Scene;
|
||||
var intersectionInfo = scene.GetBVHData().GetClosestIntersection(ray);
|
||||
|
||||
var oldPosition = getPosition();
|
||||
var newPosition = oldPosition;
|
||||
var world = Object3DControlContext.World;
|
||||
var rayNormal = (oldPosition - world.EyePosition).GetNormal();
|
||||
if (intersectionInfo == null)
|
||||
{
|
||||
if (hitPlane == null)
|
||||
{
|
||||
intersectionInfo = hitPlane.GetClosestIntersection(ray);
|
||||
if (intersectionInfo != null)
|
||||
hitPlane = new PlaneShape(new Plane(rayNormal, oldPosition), null);
|
||||
}
|
||||
|
||||
intersectionInfo = hitPlane.GetClosestIntersection(ray);
|
||||
if (intersectionInfo != null)
|
||||
{
|
||||
newPosition = intersectionInfo.HitPosition;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hitPlane = new PlaneShape(new Plane(rayNormal, oldPosition), null);
|
||||
|
||||
foreach (var object3D in scene.Children)
|
||||
{
|
||||
if (object3D.GetBVHData().Contains(intersectionInfo.HitPosition))
|
||||
{
|
||||
newPosition = intersectionInfo.HitPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hitPlane = new PlaneShape(new Plane(mouseEvent3D.MouseRay.directionNormal, intersectionInfo.HitPosition), null);
|
||||
}
|
||||
|
||||
foreach (var object3D in scene.Children)
|
||||
{
|
||||
if (object3D.GetBVHData().Contains(intersectionInfo.HitPosition))
|
||||
{
|
||||
newPosition = intersectionInfo.HitPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newPosition != oldPosition)
|
||||
{
|
||||
setPosition(newPosition);
|
||||
context.GuiSurface.Invalidate();
|
||||
}
|
||||
if (newPosition != oldPosition)
|
||||
{
|
||||
setPosition(newPosition);
|
||||
context.GuiSurface.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
downOnControl = false;
|
||||
DownOnControl = false;
|
||||
}
|
||||
|
||||
public void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public void MoveToScreenPosition(Vector2 screenPosition)
|
||||
{
|
||||
UpdatePosition(screenPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue