• Advertisement
Sign in to follow this  

how to caculate the frustum's value?

This topic is 2689 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement