devel/CSGLib/src/ML_Triangle.cpp
// This function tells you if points vP1 and vP2 are on opposite sides of the plane triPlane
This function tells you if points vP1 and vP2 are on opposite sides of the plane triPlane
This function tells you if points vP1 and vP2 are on opposite sides of the plane triPlane
bool mlRayCrossesPlane(const mlVector3D & vP1, const mlVector3D & vP2, mlTriangle & triPlane)
{
	mlVector3D vNormal = triPlane.Normal();
	mlVector3D vP1Projected = triPlane.ProjectPoint(vP1) - vP1;
	mlVector3D vP2Projected = triPlane.ProjectPoint(vP2) - vP2;
	float fDot1 = vP1Projected * vNormal;
	float fDot2 = vP2Projected * vNormal;
	if(mlFabs(fDot1) < 1.0f)
	{
		fDot1 = 0.0f;
	}
	if(mlFabs(fDot2) < 1.0f)
	{
		fDot2 = 0.0f;
	}
	float fSgn1 = mlSign(fDot1);
	float fSgn2 = mlSign(fDot2);
	if(fSgn1 == fSgn2 || fSgn1 == 0.0f || fSgn2 == 0.0f)
	{
		return false;
	}
	else
	{
		return true;
	}
}
bool mlRayCrossesPlane ( const mlVector3D & vP1 , const mlVector3D & vP2 , mlTriangle & triPlane ) { mlVector3D vNormal = triPlane . Normal ( ) ; mlVector3D vP1Projected = triPlane . ProjectPoint ( vP1 ) - vP1 ; mlVector3D vP2Projected = triPlane . ProjectPoint ( vP2 ) - vP2 ; float fDot1 = vP1Projected * vNormal ; float fDot2 = vP2Projected * vNormal ; if ( mlFabs ( fDot1 ) < 1.0f ) { fDot1 = 0.0f ; } if ( mlFabs ( fDot2 ) < 1.0f ) { fDot2 = 0.0f ; } float fSgn1 = mlSign ( fDot1 ) ; float fSgn2 = mlSign ( fDot2 ) ; if ( fSgn1 == fSgn2 || fSgn1 == 0.0f || fSgn2 == 0.0f ) { return false ; } else { return true ; } }
This function tells you if points vP1 and vP2 are on opposite sides of the plane triPlane
This function tells you if points vP1 and vP2 are on opposite sides of the plane triPlane