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);
        }
Example #2
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);
        }
Example #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;
        }
 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;
 }