moai/src/uslscore/USIntersect.cpp
//----------------------------------------------------------------//
// Return:
//	 1:		Prism is in front of the plane
//	 0:		Prism intersects the plane
//	-1:		Prism is behind the plane
Prism is in front of the plane
0:             Prism intersects the plane
1:             Prism is behind the plane
Prism is in front of the plane 0 : Prism intersects the plane 1 : Prism is behind the plane
s32 USSect::PrismToPlane ( const USPrism& prism, const USPlane3D& p ) {
	float sdX = prism.mXAxis.Dot ( p.mNorm );
	if ( sdX < 0.0f ) sdX = -sdX;
	float sdY = prism.mXAxis.Dot ( p.mNorm );
	if ( sdY < 0.0f ) sdY = -sdY;
	float sdZ = prism.mXAxis.Dot ( p.mNorm );
	if ( sdZ < 0.0f ) sdZ = -sdZ;
	float r = ( sdX + sdY + sdZ ) * 0.5f;
	USVec3D c;
	prism.GetCenter ( c );
	float d = USDist::VecToPlane ( c, p );
	if ( d > r ) return 1; 
	if ( d < -r ) return -1; 
	return 0; 
}
s32 USSect :: PrismToPlane ( const USPrism & prism , const USPlane3D & p ) { float sdX = prism . mXAxis . Dot ( p . mNorm ) ; if ( sdX < 0.0f ) sdX = - sdX ; float sdY = prism . mXAxis . Dot ( p . mNorm ) ; if ( sdY < 0.0f ) sdY = - sdY ; float sdZ = prism . mXAxis . Dot ( p . mNorm ) ; if ( sdZ < 0.0f ) sdZ = - sdZ ; float r = ( sdX + sdY + sdZ ) * 0.5f ; USVec3D c ; prism . GetCenter ( c ) ; float d = USDist :: VecToPlane ( c , p ) ; if ( d > r ) return 1 ; if ( d < - r ) return -1 ; return 0 ; }
Return:
1:             Prism is in front of the plane
0:             Prism intersects the plane
1:             Prism is behind the plane
Return : 1 : Prism is in front of the plane 0 : Prism intersects the plane 1 : Prism is behind the plane
// Get the span dots // Get the radius of the prism (as projected onto the plane's normal) // Get the prism center // The distance from the center of the prism to the plane // Now test against the span // The prism is in front of the plane // The prism is behind the plane // The prism intersects the plane