Archived

This topic is now archived and is closed to further replies.

HellRiZZer

gluProject/ glUnProject use examples?

Recommended Posts

Can someone please explain to me clearly how to use gluProject/gluUnProject ? For example, I have a 2x2 grid of vertices, xy dimensions, z into screen, how do I transform mouse screen coord to 3d coord? Thanks.

Share this post


Link to post
Share on other sites
  
GLdouble pos3D_x, pos3D_y, pos3D_z;

// arrays to hold matrix information

GLdouble model_view[16];
glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

GLdouble projection[16];
glGetDoublev(GL_PROJECTION_MATRIX, projection);

GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

// get 3D coordinates based on window coordinates

gluUnProject(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 0.01,
model_view, projection, viewport,
&pos3D_x, &pos3D_y, &pos3D_z);


This code gets the position of the center of the screen and stores it in pos3D_x, y, z.

Share this post


Link to post
Share on other sites