示例#1
0
        public CollisionResult CheckCollision(RayEntity ray)
        {
            TriangleEntity          triangleRef  = null;
            IntersectTriangleResult?collisionRef = null;
            var minDistance = double.MaxValue;

            foreach (var polygon in Polygons)
            {
                var collision = ray.IntersectTriangle(polygon);

                if (collision.HasValue && minDistance > collision.Value.Distance)
                {
                    minDistance  = collision.Value.Distance;
                    triangleRef  = polygon;
                    collisionRef = collision;
                }
            }

            if (triangleRef == null)
            {
                return(null);
            }

            return(new CollisionResult()
            {
                Normal = triangleRef.Normal,
                //Normal = (collisionRef.Value.Point - Position).Normalize(),
                Point = collisionRef.Value.Point,
            });
        }
示例#2
0
        public CollisionResult CheckCollision(RayEntity ray)
        {
            if (Polygons.Count() != 2)
            {
                throw new Exception("Quad must contain only two polygons!");
            }

            foreach (var polygon in Polygons)
            {
                var collision = ray.IntersectTriangle(polygon.VertexA, polygon.VertexB, polygon.VertexC, polygon.Normal);

                if (collision.HasValue)
                {
                    return(new CollisionResult()
                    {
                        Point = collision.Value.Point,
                        Normal = polygon.Normal,
                    });
                }
            }

            return(null);
        }