// Intersection between 2 planes public bool Intersect( Plane _p, Ray _ray ) { // Check if both planes are coplanar if ( (float) System.Math.Abs( 1.0f - _p.n.Dot(n) ) < float.Epsilon ) return false; // Let's have fun! float3 I = new float3(); _ray.Pos.Set( 0, 0, 0 ); _ray.Aim = n; if ( !_p.Intersect( _ray, ref I ) ) return false; _ray.Aim = _p.n; if ( !_p.Intersect( _ray, ref I ) ) return false; _ray.Pos = I; _ray.Aim = I - _ray.Pos; if ( !Intersect( _ray, ref I ) ) return false; _ray.Pos = I; // We have at least one point belonging to both planes! _ray.Aim = n.Cross(_p.n).Normalized; return true; }
// Arithmetic operators public static Plane operator *( Plane _Op0, float4x4 _Op1 ) { Plane Ret = new Plane(); float3 n2 = (float3) (new float4( _Op0.n, 0 ) * _Op1); Ret.d = -((float3) (new float4( -_Op0.d * _Op0.n, 0.0f ) * _Op1)).Dot( n2 ); Ret.n = n2; return Ret; }
// Intersection between 3 planes public bool Intersect( Plane _p0, Plane _p1, ref float3 _intersection ) { // Compute the intersection of 2 planes first, yielding a ray Ray Hit = new Ray(); if ( !_p0.Intersect( _p1, Hit ) ) return false; // Then compute the intersection of this ray with our plane return Intersect( Hit, ref _intersection ); }