draw a cube with mouse in helix3D

Anonymous 9 years ago updated by Kumaran M 8 years ago 1
This discussion was imported from CodePlex

Elementu wrote at 2012-01-17 10:24:

Hello ,

I am using the Helix 3d toolkit to develop my solution.

What I need and have not yet managed to develop properly is the drawing of a cube, or for that matter any other figure, with the mouse.

So when I press the left click I need the cube to begin drawing , as I keep dragging the mouse the cube should increase in size until I release the mouse button. at which moment the drawing should stop and the cube should be completed.

Unfortunately when drawing the cube i use the "HelixToolkit.Wpf.CubeVisual3D" which only has the center property and the size(width, height, depth) properties. so I am having problems drawing like any 3d program would , that is when when starting the drawing one corner should be fixed and the other points should mode until the drawing is complete. I thought of making the cube out of lines but that only applies to the cube and I also need to draw cylinders polygons   and others.

One more problem I am facing is that I assigned the rotation of the camera to the left click instead of the right click as it is usually. So that works for me only that when I select a figure to draw the left click should be used to draw and not to rotate the camera anymore until the selected button with the figure to draw is deselected then the left click is assigned back tot the rotation function.

Can anyone please point me in a right direction in order to solve this problems?

Thanks in advance.

objo wrote at 2012-01-17 11:33:

CubeVisual3D: right, you have to change the center point when you want to keep one corner (P1) fixed:

Center = P1 + new Vector3D(1,1,1) * SideLength * 0.5;

Rotate/draw modes: Can you set the RotateGesture to a MouseGesture(MouseAction.None) while you are in the draw mode?

I will add a box-drawing example when I get time :)

elementu wrote at 2012-01-17 12:36:

Thank you for your quick reply, i have tried to move the center instead of keeping it fixed but whatever I tried failed because the cube was still growing in both directions so i did not get the fixed corner I was hopping . I will try this too.

Another thing is that I get the mouse position like this HelixViewport.CurrentPosition to get a Point3D object in order to check how much the position of the mouse has changed . But if I cross an object that I already have loaded in the viewport the coordinates I get from the "CurrentPosition" property are very different and I barely move the mouse this is most visible when I have the grid lines loaded and i pas over the lines. What could be the nature of this problem ?

I will try to set the gesture to MouseAction.None when in draw mode. Actually I have thought of doing this before but wanted to modify as little as I could in the Helix code so that I don't have conflicts in other parts of the toolkit. So i tried to catch the mouse down event outside but the handler I was using was not getting triggered. the mouse up and move events were triggered i user it like this :


@elementu, please try the following code

double l,w,h;
double xGap, yGap;
double xOffsetIncrement, yOffsetIncrement;

xGap= mouseSelectionEndPoint.X - mouseSelectionStartPoint.X;
yGap = mouseSelectionEndPoint.Y - mouseSelectionStartPoint.Y;

l = Math.Abs(xGap);
w = Math.Abs(yGap);
h = 25;

xOffsetIncrement = l / 2;
yOffsetIncrement = w / 2;

if (xGap<0)
xOffsetIncrement *= -1;

if (yGap<0)
yOffsetIncrement *= -1;

TranslateTransform3D trans = new TranslateTransform3D();
trans.OffsetX = mouseSelectionStartPoint.X + xOffsetIncrement;
trans.OffsetY = mouseSelectionStartPoint.Y + yOffsetIncrement;
trans.OffsetZ = 12;

VolumeSelectionCube.Width = w;
VolumeSelectionCube.Length = l;
VolumeSelectionCube.Height = h;
VolumeSelectionCube.Transform = trans;

VolumeSelectionCube is 'BoxVisual3D' object
<h:BoxVisual3D x:Name="VolumeSelectionCube"/>

also you have to assign "mouseSelectionEndPoint" and "mouseSelectionStartPoint" from mouse down/up events.

I am using this and working perfectly...