I got the code for a frustum culling class out of a book, and there was nothing in the way of explanation, so I really don’t understand how the thing does it’s job.
The terrain is broken up into square blocks, and my goal is to cull the non-visible blocks. I believe the code is good, because the demos in the book use it, and the culling works fine.
As far as I can tell, the code is testing each corner of the bounding box to see if any of them are currently visible, and if so, the block is visible. I think the problem is that my terrain blocks are large enough so that the camera can get in a position where some of the block is still visible, yet none of the corners are. The code listed is the method used to cull the blocks.
I don’t want to make the blocks smaller, so what are my options?
// x, y, z : center vertex of the block to be checked
// size : length of one side of the block to be checked
public boolean CubeFrustumTest( float x, float y,
float z, float size )
{
for( int i=0; i<6; i++ )
{
if( m_viewFrustum[i][0] * ( x-size ) +
m_viewFrustum[i][1] * ( y-size ) +
m_viewFrustum[i][2] * ( z-size ) +
m_viewFrustum[i][3] > 0 )
continue;
if( m_viewFrustum[i][0] * ( x+size ) +
m_viewFrustum[i][1] * ( y-size ) +
m_viewFrustum[i][2] * ( z-size ) +
m_viewFrustum[i][3] > 0 )
continue;
if( m_viewFrustum[i][0] * ( x-size ) +
m_viewFrustum[i][1] * ( y+size ) +
m_viewFrustum[i][2] * ( z-size ) +
m_viewFrustum[i][3] > 0 )
continue;
if( m_viewFrustum[i][0] * ( x+size ) +
m_viewFrustum[i][1] * ( y+size ) +
m_viewFrustum[i][2] * ( z-size ) +
m_viewFrustum[i][3] > 0 )
continue;
if( m_viewFrustum[i][0] * ( x-size ) +
m_viewFrustum[i][1] * ( y-size ) +
m_viewFrustum[i][2] * ( z+size ) +
m_viewFrustum[i][3] > 0 )
continue;
if( m_viewFrustum[i][0] * ( x+size ) +
m_viewFrustum[i][1] * ( y-size ) +
m_viewFrustum[i][2] * ( z+size ) +
m_viewFrustum[i][3] > 0 )
continue;
if( m_viewFrustum[i][0] * ( x-size ) +
m_viewFrustum[i][1] * ( y+size ) +
m_viewFrustum[i][2] * ( z+size ) +
m_viewFrustum[i][3] > 0 )
continue;
if( m_viewFrustum[i][0] * ( x+size ) +
m_viewFrustum[i][1] * ( y+size ) +
m_viewFrustum[i][2] * ( z+size ) +
m_viewFrustum[i][3] > 0 )
continue;
return false;
}
return true;
}
If someone has a FrustumCuller that contains a method that would work in my case, I would be very pleased to recieve it.
kmyers@bardstowncable.net
Thanks