Ejemplo n.º 1
0
        bool IRaySegmentsCollidable.TryGetRayCollision(Body thisBody, Body raysBody, RaySegmentsShape raySegments, out RaySegmentIntersectionInfo info)
        {
            bool intersects = false;

            RaySegment[] segments = raySegments.Segments;
            Scalar[]     result   = new Scalar[segments.Length];
            Scalar       temp;

            Vector2D[][] polygons = this.Polygons;
            for (int index = 0; index < segments.Length; ++index)
            {
                result[index] = -1;
            }
            Matrix2x3 matrix = raysBody.Matrices.ToBody * thisBody.Matrices.ToWorld;

            for (int polyIndex = 0; polyIndex < polygons.Length; ++polyIndex)
            {
                Vector2D[] unTrans = polygons[polyIndex];
                Vector2D[] polygon = new Vector2D[unTrans.Length];
                for (int index = 0; index < unTrans.Length; ++index)
                {
                    Vector2D.Transform(ref matrix, ref unTrans[index], out polygon[index]);
                }
                BoundingRectangle rect;
                BoundingRectangle.FromVectors(polygon, out rect);
                BoundingPolygon poly = new BoundingPolygon(polygon);
                for (int index = 0; index < segments.Length; ++index)
                {
                    RaySegment segment = segments[index];
                    rect.Intersects(ref segment.RayInstance, out temp);
                    if (temp >= 0 && temp <= segment.Length)
                    {
                        poly.Intersects(ref segment.RayInstance, out temp);
                        if (temp >= 0 && temp <= segment.Length)
                        {
                            if (result[index] == -1 || temp < result[index])
                            {
                                result[index] = temp;
                            }
                            intersects = true;
                        }
                    }
                }
            }
            if (intersects)
            {
                info = new RaySegmentIntersectionInfo(result);
            }
            else
            {
                info = null;
            }
            return(intersects);
        }
 public RaysSegmentsDrawable(RaySegmentsShape shape)
 {
     this.shape = shape;
     this.array = new Vector2D[shape.Segments.Length * 2];
     for (int index = 0; index < shape.Segments.Length; ++index)
     {
         RaySegment segment = shape.Segments[index];
         Ray ray = segment.RayInstance;
         array[index * 2] = ray.Origin;
         array[index * 2 + 1] = ray.Origin + ray.Direction * segment.Length;
     }
 }
Ejemplo n.º 3
0
        bool IRaySegmentsCollidable.TryGetRayCollision(Body thisBody, Body raysBody, RaySegmentsShape raySegments, out RaySegmentIntersectionInfo info)
        {
            bool intersects = false;

            RaySegment[]   segments = raySegments.Segments;
            Scalar[]       result   = new Scalar[segments.Length];
            BoundingCircle bounding = new BoundingCircle(Vector2D.Zero, this.radius);
            Matrix2x3      vertexM  = thisBody.Matrices.ToBody * raysBody.Matrices.ToWorld;

            for (int index = 0; index < segments.Length; ++index)
            {
                RaySegment segment = segments[index];
                Ray        ray2;

                Vector2D.Transform(ref vertexM, ref segment.RayInstance.Origin, out ray2.Origin);
                Vector2D.TransformNormal(ref vertexM, ref segment.RayInstance.Direction, out ray2.Direction);

                Scalar temp;
                bounding.Intersects(ref ray2, out temp);
                if (temp >= 0 && temp <= segment.Length)
                {
                    intersects    = true;
                    result[index] = temp;
                    continue;
                }
                else
                {
                    result[index] = -1;
                }
            }
            if (intersects)
            {
                info = new RaySegmentIntersectionInfo(result);
            }
            else
            {
                info = null;
            }
            return(intersects);
        }
Ejemplo n.º 4
0
 public static RaySegmentsShape CreateRays(RaySegment[] raySegments)
 {
     RaySegmentsShape rayShape = new RaySegmentsShape(raySegments);
     rayShape.Tag = new RaysSegmentsDrawable(rayShape);
     return rayShape;
 }
Ejemplo n.º 5
0
 void SetShape(RaySegmentsShape shape)
 {
     current = new RaySegmentsCollisionInfo[shape.Segments.Length];
     next = new RaySegmentsCollisionInfo[shape.Segments.Length];
     Init(current);
     Init(next);
 }
Ejemplo n.º 6
0
        bool IRaySegmentsCollidable.TryGetRayCollision(Body thisBody, Body raysBody, RaySegmentsShape raySegments, out RaySegmentIntersectionInfo info)
        {
            bool intersects = false;
            RaySegment[] segments = raySegments.Segments;
            Scalar[] result = new Scalar[segments.Length];
            BoundingCircle bounding = new BoundingCircle(Vector2D.Zero, this.radius);
            Matrix2x3 vertexM = thisBody.Matrices.ToBody * raysBody.Matrices.ToWorld;

            for (int index = 0; index < segments.Length; ++index)
            {
                RaySegment segment = segments[index];
                Ray ray2;

                Vector2D.Transform(ref vertexM, ref segment.RayInstance.Origin, out ray2.Origin);
                Vector2D.TransformNormal(ref vertexM, ref segment.RayInstance.Direction, out ray2.Direction);

                Scalar temp;
                bounding.Intersects(ref ray2, out temp);
                if (temp >= 0 && temp <= segment.Length)
                {
                    intersects = true;
                    result[index] = temp;
                    continue;
                }
                else
                {
                    result[index] = -1;
                }
            }
            if (intersects)
            {
                info = new RaySegmentIntersectionInfo(result);
            }
            else
            {
                info = null;
            }
            return intersects;
        }
Ejemplo n.º 7
0
 bool IRaySegmentsCollidable.TryGetRayCollision(Body thisBody, Body raysBody, RaySegmentsShape raySegments, out RaySegmentIntersectionInfo info)
 {
     bool intersects = false;
     RaySegment[] segments = raySegments.Segments;
     Scalar[] result = new Scalar[segments.Length];
     Scalar temp;
     Vector2D[][] polygons = this.Polygons;
     for (int index = 0; index < segments.Length; ++index)
     {
         result[index] = -1;
     }
     Matrix2x3 matrix = raysBody.Matrices.ToBody * thisBody.Matrices.ToWorld;
     for (int polyIndex = 0; polyIndex < polygons.Length; ++polyIndex)
     {
         Vector2D[] unTrans = polygons[polyIndex];
         Vector2D[] polygon = new Vector2D[unTrans.Length];
         for (int index = 0; index < unTrans.Length; ++index)
         {
             Vector2D.Transform(ref matrix, ref unTrans[index], out polygon[index]);
         }
         BoundingRectangle rect;
         BoundingRectangle.FromVectors(polygon, out rect);
         BoundingPolygon poly = new BoundingPolygon(polygon);
         for (int index = 0; index < segments.Length; ++index)
         {
             RaySegment segment = segments[index];
             rect.Intersects(ref segment.RayInstance, out temp);
             if (temp >= 0 && temp <= segment.Length)
             {
                 poly.Intersects(ref segment.RayInstance, out temp);
                 if (temp >= 0 && temp <= segment.Length)
                 {
                     if (result[index] == -1 || temp < result[index])
                     {
                         result[index] = temp;
                     }
                     intersects = true;
                 }
             }
         }
     }
     if (intersects)
     {
         info = new RaySegmentIntersectionInfo(result);
     }
     else
     {
         info = null;
     }
     return intersects;
 }