<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks David. With your help I almost solved the interaction problem. My resulting example creates a board with three pieces on it that may be moved around with the right mouse button. The example may be found here:<br>
<br><a href="https://gist.github.com/dov/10310484">https://gist.github.com/dov/10310484</a><br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">It gives a very intuitive feeling for moving the pieces around on the board no matter how the board is rotated. But there is still a dragging problem at high zoom ins. Then the pieces don't follow the mouse anymore. I'm still at lost why his happens.<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Feel free to add this example to the vtk example programs.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
Regards,<br>Dov<br><br></div><div style id="divCleekiAttrib"></div><div style id="divCleekiAttrib"></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 9, 2014 at 12:36 AM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Dov,<br>
<br>
When you do the Display-to-World, what are you using as the input "Z"<br>
display coordinate? Really, I don't think I understand your situation.<br>
<br>
Generally, if you know that your objects are constrained to move<br>
within a certain plane, you should do the following:<br>
<br>
Let X,Y be the "display" coordinates, in pixel units.<br>
Let Z be the display "depth", with a range of [0,1].<br>
<br>
Convert display coordinate (X, Y, 0.0) to world coordinate (x_near,<br>
y_near, z_near)<br>
Convert display coordinate (X, Y, 1.0) to world coordinate (x_far, y_far, z_far)<br>
<br>
Now "far" and "near" define the two ends of a line segment in world<br>
coordinates.  These are where the view ray intersects the near and far<br>
clipping planes for the vtkCamera.<br>
<br>
At some point along the segment between "near" and "far", the segment<br>
will intersect your constraint plane.  Obviously it does not have to<br>
be a plane, it can be whatever kind of constraint surface you want.<br>
Let's call this intersection point "surface" because it lies on the<br>
constraint surface.<br>
<br>
So now you have three points in world coordinates: near, surface, and<br>
far.  Use Pythagoras to compute:<br>
<br>
Z = (surface - near)/(far - near)<br>
<br>
Now Z is the depth at which the view ray at (X,Y) intersects your<br>
constraint surface.  Of course, maybe you don't need to compute "Z" at<br>
all, maybe you can just leave the surface intersection point in world<br>
coordinates.<br>
<br>
I don't know if VTK has any special functions to do this, but even if<br>
it did, I probably wouldn't use them.  I always write my interaction<br>
code by thinking about how the view ray intersects my world space, and<br>
then by applying a constraint to achieve the desired 2D-to-3D<br>
coordinate conversion (or vice-versa).<br>
<span class="HOEnZb"><font color="#888888"><br>
  David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
<br>
On Tue, Apr 8, 2014 at 2:48 PM, Dov Grobgeld <<a href="mailto:dov.grobgeld@gmail.com">dov.grobgeld@gmail.com</a>> wrote:<br>
> Thanks David,<br>
><br>
> I got it to work perfectly as long as I'm looking at the scene from the top.<br>
> But when i rotate the scene, e.g. tilt it forward around the x-axis, then<br>
> the dragging of the pieces lags behind the mouse. Geometrically I somehow<br>
> understand why, as I'm constraining to only move the piece in the x-y plane<br>
> and the Display2World transformation is also returning a z-component that<br>
> I'm ignoring. Is there a shortcut in vtk to do the necessary z to x,y<br>
> projections, or should i just figure it out on my own? Again, my requirement<br>
> is that the mouse should stay around the same position on the piece, as I'm<br>
> moving it around.<br>
><br>
> Regards,<br>
> Dov<br>
><br>
><br>
><br>
> On Tue, Apr 8, 2014 at 11:19 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>
>><br>
>> Hi Dov,<br>
>><br>
>> I use a function like this:<br>
>><br>
>> void DisplayToWorld(vtkRenderer *renderer,<br>
>>   double x, double y, double z, // window coordinates (the input)<br>
>>   double world[3]) // world coordinates (the output)<br>
>> {<br>
>>   // Use the vtkViewport interterface for conversions.<br>
>>   renderer->SetDisplayPoint(x, y, z);<br>
>>   renderer->DisplayToWorld();<br>
>>   double hcoord[4];<br>
>>   renderer->GetWorldPoint(hcoord);<br>
>>   world[0] = hcoord[0]/hcoord[3];<br>
>>   world[1] = hcoord[1]/hcoord[3];<br>
>>   world[2] = hcoord[2]/hcoord[3];<br>
>> }<br>
>><br>
>> It is not enough to have just the xy window coordinates.  You also<br>
>> need a z window coordinate, which is a depth value in the range [0,1].<br>
>> Usually you get the depth from the pick.<br>
>><br>
>>   David<br>
>><br>
>><br>
>> On Tue, Apr 8, 2014 at 2:03 PM, Dov Grobgeld <<a href="mailto:dov.grobgeld@gmail.com">dov.grobgeld@gmail.com</a>><br>
>> wrote:<br>
>> > I'm trying to create a toy x-y board which has pieces, realized as<br>
>> > Actors,<br>
>> > that I can drag around in the x-y plane. Through the vtkPicker() I have<br>
>> > figured out how to choose a piece, and I can get the render window<br>
>> > coordinates through GetInteractor().GetEventPosition(). Further, if I<br>
>> > now<br>
>> > move the mouse I can calculate a Dx,Dy shift in the window coordinate.<br>
>> > But I<br>
>> > would now like to translate the Window Dx,Dy to an Actor Dx,Dy shift.<br>
>> > I.e. I<br>
>> > would like to take a two pairs of xy coordinates in window coordinates<br>
>> > and<br>
>> > calculate their respective positions in actor coordinates, according to<br>
>> > the<br>
>> > current actor to dispay matrix. How can I do that?<br>
>> ><br>
>> > Thanks in advance!<br>
>> > Dov<br>
><br>
><br>
</div></div></blockquote></div><br></div>