[vtkusers] Dragging an object in the x-y plane

Dov Grobgeld dov.grobgeld at gmail.com
Tue Apr 8 16:48:37 EDT 2014


Thanks David,

I got it to work perfectly as long as I'm looking at the scene from the
top. But when i rotate the scene, e.g. tilt it forward around the x-axis,
then the dragging of the pieces lags behind the mouse. Geometrically I
somehow understand why, as I'm constraining to only move the piece in the
x-y plane and the Display2World transformation is also returning a
z-component that I'm ignoring. Is there a shortcut in vtk to do the
necessary z to x,y projections, or should i just figure it out on my own?
Again, my requirement is that the mouse should stay around the same
position on the piece, as I'm moving it around.

Regards,
Dov



On Tue, Apr 8, 2014 at 11:19 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi Dov,
>
> I use a function like this:
>
> void DisplayToWorld(vtkRenderer *renderer,
>   double x, double y, double z, // window coordinates (the input)
>   double world[3]) // world coordinates (the output)
> {
>   // Use the vtkViewport interterface for conversions.
>   renderer->SetDisplayPoint(x, y, z);
>   renderer->DisplayToWorld();
>   double hcoord[4];
>   renderer->GetWorldPoint(hcoord);
>   world[0] = hcoord[0]/hcoord[3];
>   world[1] = hcoord[1]/hcoord[3];
>   world[2] = hcoord[2]/hcoord[3];
> }
>
> It is not enough to have just the xy window coordinates.  You also
> need a z window coordinate, which is a depth value in the range [0,1].
> Usually you get the depth from the pick.
>
>   David
>
>
> On Tue, Apr 8, 2014 at 2:03 PM, Dov Grobgeld <dov.grobgeld at gmail.com>
> wrote:
> > I'm trying to create a toy x-y board which has pieces, realized as
> Actors,
> > that I can drag around in the x-y plane. Through the vtkPicker() I have
> > figured out how to choose a piece, and I can get the render window
> > coordinates through GetInteractor().GetEventPosition(). Further, if I now
> > move the mouse I can calculate a Dx,Dy shift in the window coordinate.
> But I
> > would now like to translate the Window Dx,Dy to an Actor Dx,Dy shift.
> I.e. I
> > would like to take a two pairs of xy coordinates in window coordinates
> and
> > calculate their respective positions in actor coordinates, according to
> the
> > current actor to dispay matrix. How can I do that?
> >
> > Thanks in advance!
> > Dov
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140408/ee7f97cb/attachment.html>


More information about the vtkusers mailing list