Advertisement

Camera Frustrum/Frustration

Started by July 09, 2000 10:35 AM
0 comments, last by DuhMe 24 years, 4 months ago
I am posting this question after hours of frustration. I''ve been working on determining the Camera''s frustrum in OGL. I want to figure out the four corner points for some math and additional procedures I plan on completeing. If anyone could help I''d greatly appreciate it. I''ve been tried to take the parameters from gluPerspective like the FOVY and calculate the arcsin(FOVY/2) (note: I converted FOVY to radians first ). Then I proceeded to rotate these coords by the angle created by the center coord and translate these coords by the eye position (all from gluLookAt). Am I far off with this approach or just taking the wrong approach? DuhMe I''m an idiot so you don''t have to be.
DuhMeI''m an idiot so you don''t have to be.
It will probably help if you think of a frustum (only 1 ''r'' as a set of 6 planes (Left, Right, Top, Bottom, Front, Back). Each plane consists of a normal and an offset (distance along the normal where the plane is located).

Also, you need to decide on which axis your frustum will lie/point down. I use a Z up, Y forward / into the screen, X to the right coordinate system. So my near/far planes will be located along the Y axis:

planes[NEAR_PLANE].set(0.0f, 1.0f, 0.0f, nearDistance);
planes[FAR_PLANE].set(0.0f, -1.0f, 0.0f, farDistance);

Also note that the normals to my 6 planes point towards the ''inside'' of the frustum. So the far plane points down -Y and is moved back an amount specified by farDistance.

The 4 other planes are basically just normals from the origin (offset == 0). They can be found using the horizFOV and vertFOV parameters. Get some paper and draw a few triangles that represent your FOV when looking from either the top (for left/right planes) or side (top/bottom planes). Use the hFOV and vFOV values, and then using some trig (sin & cos of the hFOV/vFOV), you can calc the normals you need.

Here''s how I calc the left/right planes... The top/bottom are similar.

  float hAng = (hFOV * 0.5f);  float vAng = (vFOV * 0.5f);  float s, c;  mSinCos(hAng, s, c); // s = sin(hAng), c = cos(hAng)      // LEFT_PLANE  planes[LEFT_PLANE].set(c, s, 0, 0);  // RIGHT_PLANE  planes[RIGHT_PLANE].set(-c, s, 0, 0);


(remember that for me, +Y is ''forward'')..

To transform this frustum to match the location of the camera, you just need to transform each of the 6 planes which it fairly straightfoward..

This topic is closed to new replies.

Advertisement