I added a new function to the SViewFrustrum struct. It classifys the relation of a aabbox to the frustum. Return values are:
0 = Whole box is outside the frustum,
1 = Box intersects with frustum,
2 = Whole box is inside the frustum
This is kinda helpful for quadtree frustum culling.
Diff can be downloaded here (Note: This diff is for Irrlicht NX): http://homepage.swissonline.ch/nevrast/ ... ion.h.diff
Function:
Code: Select all
//! Tests if a aabox is within the frustrum.
//! \return 0 = Whole box is outside the frustum, 1 = Box intersects with frustum, 2 = Whole box is inside the frustum.
inline u32 SViewFrustrum::classifyBoxRelation( const core::aabbox3d<f32>& aabox ) const
{
// Get edges
core::vector3d<f32> edges[8];
aabox.getEdges(edges); // let's generate the edge points
// Helpers
u32 uInsidePlane = 0;
u32 uPointsInside; // Number of points which are in front of current plane
u32 uBoxIsInside; // Flag: 1 if whole box is in front of current plane
for( u32 p=0; p<6; ++p )
{
uPointsInside = 8;
uBoxIsInside = 1;
for( u32 i=0; i<8; ++i )
{
// check if current point is behind the plane
if( planes[p].classifyPointRelation(edges[i]) == core::ISREL3D_BACK )
{
uBoxIsInside = 0;
--uPointsInside;
}
}
// if all 8 points of the box are outside of a plane -> box is outside frustum
if( 0 == uPointsInside ) return(0);
uInsidePlane += uBoxIsInside;
}
// if box is in front of all 6 planes -> box is fully inside
if( 6 == uInsidePlane ) return(2);
// box intersects with a plane
return(1);
}