0

Simplest way to draw a new RectangularVisual3d

Anonymous 10 years ago 0
This discussion was imported from CodePlex

ronnyek wrote at 2012-05-10 17:07:

I am looking at creating a plane that when in the overhead view, I'd like to be able to draw a rectangle to represent selection. (like what you might see when lasso'ing a bunch of icons in windows.

I'm struggling to find out a way to draw a rectanglularvisual... and was hoping perhaps someone can point me in the correct direction.

I've got the mouse down/move/up events setting upper left and lower right of a rectangle, but seeing as rectangularvisual 3d uses origin etc, I cant just plug those values in. 

 

ondown, check mouse buttons, findnearestpoint set variable to that if there is a value

onmove, if dragging, create rectangular visual if not null, and then set its origin to x-x/2 and y-y/2. (z dimension shouldnt really matter in this case.

 

Is there an easier way to do this? (I couldnt get this to work anyway)


objo wrote at 2012-05-10 22:07:

yes, the RectangleVisual3D is defined by Origin, Width and Length.

If you want to draw a rectangle aligned with the X and Y axes in the z=0 plane, e.g. from P1=Point3D(x1,y1,0) to P2=Point3D(x2,y2,0), you could set

Normal = new Vector3D(0,0,1)
LengthDirection = new Vector3D(1,0,0)
Origin = P1+(P2-P1)*0.5
Length = Math.Abs(P2.X-P1.X)
Width = Math.Abs(P2.Y-P1.Y)

CornelRo wrote at 2012-11-07 09:03:

Thanks for the code above, I am also trying to make a selection box by creating a RectangleVisual3D to always face the camera regardless of the camera position. With the above code I made this possible, but only if the camera is in the standard views(F,B,L,R,U,D).

Does anybody know how to calculate the Normal & LengthDirection of the RectangleVisual3D depending on the Camera settings?


objo wrote at 2012-11-07 09:20:

see Source\HelixToolkit.Wpf\Visual3Ds\ScreenSpaceVisuals\BillboardVisual3D.cs