# Frustum Culling problem.......

2 replies to this topic

### #1BlackWind

New Member

• Members
• 2 posts

Posted 09 December 2004 - 11:13 PM

Hi.
according to www.gametutorials.com in their frustum culling tuto, to abstract the frustum from OpenGL, we need the projection and modelview matrix.
To get the projection matrix we use:
glGetFloatv( GL_PROJECTION_MATRIX, proj);
Then, to get the modelview matrix we use:
glGetFloatv( GL_MODELVIEW_MATRIX, modl);

where proj and modl are arrays of 16 floats

These 2 functions gives us an array of 16 floats (The matrix).
Next, we need to combine these 2 matrices (for the clipping planes). We do that by matrix multiplication.
and we store the data into another 16 floats array named clip[16]

and they do this:
clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];

clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];

clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];

clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];

clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];

clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];

clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];

clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];

clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];

clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];

clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];

clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];

clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];



what i dont understand, is hoe do they know the order??, why that order (in the positions of the proj and modl matrix multiplication).
why not for example: clip[15] = modl[15] * proj[ 0] + modl[15] * proj[ 1] + modl[15] * proj[11] + modl[13] * proj[15];

Now that we have the 2 matrixes combined (in clip[]), we can abstract the sides of the frustum.
This will give us the normal and the distance from the plane to the origin (ABC and D).
i dont understand why they do it in this order:

// right
m_Frustum[RIGHT][A] = clip[ 3] - clip[ 0];
m_Frustum[RIGHT][B] = clip[ 7] - clip[ 4];
m_Frustum[RIGHT][C] = clip[11] - clip[ 8];
m_Frustum[RIGHT][D] = clip[15] - clip[12];

// left
m_Frustum[LEFT][A] = clip[ 3] + clip[ 0];
m_Frustum[LEFT][B] = clip[ 7] + clip[ 4];
m_Frustum[LEFT][C] = clip[11] + clip[ 8];
m_Frustum[LEFT][D] = clip[15] + clip[12];

// bottom
m_Frustum[BOTTOM][A] = clip[ 3] + clip[ 1];
m_Frustum[BOTTOM][B] = clip[ 7] + clip[ 5];
m_Frustum[BOTTOM][C] = clip[11] + clip[ 9];
m_Frustum[BOTTOM][D] = clip[15] + clip[13];

// top
m_Frustum[TOP][A] = clip[ 3] - clip[ 1];
m_Frustum[TOP][B] = clip[ 7] - clip[ 5];
m_Frustum[TOP][C] = clip[11] - clip[ 9];
m_Frustum[TOP][D] = clip[15] - clip[13];

// front
m_Frustum[FRONT][A] = clip[ 3] + clip[ 2];
m_Frustum[FRONT][B] = clip[ 7] + clip[ 6];
m_Frustum[FRONT][C] = clip[11] + clip[10];
m_Frustum[FRONT][D] = clip[15] + clip[14];

// back
m_Frustum[BACK][A] = clip[ 3] - clip[ 2];
m_Frustum[BACK][B] = clip[ 7] - clip[ 6];
m_Frustum[BACK][C] = clip[11] - clip[10];
m_Frustum[BACK][D] = clip[15] - clip[14];



how do they know which positions to take???

hope someone can help, tanks....

### #2caesar4

New Member

• Members
• 9 posts

Posted 10 December 2004 - 03:09 AM

the proof is long and painful, ure gonna have to expand the matricies and also do it by creating a frustum transform matrix from the camera pos,up,lookat by extracting the euler angles (heading, pitch, roll), translate, then transform a pyramid representing the view frustum

btw
if ur camera near plane is really close to the camera pos (znear <= 1f), save urself some time and dont even check the near plane

### #3BlackWind

New Member

• Members
• 2 posts

Posted 10 December 2004 - 04:07 PM

caesar4 said:

the proof is long and painful, ure gonna have to expand the matricies and also do it by creating a frustum transform matrix from the camera pos,up,lookat by extracting the euler angles (heading, pitch, roll), translate, then transform a pyramid representing the view frustum

btw
if ur camera near plane is really close to the camera pos (znear <= 1f), save urself some time and dont even check the near plane

well....that was not my question, but i got a nice link where they explain it....
http://www2.ravensoft.com/users/ggribb/pla...0extraction.pdf

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users