Exemplo n.º 1
0
        internal override sealed void Trace( Ray ModelRay, ShapeHitCollection ShapeHits )
        {
            Debug.Assert( ShapeHits != null );

            ShapeHitList Hits = new ShapeHitList( ShapeHits );
            Trace( ModelRay, ref Hits );
        }
Exemplo n.º 2
0
        protected override void Trace( Ray ModelRay, ref ShapeHitList Hits )
        {
            Vector oc = Center - ModelRay.Origin;
            float l2oc = Vector.DotProduct( oc, oc );
            float dp = Vector.DotProduct( ModelRay.Direction, ModelRay.Direction );

            if ( l2oc <= RadiusSquared ) // Inside the sphere
            {
                float tca = Vector.DotProduct( oc, ModelRay.Direction );
                float l2hc = ( RadiusSquared - l2oc ) / dp + tca * tca;

                float t = tca + (float)Math.Sqrt( l2hc );
                Hits.Add( t, SphereInsideFaceIndex );
            }
            else
            {
                float tca = Vector.DotProduct( oc, ModelRay.Direction ) / dp;

                if ( tca >= 0.0f )
                {
                    float l2hc = ( RadiusSquared - l2oc ) / dp + tca * tca;
                    float t = tca - (float)Math.Sqrt( l2hc );

                    if ( l2hc > 0.0f ) // Hits Sphere
                    {
                        Hits.Add( t, SphereOutsideFaceIndex );
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected override void Trace( Ray ModelRay, ref ShapeHitList Hits )
        {
            float dp = Vector.DotProduct( ModelRay.Direction, Normal );
            float distance = -Vector.DotProduct( ModelRay.Origin - P0, Normal ) / dp;

            // If the distnace traveled is less than zero, misses the plane
            if ( distance <= 0.0f )
            {
                return;
            }

            if ( dp > 0.0f ) // Hits front
            {
                Hits.Add( distance, PlaneFrontFaceIndex );
            }
            else // Hits back
            {
                Hits.Add( distance, PlaneBackFaceIndex );
            }
        }
Exemplo n.º 4
0
 protected abstract void Trace( Ray ModelRay, ref ShapeHitList Hits );