Ejemplo n.º 1
0
        public override bool PreciseIntersect(ref SSRay worldSpaceRay, ref float distanceAlongRay)
        {
            SSRay          localRay            = worldSpaceRay.Transformed(this.worldMat.Inverted());
            SSAbstractMesh mesh                = this._mesh;
            bool           hit                 = false;
            float          localNearestContact = float.MaxValue;

            if (mesh == null)
            {
                return(true);                // no mesh to test
            }
            else
            {
                // precise meshIntersect
                bool global_hit = mesh.traverseTriangles((state, V1, V2, V3) => {
                    float contact;
                    if (OpenTKHelper.TriangleRayIntersectionTest(V1, V2, V3, localRay.pos, localRay.dir, out contact))
                    {
                        hit = true;
                        localNearestContact = Math.Min(localNearestContact, contact);
                        Console.WriteLine("Triangle Hit @ {0} : Object {1}", contact, Name);
                    }
                    return(false);                    // don't short circuit
                });
                if (hit)
                {
                    float worldSpaceContactDistance = -localNearestContact * this.Scale.LengthFast;
                    Console.WriteLine("Nearest Triangle Hit @ {0} vs Sphere {1} : Object {2}", worldSpaceContactDistance, distanceAlongRay, Name);
                    distanceAlongRay = worldSpaceContactDistance;
                }
                return(global_hit || hit);
            }
        }