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

David Gobbi david.gobbi at gmail.com
Tue Apr 8 16:19:42 EDT 2014


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


More information about the vtkusers mailing list