Re: Drag & Drop

New Message Reply Date view Thread view Subject view Author view

Allan Schaffer (allan++at++southpark.engr.sgi.com)
Wed, 21 Oct 1998 13:33:15 -0700 (PDT)


On Oct 21, 2:31pm, Anda Singer wrote:
> I want to drag and drop an object in my Performer application scene.
> What is the best way to translate the screen (x,y) coordinates to the
> scene (world) coordinates?

Alejandro does a wonderful job of laying out the issues involved
here; an OpenGL routine to help with the calculations is 'gluUnProject()'.

gluUnProject takes screen (sX,sY,sZ) coordinates [yes, there is a Z
component in screen coordinates], the current modelview matrix, the
current projection matrix and viewport, and returns object
coordinates (x,y,z).

So the main question becomes, what should you use as the screen Z
coordinate? If my memory is correct (and you'll want to test this
first to be sure), the Z coord is normalized with (-1,+1)
representing the near & far clip planes. You could call gluUnProject
using both (-1,+1) to get the endpoints of a line segment, and (if a
variant of picking is what you are implementing) do an intersection
test using that segment.

As for IRIS GL, there was a routine called 'mapw()' which did the
same thing, or this very clever hack:
   cmov2(sX,sY);
   getcpos(&oX,&oY,&oZ);

This technique gave results assuming sZ=0.

gluUnProject is fairly slow, so it should only be used in
"user-interface" situations.

Allan

-- 
Allan Schaffer                                                allan++at++sgi.com
Silicon Graphics                               http://reality.sgi.com/allan

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Wed Oct 21 1998 - 13:33:19 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.