Exemple #1
0
        protected (bool, float, float, float) TestLocalIntersection(Ray localRay)
        {
            Tuple dirCrossE2 = localRay.Direction.Cross(E2);
            float det        = E1.Dot(dirCrossE2);

            if (Abs(det) < Constants.floatEps)
            {
                return(false, 0, 0, 0);
            }

            float invDet = 1.0f / det;

            Tuple p1ToOrigin = localRay.Origin - P1;
            float u          = invDet * p1ToOrigin.Dot(dirCrossE2);

            if (u < 0 || u > 1)
            {
                return(false, 0, 0, 0);
            }

            Tuple originCrossE1 = p1ToOrigin.Cross(E1);
            float v             = invDet * localRay.Direction.Dot(originCrossE1);

            if (v < 0 || (u + v) > 1)
            {
                return(false, 0, 0, 0);
            }

            float t = invDet * E2.Dot(originCrossE1);

            return(true, t, u, v);
        }