Frustum corner point calculation

This topic is 2810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
Quote:
 Original post by NairbI 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.

Share on other sites
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).

Share on other sites
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.

Share on other sites
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.

Share on other sites
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).

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633744
• Total Posts
3013653
×