Jump to content
  • Advertisement
Sign in to follow this  
moleary

Frustum Calculations

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I determine the plane equations for the frustum created from the current camera position, direction vector, and my given field of view? Thanks for the help!

Share this post


Link to post
Share on other sites
Advertisement
You might start here. Or, you can construct the planes in camera space using trig and then transform them into world space.

Keep in mind that you'll also need a reference vector for your orientation (it's not uniquely defined by a position and direction), and an aspect ratio.

Share this post


Link to post
Share on other sites
Quote:
http://www2.ravensoft.com/users/ggribb/plane%20extraction.pdf
Just to save the OP some time, that's the same paper that I linked to in my post.

Share this post


Link to post
Share on other sites
I am writing a portal renderer which is why I need this info. I am a newbie in this, so if someone could fill in some blanks, it would be helpful.

I was just imagining that I could compute the frustum plane equations from an arbitrary position, view vector, up vector, field of view, and aspect ratio. But the posted article seems to imply that it must be done through the projection matrix. So, I gather to compute an arbitrary frustum, I must use the modelview matrix to move to the arbitrary location and set up the view and up vectors?

Another thing, what is the difference between glFrustum and gluPerspective? gluPersepective specifies an aspect ratio but one isn't specified with glFrustum. Is it somehow determined with the values passed to glFrustum?

Thanks to everyone who helped out!

Share this post


Link to post
Share on other sites
Thinking about this some more, I think there are really two things I need to know how to do for a portal renderer. Anyone correct me if I'm wrong here. Please.

1) I need to compute the frustum for the camera location. This will require the projection matrix.

2) I need to know how to determine the plane equations for a frustum given a start point and a quad. I don't think the projection matrix needs to come into play for this. More generally, I need to know how to compute a plane equation given 3 points.

Thanks again!

Share this post


Link to post
Share on other sites
Quote:
Another thing, what is the difference between glFrustum and gluPerspective? gluPersepective specifies an aspect ratio but one isn't specified with glFrustum. Is it somehow determined with the values passed to glFrustum?
glFrustum() takes six arguments: the distance to the near and far planes, and the left, right, bottom, and top coordinates of the viewing window at the near plane.

Note that left can be different from -right and bottom can be different from -top. This means that the frustum (although still a perspective projection) can be skewed off center if desired. Note that the aspect ratio is implicit in the function arguments.

gluPerspective() is a utility function that wraps glFrustum(). It takes a vertical field of view, an aspect ratio, and the near and far plane distances, converts the arguments to l,r,b,t,n,f form, and calls glFrustum(). Well, I don't actually know if it calls glFrustum() or computes the matrix in place, but in any case it does the same thing as glFrustum(), except that the frustum cannot be off-axis; it is always symmetrical across the xz and yz planes.

I'm at work now, but if no one's helped you with your other questions later I'll try to provide some more info.

Share this post


Link to post
Share on other sites
Home for lunch, so I'll try to provide a little more info.
Quote:
I was just imagining that I could compute the frustum plane equations from an arbitrary position, view vector, up vector, field of view, and aspect ratio. But the posted article seems to imply that it must be done through the projection matrix. So, I gather to compute an arbitrary frustum, I must use the modelview matrix to move to the arbitrary location and set up the view and up vectors?
You can do it either way. An advantage of doing it through the gl matrix is that you have a uniform way of extracting the planes, regardless of what sort of projection you've set up (off-center or whatever).

However, unless you're constructing these matrices yourself and submitting them to OpenGL, the matrix extraction method requires querying the OpenGL matrices, which isn't always desirable.

As an alternative, you can construct it yourself from the information you listed - position, view, up, fov, and aspect. There are a few things you need to know, such as how to express fov as a zoom factor and/or how to convert between horizontal and vertical fov. If you then draw a top-down or side-on view of the frustum, it will probably start to become clear how to compute the plane normals using trig. It's probably easiest to compute the planes in camera space based on fov, aspect, near and far, and then transform to world space using position, view, and up. Don't forget to account for OpenGL's -z forward if necessary.
Quote:
I need to know how to determine the plane equations for a frustum given a start point and a quad. I don't think the projection matrix needs to come into play for this. More generally, I need to know how to compute a plane equation given 3 points.
This is another way to approach the problem. The near plane corners in camera space are [l,b,n], [r,b,n], [r,t,n], and [l,t,n]. Transform these by the camera coordinate system to find the corners of the quad you mention. Then create the planes using the camera position and the quad corners. Google 'plane from points' if you're not sure how to do that.

'Hope some of this will be helpful to you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!