コード例 #1
0
        public bool Raycast(Ray3D ray, out float t)
        {
            if (ray.IntersectsPlane(_plane, out t))
            {
                Vector3 intersectionPoint = ray.GetPoint(t);
                return(ContainsPoint(intersectionPoint));
            }

            return(false);
        }
コード例 #2
0
        public bool IntersectsTriangle(Triangle3D triangle, out Triangle3DIntersectInfo intersectInfo)
        {
            intersectInfo = new Triangle3DIntersectInfo();
            if (triangle.Normal.IsAlignedWith(Normal))
            {
                return(false);
            }

            float            t;
            List <Segment3D> otherTriSegments = triangle.GetSegments();
            var firstTriIntersectionPoints    = new List <Vector3>();

            foreach (var segment in otherTriSegments)
            {
                Ray3D ray = new Ray3D(segment.StartPoint, segment.EndPoint);
                if (Raycast(ray, out t))
                {
                    firstTriIntersectionPoints.Add(ray.GetPoint(t));
                }
            }

            List <Segment3D> thisTriSegments = GetSegments();
            var secondTriIntersectionPoints  = new List <Vector3>();

            foreach (var segment in thisTriSegments)
            {
                Ray3D ray = new Ray3D(segment.StartPoint, segment.EndPoint);
                if (triangle.Raycast(ray, out t))
                {
                    secondTriIntersectionPoints.Add(ray.GetPoint(t));
                }
            }

            if (firstTriIntersectionPoints.Count != 0 || secondTriIntersectionPoints.Count != 0)
            {
                intersectInfo = new Triangle3DIntersectInfo(this, triangle, firstTriIntersectionPoints, secondTriIntersectionPoints);
                return(true);
            }

            return(false);
        }