• Advertisement
Sign in to follow this  

gluUnproject

This topic is 3768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need to convert window co ordinate to object co ordinate. Hence I use function gluUnproject. I have a deviation in my result in using the function. Following is the code I used to draw four objects... glColor3f(1, 0, 0); glTranslatef(1,1,0); glutSolidTeapot(0.1); glColor3f(1, 1, 0); glTranslatef(-2,0,0); glutSolidSphere(0.1,10,10); glColor3f(1, 1, 1); glTranslatef(0,-2,0); glutSolidCube(0.1); glColor3f(1, 0, 1); glTranslatef(2,0,0); glutSolidTorus(0.02,0.06,10,10); The objects are drawn and I want the click on them to be detected... So I use the following in the mouse click call back function GLdouble model[16]; GLdouble proj[16]; GLint view[4]; GLdouble x[1],y[1],z[1]; glGetDoublev(GL_MODELVIEW_MATRIX,model); glGetDoublev(GL_PROJECTION_MATRIX,proj); glGetIntegerv(GL_VIEWPORT,view); gluUnProject(xpos,ypos,0,model,proj,view,x,y,z); But the results are not correct .... I get the results as: Teapot click : x:-0.8 y:-0.8 z: 4 Sphere click : x:-1.2 y:0.798 z: 4 Cube click : x:-1.202 y:1.195 z: 4 Torus click : x:-0.799 y:1.18 z: 4 which are originally not their corresponding values as i draw them at TeaPot:1,1,0 Sphere:-1,1,0 Cube:-1,-1,0 Torus:1,-1,0 Am I missing out some thing in Unproject function???????????? Expecting help..........................

Share this post


Link to post
Share on other sites
Advertisement
Q: You're passing in Z=0. Why?
A: Because you don't know what the appropriate Z-value is.

Converting points in screen space to points in world space is not trivial, because a given point in screen space maps to an infinite number of points (along a ray) in world space. More info.

Share this post


Link to post
Share on other sites
Hi

Thanks for the reply...

I have read the link which u have given.

In that they state a method for doing it by generating a picking ray

(which I have done by using the following code:

GLdouble model[16];
GLdouble proj[16];
GLint view[4];
GLdouble x1[1],y1[1],z1[1];
GLdouble x2[1],y2[1],z2[1];

glGetDoublev(GL_MODELVIEW_MATRIX,model);
glGetDoublev(GL_PROJECTION_MATRIX,proj);
glGetIntegerv(GL_VIEWPORT,view);
gluUnProject(xpos,ypos,0,model,proj,view,x1,y1,z1);
gluUnProject(xpos,ypos,1,model,proj,view,x2,y2,z2);

GLdouble x = x2[0]-x1[0];
GLdouble y = y2[0]-y1[0];
GLdouble z = z2[0]-z1[0];
)
and test for the intersections of the ray with the currently displayed objects.

How to do this part
The link suggested is http://reality.sgi.com/bspfaq/
which I could not open....

Kindly help....


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement