Which coordinates do I have to pass to gluUnProject to retrieve the frustum corners as world space coordinates? Whatever I tried doesn’t seem to work:
void CFrustum::Compute (void)
{
static CFloatVector corners [8] = {
#if 0
{{0.0, 0.0, 0.0}}, {{0.0, 1.0, 0.0}}, {{1.0, 1.0, 0.0}}, {{1.0, 0.0, 0.0}},
{{0.0, 0.0, 1.0}}, {{0.0, 1.0, 1.0}}, {{1.0, 1.0, 1.0}}, {{1.0, 0.0, 1.0}}
#else
{{-1.0f, -1.0f, 0.0}}, {{-1.0f, 1.0f, 0.0}}, {{1.0f, 1.0f, 0.0}}, {{1.0f, -1.0f, 0.0}},
{{-1.0f, -1.0f, 1.0}}, {{-1.0f, 1.0f, 1.0}}, {{1.0f, 1.0f, 1.0}}, {{1.0f, -1.0f, 1.0}},
#endif
};
transformation.SystemMatrix (-1).Get (GL_MODELVIEW_MATRIX, false);
transformation.SystemMatrix (-2).Get (GL_PROJECTION_MATRIX, false);
GLint viewport [4];
glGetIntegerv (GL_VIEWPORT, viewport);
for (int i = 0; i < 8; i++) {
GLdouble x, y, z;
gluUnProject (corners [i].v.coord.x, corners [i].v.coord.y, corners [i].v.coord.z,
&transformation.SystemMatrix (-1) [0],
&transformation.SystemMatrix (-2) [0],
viewport,
&x, &y, &z);
// ...
}
The modelview matrix is the identity matrix.