BEPUphysics.CollisionShapes.MobileMeshShape.ComputeSolidSidedness C# (CSharp) Method

ComputeSolidSidedness() private method

private ComputeSolidSidedness ( ) : void
return void
        void ComputeSolidSidedness()
        {
            //Raycast against the mesh.
            //If there's an even number of hits, then the ray start point is outside.
            //If there's an odd number of hits, then the ray start point is inside.

            //If the start is outside, then take the earliest toi hit and calibrate sidedness based on it.
            //If the start is inside, then take the latest toi hit and calibrate sidedness based on it.

            //This test assumes consistent winding across the entire mesh as well as a closed surface.
            //If those assumptions are not correct, then the raycast cannot determine inclusion or exclusion,
            //or there exists no calibration that will work across the entire surface.

            //Pick a ray direction that goes to a random location on the mesh.  
            //A vertex would work, but targeting the middle of a triangle avoids some edge cases.
            var ray = new Ray();
            Vector3 vA, vB, vC;
            triangleMesh.Data.GetTriangle(((triangleMesh.Data.indices.Length / 3) / 2) * 3, out vA, out vB, out vC);
            ray.Direction = (vA + vB + vC) / 3;
            ray.Direction.Normalize();

            solidSidedness = ComputeSolidSidednessHelper(ray);
            //TODO: Positions need to be valid for the verifying directions to work properly.
            ////Find another direction and test it to corroborate the first test.
            //Ray alternateRay;
            //alternateRay.Position = ray.Position;
            //Vector3.Cross(ref ray.Direction, ref Toolbox.UpVector, out alternateRay.Direction);
            //float lengthSquared = alternateRay.Direction.LengthSquared();
            //if (lengthSquared < Toolbox.Epsilon)
            //{
            //    Vector3.Cross(ref ray.Direction, ref Toolbox.RightVector, out alternateRay.Direction);
            //    lengthSquared = alternateRay.Direction.LengthSquared();
            //}
            //Vector3.Divide(ref alternateRay.Direction, (float)Math.Sqrt(lengthSquared), out alternateRay.Direction);
            //var sidednessCandidate2 = ComputeSolidSidednessHelper(alternateRay);
            //if (sidednessCandidate == sidednessCandidate2)
            //{
            //    //The two tests agreed! It's very likely that the sidedness is, in fact, in this direction.
            //    solidSidedness = sidednessCandidate;
            //}
            //else
            //{
            //    //The two tests disagreed.  Tiebreaker!
            //    Vector3.Cross(ref alternateRay.Direction, ref ray.Direction, out alternateRay.Direction);
            //    solidSidedness = ComputeSolidSidednessHelper(alternateRay);
            //}
        }