Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Given a left-handed Projection matrix, a left-handed View matrix, a ViewProj matrix of View * Projection - How do I create a bounding Frustum comprised of near, far, left, right and top, bottom planes?

The only example I could find on Google (Tutorial 16: Frustum Culling) seems to not work; for example, if the math is used as given, the near-plane's distance is a negative. This places the near-plane behind the camera...

share|improve this question
    
I took a look at how it's done in XNA (where in this example value corresponds to a ViewProjection matrix) and it seems to be possible to extract all the plane information directly from the matrix. I'm too tired to figure it out at the moment though :P –  David Gouveia Jun 2 '12 at 5:13

1 Answer 1

up vote 7 down vote accepted

The easiest way I know of is to construct the view frustum in post-projective space (so-called NDC space), where the frustum is a cube, then transform it through the inverse view-projection matrix and construct the planes in world space.

The frustum in NDC space runs from -1 to +1 along the x and y axes, and from -1 to +1 on z if you're in OpenGL, or 0 to 1 on z if you're in D3D. Build the eight corners of this cube (setting w = 1), then multiply them by the inverse view-projection matrix, and divide by w to convert back to regular 3D points.

The result should be the frustum corners in world space, and you can then build the planes by using groups of 3 points and the usual formula for calculating a plane equation from 3 points.

This general technique should work with any kind of view-projection matrix - perspective or orthographic, oblique or straight, any FoV or aspect ratio, etc. There are ways to simplify it by making some assumptions about the form of the matrix, but those tend to break if any of the assumptions are changed.

share|improve this answer
    
Projection matrices appear to be non-invertible. –  Narf the Mouse Jun 2 '12 at 4:56
    
Never mind; just tired. –  Narf the Mouse Jun 2 '12 at 5:05
    
@NarftheMouse, the full 4x4 projection matrix should still be invertible. See for instance D3DXMatrixPerspectiveLH‌​; that's perfectly invertible given nonzero values for near, far, etc. –  Nathan Reed Jun 2 '12 at 5:08
    
Yep; just mistook the math due to tiredness. –  Narf the Mouse Jun 2 '12 at 5:14
    
Anyway, up-voted and checked the answer box, as I implemented it today and it works. Was pretty sure it would, but wanted to keep it open in case there was a problem. –  Narf the Mouse Jun 4 '12 at 22:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.