Assumptions: (1) both the modelview and projection matrixes are available in float arrays. Use glGetFloatv on them if not. (2) You have a function that will multiply two matrixes together and store the result in a third (called something like "GL_MultiplyMatrix"). Look on Google for sample code if you don't.
No other changes are needed aside from removing the call to R_SetFrustum and inserting a call to this one somewhere after you call to R_SetupGL.
Code: Select all
void R_ExtractFrustum (void)
{
int i;
float r_mvp_matrix[16];
// get the frustum from the actual matrixes that were used
GL_MultiplyMatrix (r_mvp_matrix, r_world_matrix, r_projection_matrix);
// right
frustum[0].normal[0] = r_mvp_matrix[3] - r_mvp_matrix[0];
frustum[0].normal[1] = r_mvp_matrix[7] - r_mvp_matrix[4];
frustum[0].normal[2] = r_mvp_matrix[11] - r_mvp_matrix[8];
// left
frustum[1].normal[0] = r_mvp_matrix[3] + r_mvp_matrix[0];
frustum[1].normal[1] = r_mvp_matrix[7] + r_mvp_matrix[4];
frustum[1].normal[2] = r_mvp_matrix[11] + r_mvp_matrix[8];
// bottom
frustum[2].normal[0] = r_mvp_matrix[3] + r_mvp_matrix[1];
frustum[2].normal[1] = r_mvp_matrix[7] + r_mvp_matrix[5];
frustum[2].normal[2] = r_mvp_matrix[11] + r_mvp_matrix[9];
// top
frustum[3].normal[0] = r_mvp_matrix[3] - r_mvp_matrix[1];
frustum[3].normal[1] = r_mvp_matrix[7] - r_mvp_matrix[5];
frustum[3].normal[2] = r_mvp_matrix[11] - r_mvp_matrix[9];
for (i = 0; i < 4; i++)
{
VectorNormalize (frustum[i].normal);
frustum[i].type = PLANE_ANYZ;
frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
frustum[i].signbits = SignbitsForPlane (&frustum[i]);
}
}