Sign in to follow this  
SteveYin

how to caculate the frustum's value?

Recommended Posts

Currently I'm trying to intergrate two different sdk, in sdk a, it use fov/near/far/aspect to describ the camera's projection( of course, internal use matrix), but in sdk b, it use frustrum ( left/right/top/bottom/near/far in float) to describe the camera.

How can I calcluate the value of frustrum, ( left/right/top/bottom) from sdk a's property?

I'm not a master of math, so don't tell me to calculate the frustum from it's projection matrix..... :(

Share this post


Link to post
Share on other sites
Here's the corresponding code from the CML:
float height = 2.f * std::tan(yfov * .5f) * near;
matrix_perspective(m, height * aspect, height, near, far);
I cleaned it up a little to make it more clear, but I don't think I messed anything up in the process, so it should be right.

Note that that's for vertical field of view. The code for horizontal field of view would be:
float width = 2.f * std::tan(xfov * .5f) * near;
matrix_perspective(m, width, width / aspect, near, far);

Share this post


Link to post
Share on other sites
well, first of all , thank you.

But, I don't need to calculate the projection matrix, I need to calculate the six number of frustum, the left, right, top, bottom, these four value's, either from projection matrix or from fov, aspect...

Share this post


Link to post
Share on other sites
Quote:
But, I don't need to calculate the projection matrix, I need to calculate the six number of frustum, the left, right, top, bottom, these four value's, either from projection matrix or from fov, aspect...
The code I posted shows how to compute the width and height of the view frustum at the near plane based on the aspect ratio and field of view, but you can easily compute the parameters you need from the width and height as follows:
float halfWidth = width / 2;
float halfHeight = height / 2;
float left = -halfWidth;
float right = halfWidth;
float bottom = -halfHeight;
float top = halfHeight;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this