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