devel/CSGLib/src/ML_Triangle.cpp
// This function tells you if a ball moving from vP1 to vP2 with radius fRadius will cross plane triPlane.
// If the ball at vP1 is intersecting the plane, it doesn't care as long as the ball is moving away.
// A weird situation then is if both vP1 and vP2 is intersecting, yet vP2 is further away than vP1
This function tells you if a ball moving from vP1 to vP2 with radius fRadius will cross plane triPlane.
If the ball at vP1 is intersecting the plane, it doesn't care as long as the ball is moving away.
A weird situation then is if both vP1 and vP2 is intersecting, yet vP2 is further away than vP1
This function tells you if a ball moving from vP1 to vP2 with radius fRadius will cross plane triPlane . If the ball at vP1 is intersecting the plane it doesn ' t care as long as the ball is moving away . A weird situation then is if both vP1 and vP2 is intersecting yet vP2 is further away than vP1
bool mlBallCrossesPlane(const mlVector3D & vP1, const mlVector3D & vP2, mlTriangle & triPlane, float fRadius)
{
	mlVector3D vP1Projected = triPlane.ProjectPoint(vP1);
	mlVector3D vP1ProjectedRay = vP1Projected - vP1;
	mlVector3D vP2Projected = triPlane.ProjectPoint(vP2);
	mlVector3D vP2ProjectedRay = vP2Projected - vP2;
	float fLengthP1 = vP1ProjectedRay.Magnitude();
	float fLengthP2 = vP2ProjectedRay.Magnitude();
	if(fLengthP2 < fRadius && fLengthP2 < fLengthP1)
	{
		return true;
	}
	vP2ProjectedRay.Normalise();
	vP2ProjectedRay *= fRadius;
	mlVector3D vP1ClosePoint = vP1 + vP2ProjectedRay;
	mlVector3D vP2ClosePoint = vP2 + vP2ProjectedRay;
	return mlRayCrossesPlane(vP1ClosePoint, vP2ClosePoint, triPlane);
}
bool mlBallCrossesPlane ( const mlVector3D & vP1 , const mlVector3D & vP2 , mlTriangle & triPlane , float fRadius ) { mlVector3D vP1Projected = triPlane . ProjectPoint ( vP1 ) ; mlVector3D vP1ProjectedRay = vP1Projected - vP1 ; mlVector3D vP2Projected = triPlane . ProjectPoint ( vP2 ) ; mlVector3D vP2ProjectedRay = vP2Projected - vP2 ; float fLengthP1 = vP1ProjectedRay . Magnitude ( ) ; float fLengthP2 = vP2ProjectedRay . Magnitude ( ) ; if ( fLengthP2 < fRadius && fLengthP2 < fLengthP1 ) { return true ; } vP2ProjectedRay . Normalise ( ) ; vP2ProjectedRay *= fRadius ; mlVector3D vP1ClosePoint = vP1 + vP2ProjectedRay ; mlVector3D vP2ClosePoint = vP2 + vP2ProjectedRay ; return mlRayCrossesPlane ( vP1ClosePoint , vP2ClosePoint , triPlane ) ; }
This function tells you if a ball moving from vP1 to vP2 with radius fRadius will cross plane triPlane.
This function tells you if a ball moving from vP1 to vP2 with radius fRadius will cross plane triPlane .
// Is P2 close enough so the ball crosses the plane? //float fLength = vP2ProjectedRay.Magnitude(); //if(fLength < fRadius) // Perhaps only return true if it is closer to the plane than P1 is. // Get the 2 sphere points, and see if they are on opposite sides of the plane