Addon: SViewFrustrum::classifyBoxRelation()

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
eax
Posts: 9
Joined: Sun Dec 14, 2003 12:49 pm
Location: Switzerland::Bern

Addon: SViewFrustrum::classifyBoxRelation()

Post by eax »

Hi all

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);
	}
Visit Project|Aqua Homepage
eax
Posts: 9
Joined: Sun Dec 14, 2003 12:49 pm
Location: Switzerland::Bern

Post by eax »

Was added today to Irrlicht NX CVS.
Visit Project|Aqua Homepage
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Ah, definately useful :)
Post Reply