Here a plane intersection function :
bool IntersectRayPlane( const CRay& Ray, const CPlane& Plane, float* t )
{
const float Numerator = VectorDot( Plane.n, Ray.m_Origin ) + Plane.d;
if( Numerator <= 0.0f )
return false;
const float Denominator = VectorDot( Plane.n, Ray.m_Direction );
if( CMath::Abs( Denominator ) < CMath::EPSILON )
return false;
*t = -( Numerator / Denominator );
return true;
}
This part is the backface culling :
if( Numerator <= 0.0f )
return false;
Is it better to have a boolean param to enable or disable the backface culling ?
Edit :
Maybe that's more clear to do : const float Numerator = Plane.DistanceToPoint( Ray.m_Origin );
Maybe that's more correct to do : if( Denominator == 0.0f )