rawalpundi

07-16-2010, 06:43 PM

Hello,

I use gluUnProject to get the ray perpendicular to a pixel of the screen :

gluUnProject(x, viewport[3] - y, 0, modelviewMatrix, projectionMatrix, viewport, &x1, &y1, &z1)

gluUnProject(x, viewport[3] - y, 1, modelviewMatrix, projectionMatrix, viewport, &x2, &y2, &z2)

In the render function, I use an ortho projection :

glMatrixMode(GL_PROJECTION)

glLoadIdentity()

glOrtho(-2, 2, -2, 2, -2, 2)

I noticed a strange return of the gluUnProject function when I put a z-translation of the objects in the render function :

glMatrixMode(GL_MODELVIEW)

glLoadIdentity()

glTranslated(0, 0, -1)

=> I get : z1 = 3, z2 = -1

I would have expected the following result : z1 = 2, z2 = -2 because it is the bounding box of the ortho projection.

I get this expected result for x1/x2 and y1/y2 when I put a x- or y-translation.

Any idea why the z-axis seems different ?

Thanks

I use gluUnProject to get the ray perpendicular to a pixel of the screen :

gluUnProject(x, viewport[3] - y, 0, modelviewMatrix, projectionMatrix, viewport, &x1, &y1, &z1)

gluUnProject(x, viewport[3] - y, 1, modelviewMatrix, projectionMatrix, viewport, &x2, &y2, &z2)

In the render function, I use an ortho projection :

glMatrixMode(GL_PROJECTION)

glLoadIdentity()

glOrtho(-2, 2, -2, 2, -2, 2)

I noticed a strange return of the gluUnProject function when I put a z-translation of the objects in the render function :

glMatrixMode(GL_MODELVIEW)

glLoadIdentity()

glTranslated(0, 0, -1)

=> I get : z1 = 3, z2 = -1

I would have expected the following result : z1 = 2, z2 = -2 because it is the bounding box of the ortho projection.

I get this expected result for x1/x2 and y1/y2 when I put a x- or y-translation.

Any idea why the z-axis seems different ?

Thanks