Use custom hidden ObjectManipulator to move entities

This sample uses a hidden custom ObjectManipulator to move the entities.
After the entity is selected with a mouse click, you can start the dragging of the selected entity on view.
When the viewport is clicked again the translation is applied to the entities.

using devDept.Eyeshot;
using devDept.Eyeshot.Entities;
using devDept.Geometry;

class MyOM : ObjectManipulator { public MyOM(ObjectManipulator another) : base(another.Size, another.Visible, another.ShowOriginalWhileEditing, another.Translate, another.TranslateX, another.TranslateY, another.TranslateZ, another.RotateX, another.RotateY, another.RotateZ, another.RotationStep, another.TranslationStep) { } 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(); ...
viewportLayout1.Click += VpOnClick; } private bool dragging = false;
private int entityIndex = -1;
private void VpOnClick(object sender, EventArgs eventArgs) { if (viewportLayout1.ActionMode != actionType.None) return; if (dragging)
{ viewportLayout1.ObjectManipulator.Apply();
viewportLayout1.Entities[entityIndex].Selected = false;
} else {
MouseEventArgs me = (MouseEventArgs) eventArgs;
entityIndex = viewportLayout1.GetEntityUnderMouseCursor(me.Location);
if (entityIndex < 0)
viewportLayout1.Entities[entityIndex].Selected = true;
((MyOM)viewportLayout1.ObjectManipulator).EnableDragging(true, viewportLayout1.Viewports[0], me); }
viewportLayout1.Invalidate(); dragging = !dragging; } protected override void OnLoad(EventArgs e) {
base.OnLoad(e); viewportLayout1.Entities.Add(Mesh.CreateSphere(10, 10, 10)); viewportLayout1.ObjectManipulator = new MyOM(viewportLayout1.ObjectManipulator);
viewportLayout1.ObjectManipulator.ShowOriginalWhileEditing = false; viewportLayout1.CompileUserInterfaceElements();

viewportLayout1.PanUp(200); }

Previous versions of this article: Eyeshot 9

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.