#include #include Plane::Plane( const Vector3 &pt, const Vector3 &normal ) { a = normal.x; b = normal.y; c = normal.z; d = ( -a * pt.x ) - ( b * pt.y ) - ( c * pt.z ); } Plane::~Plane( void ) { } bool Plane::closestIntersect( Vector3 *pos, Vector3 *norm, const Vector3 &o, const Vector3 &dir ) const { double bot = ( ( a * dir.x ) + ( b * dir.y ) + ( c * dir.z ) ); if( threshEqual( 0.0, bot, 0.00001 ) ) return false; double top = ( ( -a * o.x ) - ( b * o.y ) - ( c * o.z ) - d ); double t = top / bot; if( t <= 0.0 ) return false; *pos = o.add( dir.scalarMult( t ) ); *norm = Vector3( a, b, c ); return true; }