This sample uses a hidden custom ObjectManipulator to move the entities.
After selecting an entity by clicking the mouse, you can start dragging of the selected entity within the view.
Upon clicking the viewport again, the transformation is applied to the entities.
using devDept.Eyeshot;
using devDept.Eyeshot.Control;
using devDept.Geometry;
class MyOM : ObjectManipulator
{
public MyOM(ObjectManipulator another) : base(another.Size, another.Visible, another.ShowOriginalWhileEditing, another.Ball, another.TranslateX,
another.TranslateY, another.TranslateZ, another.RotateX, another.RotateY, another.RotateZ, another.RotationStep, another.TranslationStep)
{
ShowTransformationLabel = false;
}
private bool first = true;
public void EnableDragging(bool enable, Viewport viewport, MouseEventArgs e)
{
if (enable)
{
Enable(new Identity(), true);
PickedEntity = Entities[0];
}
else
{
PickedEntity = null;
}
OnMouseDown(e, viewport);
first = true;
}
protected override bool OnMouseUp(System.Windows.Forms.MouseEventArgs e, Viewport viewport)
{
var res = base.OnMouseUp(e, viewport);
Dragging = true;
return res;
}
protected override bool OnDrag(ref System.Drawing.Point lastPoint, System.Drawing.Point curPoint, Viewport viewport)
{
if (first)
lastPoint = curPoint;
first = false;
return base.OnDrag(ref lastPoint, curPoint, viewport);
}
public override void Draw(RenderParams data)
{
//base.Draw(data);
}
}
public Form1()
{
InitializeComponent();
...
design1.Click += Design1_Click;
}
private bool dragging = false;
private int entityIndex = -1;
private void Design1_Click(object sender, EventArgs e)
{
if (design1.ActionMode != actionType.None)
return;
if (dragging)
{
design1.ObjectManipulator.Apply();
design1.Entities.Regen();
design1.Entities[entityIndex].Selected = false;
}
else
{
MouseEventArgs me = (MouseEventArgs) e;
entityIndex = design1.GetEntityUnderMouseCursor(me.Location);
if (entityIndex < 0)
return;
design1.Entities[entityIndex].Selected = true;
((MyOM)design1.ObjectManipulator).EnableDragging(true, design1.Viewports[0], me);
}
design1.Invalidate();
dragging = !dragging;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
design1.Entities.Add(Mesh.CreateSphere(10, 10, 10));
design1.ObjectManipulator = new MyOM(design1.ObjectManipulator);
design1.ObjectManipulator.ShowOriginalWhileEditing = false;
design1.CompileUserInterfaceElements();
design1.ZoomFit();
design1.ZoomOut(120);
design1.Invalidate();
}
Comments
Thank you for this example.
Is it possible to force the dragging only along one direction ? For example along a Vector3D direction. With this example the dragging is free while instead my goal is to be able to drag it only along a direction.
Thank you.
Keven Corazza
I'm using this hidden object manipulator in my project and have set ShowTransformationLabel to false. But sometimes I can see a label appearing in the viewport and even after the object manipulator is disabled (by calling Cancel()), this label remains visible. What could be the reason? I'm using version 2023.3.630.0
@Keven. In order to restrict movement along a fixed direction you can do the following. Instead of choosing PickedEntity = Entities[0]; do PickedEntity = Entities[1]; Entities[1] is object manipulator's X direction arrow, by doing so you can restrict movement along X direction. If you want a different direction (assuming in XY plane), then find the angle between Vector3D XAxis and your Vector3D. Prepare a rotation transformation and pass it as initial transformation in Enable(Transformation initialTransform, bool centerOnEntities, IList<Entity> entities). Now drag will happen only along your Vector3D. I guess Entities[3] is Y direction and Entities[5] is Z direction. You may choose PickedEntity as per your use case. Hope you got the point.
Please sign in to leave a comment.