Jump to content
  • Advertisement
Sign in to follow this  
tomer_sh

frustum math question

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

Hi all! - I do the following with OpenGL: gluPerspective(45.0f,(GLfloat)256.0/(GLfloat)192.0,0.1f,100.0f); - So from that you should know: - My Height Angle is 45 degrees - Screen Width is 256 - screen Height is 192 - Near plane at z = 0.1 - Far plane is at z = 100.0 - my question is: How do I gather all of this data to calculate the frustum's planes? I'm looking for the real calculus equations, and not by extracting data from Projection and ModelView matrices like most tutorials show. - question number 2: Not too long ago I stumbled with this code for Frustum calculation: look at it and please answer, how can I modify it so it will take into consideration the Height angle of FOV of my choise, so it will have compatiability with openGL' gluPerspective, or how can I make perspective of OpenGL that will have similar calculus as this code. I know I'm a bit confused, but a good explanation of the following calculus, and especially on why it doesn't work like OpenGL does with constant angle would be helpful. #define Screen_Width 256 #define Screen_Height 192 double fieldofview = 2.0; double xscreenscale = Screen_Width / 2; double yscreenscale = Screen_Height / 2; double maxscale = max(xscreenscale , yscreenscale ); void SetUpFrustum(void) { double angle, s, c; point_t normal; angle = atan(2.0 / fieldofview * maxscale / xscreenscale); s = sin(angle); c = cos(angle); // Left clip plane normal.v[0] = s; normal.v[1] = 0; normal.v[2] = c; SetWorldspaceClipPlane(&normal, &frustumplanes[0]); // Right clip plane normal.v[0] = -s; SetWorldspaceClipPlane(&normal, &frustumplanes[1]); angle = atan(2.0 / fieldofview * maxscale / yscreenscale); s = sin(angle); c = cos(angle); // Bottom clip plane normal.v[0] = 0; normal.v[1] = s; normal.v[2] = c; SetWorldspaceClipPlane(&normal, &frustumplanes[2]); // Top clip plane normal.v[1] = -s; SetWorldspaceClipPlane(&normal, &frustumplanes[3]); } anyaway, thanks in advance. your help is important

Share this post


Link to post
Share on other sites
Advertisement
I'm not really sure how to help you.

You can get the clip matrix (projection*modelview) and use that to clip vertices as in/out. It's called clip codes by most people. It is an easy technique for frustum culling.

As for calculus formulas, I have no idea, but why would you want that anyways? It'd probably be expensive to solve this like that when it is much quicker to extract the planes and test against them. I think clip code rejection is even faster as you don't have to build the planes at all.

Or you can look in Wild Magic, he has a pretty neat camera class.

Share this post


Link to post
Share on other sites
All of questions are answered in a paper
"Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix" by Gil Gribb and Klaus Hartmann.
Simply query OpenGL for the Model-View-Projection matrix and follow the simple to understand paper - its way more efficient than than you think...

HTH

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!