1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| int UnProject(GLint x, GLint y, dpoint3d *pos3d)
{
GLfloat prof;
GLdouble ModelView_Matrix[16], Projection_Matrix[16];
GLint Viewport_Matrix[4];
int status;
/* On récupe l'information de profondeur */
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &prof);
if (prof == 1.0)
{
/* On a pointe dans le vide */
pos3d->x = 0.0;
pos3d->y = 0.0;
pos3d->z = 0.0;
status = -1;
}
else
{
/* On recupere le reste : les matrices de modele, de projection et le viewport */
glGetDoublev(GL_MODELVIEW_MATRIX, ModelView_Matrix);
glGetDoublev(GL_PROJECTION_MATRIX, Projection_Matrix);
glGetIntegerv(GL_VIEWPORT, Viewport_Matrix);
/* Et enfin les coordonnées 3D qui correspondent */
gluUnProject((GLdouble)x, (GLdouble)y, (GLdouble)prof, ModelView_Matrix,
Projection_Matrix, Viewport_Matrix, &(pos3d->x),&(pos3d->y),&(pos3d->z));
status = 0;
}
return status;
} |
Partager