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.
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.