Frustum corner point calculation

Started by
4 comments, last by Trienco 13 years ago
I know there has to be a relatively easy way to do this, but my maths are escaping me presently and Google is surprisingly sparse: I want to render an outline of a camera's frustum. I have camera position, orientation, FOV, near plane, and far plane. How do I find the eight points specifying the frustum? Cheers, --Brian
Advertisement
Quote:Original post by Nairb
I know there has to be a relatively easy way to do this, but my maths are escaping me presently and Google is surprisingly sparse:

I want to render an outline of a camera's frustum. I have camera position, orientation, FOV, near plane, and far plane. How do I find the eight points specifying the frustum?

Cheers,
--Brian
There are a couple of ways to do this:

1. If you have the frustum planes available (which you probably do if you're doing frustum culling), simply intersect the frustum planes in sets of three to yield the frustum corners.

2. Although I haven't tried this method, I think you can also apply an inverse transform to the corners of the frustum as expressed in NDC space to yield the corners in world space.

3. Another option is to just compute the corners directly using some trig and vector algebra.

I generally use method 1.
I generally use method 2. Personally, I use it for constructing a ray based on the mouse pos on the screen (by back-projecting two points with different z value).
This tutorial will show you how to calculate the frustum corners in view-space using the parameters you've specified. Once you've done that, you just need to transform all 8 corners by the world matrix of the camera (inverse of the view matrix) and you'll get the world-space coordinates.
If the matrix is invertable (non-orthographic), you can transform the 8 vertices making up the unit cube by this matrix to get their positions. The 'extract the planes' method is faster and more accurate, but more work to implement.
http://www.gearboxsoftware.com/
It's probably the result of how my camera class is working (storing it's transformation matrix just like any other game object and knowing it's width and height at z=1 to do frustum culling). In other words: no planes required. In more other words: it only works for a symmetrical view frustum. Some bits and pieces...


//Called "Fac" because it's the factor to multiply with a given z to get the frustum width and height for that distance
yFac = tanf(FoV * PI/360.0f);
xFac = yFac*aspectRatio;

Vector3 Forward, Right, Up; //Simply the three columns from your transformation matrix (or the inverse of your view matrix)

Vector3 farLeftTop = Position + Forward*far - far*Right*xFac*far + Up*yFac*far;
Vector3 farRightTop = Position + Forward*far + far*Right*xFac*far + Up*yFac*far;
Vector3 farLeftBottom = Position + Forward*far - far*Right*xFac*far - Up*yFac*far;
Vector3 farLeftBottom = Position + Forward*far + far*Right*xFac*far - Up*yFac*far;
// and so on for the near plane
}


I uploaded the entire thing for more context: http://festini.devic...o.de/camera.zip

But: it's OpenGL (same principles apply for D3D), it's old and messy and I don't know how much functionality I broke when changing it back to a right handed coordinate system (I generally prefer left handed with positive z being into the screen... a positive number pointing "backwards" just feels wrong).
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement