view frustum problem

Ok… I want to try to be as clear as I can so that maybe someone can help me Please

Any way here goes…

I know that this is only sort of OGL related, but I need to know given these variables

near, far, fov, eyex, eyey, eyez,
cameraroll, camerapitch, camerayaw

what are the six viewing planes that define that volume…

Specifically say I want to build a box that will exactly (or just a little bigger not important) completely fill the viewing volume

using a perspective projection…

What I need is the xyz coordinates of the corners of the polyhedron…

Thank you very much in advance

It seems that you need this for clipping
The you should build six plane equations and transform your bounding box points with them assigning the sign to point. Wehn all points have negative sign ( or positive if inverse equation is used ), box lies completely outside, if at least one point has positive sign and one negative - the primitive is clipped with plane …
In first case you may stop checking just now …
also, if all boo points have positive signs for all six planes, and you have the EXT_clip_volume_hint extension, you bay disable clipping since it lies completely within sliced view pyramid.

About equations - check some old Michael Abrashes DDJ articles about building equations for view frustum planes.

I hope people are still watching this thread…

Anyway I am going to run an idea…

Build a polyhedron that completely matches the viewing frustum… (by trig)

When a user moves the camera (or the scene whatever) the viewing frustum moves to a different area of the scene…

So what we do is given the points that define the polyhedron we grab the current modelview matrix and translate rotate (basically apply the change) to the polyhedron thus moving it to the new viewing frustum position

I hope that by applying the transformation matrix that the polyhedron will match the new viewing volume

Then when we want to check to see if a bounding box or primative is within the volume we have the edges of the volume (through the polyhedron) and we render or don’t render based on the tests

Anyway, what I am asking now is two parts

A. The original question (what are these points that define the polyhedron itially)

B. If my idea will work that is all I need, but if it wont work then we need to define the polyhedron in terms of

roll pitch yaw x y z fov and near far planes
(which we would do originally, but it is much simpler for a known case, not an arbitrary one such as any arbitrary motion that a user may impose

Anyway… Thanks and have a good day

BTW I need this for use in early culling or view frustum culling … thus objects that pass the test are sent to gl if not then they are not sent to gl.

[This message has been edited by frogger (edited 06-08-2000).]

Ok, here is a piece of code which calculates the clipping planes equations.

void GL_frust_calc_clip_planes(CAMERA camera)
{
/
This function updates the clipping planes from the current
OpenGL frustum defined */

    GLfloat         mdlmatGL[16];
    GLfloat         projmatGL[16];
    real            mdlmat[16];
    real            projmat[16];
    real            clipmat[16];
    ushortint       i;              /* count variable */

    /* Get the modelview and projection matrices */
    glGetFloatv(GL_MODELVIEW_MATRIX,mdlmatGL);
    glGetFloatv(GL_PROJECTION_MATRIX,projmatGL);

#ifndef REAL_IS_GLFLOAT
for (i=0;i<16;i++)
{
mdlmat[i]=(real)mdlmatGL[i];
projmat[i]=(real)projmatGL[i];
}
#endif

    /* clipmat transforms from OC (object coordinates) to CC (clip coordinates) */
    MATRIX_concat(clipmat,mdlmat,projmat);

    /* Calculate the six OC plane equations. */
    (camera->clip_plane)[0][0]=(real)(clipmat[3]-clipmat[0]);
    (camera->clip_plane)[0][1]=(real)(clipmat[7]-clipmat[4]);
    (camera->clip_plane)[0][2]=(real)(clipmat[11]-clipmat[8]);
    (camera->clip_plane)[0][3]=(real)(clipmat[15]-clipmat[12]);

    (camera->clip_plane)[1][0]=(real)(clipmat[3]+clipmat[0]);
    (camera->clip_plane)[1][1]=(real)(clipmat[7]+clipmat[4]);
    (camera->clip_plane)[1][2]=(real)(clipmat[11]+clipmat[8]);
    (camera->clip_plane)[1][3]=(real)(clipmat[15]+clipmat[12]);

    (camera->clip_plane)[2][0]=(real)(clipmat[3]+clipmat[1]);
    (camera->clip_plane)[2][1]=(real)(clipmat[7]+clipmat[5]);
    (camera->clip_plane)[2][2]=(real)(clipmat[11]+clipmat[9]);
    (camera->clip_plane)[2][3]=(real)(clipmat[15]+clipmat[13]);

    (camera->clip_plane)[3][0]=(real)(clipmat[3]-clipmat[1]);
    (camera->clip_plane)[3][1]=(real)(clipmat[7]-clipmat[5]);
    (camera->clip_plane)[3][2]=(real)(clipmat[11]-clipmat[9]);
    (camera->clip_plane)[3][3]=(real)(clipmat[15]-clipmat[13]);

    (camera->clip_plane)[4][0]=(real)(clipmat[3]+clipmat[2]);
    (camera->clip_plane)[4][1]=(real)(clipmat[7]+clipmat[6]);
    (camera->clip_plane)[4][2]=(real)(clipmat[11]+clipmat[10]);
    (camera->clip_plane)[4][3]=(real)(clipmat[15]+clipmat[14]);

    (camera->clip_plane)[5][0]=(real)(clipmat[3]-clipmat[2]);
    (camera->clip_plane)[5][1]=(real)(clipmat[7]-clipmat[6]);
    (camera->clip_plane)[5][2]=(real)(clipmat[11]-clipmat[10]);
    (camera->clip_plane)[5][3]=(real)(clipmat[15]-clipmat[14]);

}

MATRIX_concat is used to concatenate two matrix. The result is the first argument. If you want the code of it, just tell me.

This function should be called only when the camera moves (translation/rotation). Not each frame.

Good luck,

Y.

yes I would like to see the code for Mat_concat

This, taken from a matrix faq I picked up an age ago…

static void matrixConcatenate (float *result, float *ma, float *mb)
{
    int i;
    double mb00, mb01, mb02, mb03,
           mb10, mb11, mb12, mb13,
           mb20, mb21, mb22, mb23,
           mb30, mb31, mb32, mb33;
    double mai0, mai1, mai2, mai3;

    mb00 = mb[0];  mb01 = mb[1];
    mb02 = mb[2];  mb03 = mb[3];
    mb10 = mb[4];  mb11 = mb[5];
    mb12 = mb[6];  mb13 = mb[7];
    mb20 = mb[8];  mb21 = mb[9];
    mb22 = mb[10];  mb23 = mb[11];
    mb30 = mb[12];  mb31 = mb[13];
    mb32 = mb[14];  mb33 = mb[15];

    for (i = 0; i < 4; i++) {
        mai0 = ma[i*4+0];  mai1 = ma[i*4+1];
            mai2 = ma[i*4+2];  mai3 = ma[i*4+3];

        result[i*4+0] = mai0 * mb00 + mai1 * mb10 + mai2 * mb20 + mai3 * mb30;
        result[i*4+1] = mai0 * mb01 + mai1 * mb11 + mai2 * mb21 + mai3 * mb31;
        result[i*4+2] = mai0 * mb02 + mai1 * mb12 + mai2 * mb22 + mai3 * mb32;
        result[i*4+3] = mai0 * mb03 + mai1 * mb13 + mai2 * mb23 + mai3 * mb33;
    }
}

HTH,
Paul