Ejemplo n.º 1
0
 public static IEnumerable <LSBody> RaycastAll(Vector2d start, Vector2d end)
 {
     _Version++;
     LSBody.PrepareAxisCheck(start, end);
     foreach (FractionalLineAlgorithm.Coordinate coor in
              GetRelevantNodeCoordinates(start, end))
     {
         int indexX = coor.X;
         int indexY = coor.Y;
         if (!Partition.CheckValid(coor.X, coor.Y))
         {
             break;
         }
         PartitionNode node = Partition.GetNode(indexX, indexY);
         for (int i = node.ContainedDynamicObjects.Count - 1; i >= 0; i--)
         {
             LSBody body = PhysicsManager.SimObjects[node.ContainedDynamicObjects[i]];
             if (body.IsNotNull() && body.RaycastVersion != _Version)
             {
                 if (Conditional.IsNull() || Conditional())
                 {
                     body.RaycastVersion = _Version;
                     if (body.Overlaps(bufferIntersectionPoints))
                     {
                         yield return(body);
                     }
                 }
             }
         }
     }
     Conditional = null;
     yield break;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds all dynamic bodies touching a defined circle.
        /// </summary>
        /// <param name="radius">Radius.</param>
        /// <param name="output">Output.</param>
        public static void CircleCast(Vector2d position, long radius, FastList <LSBody> output)
        {
            long xMin = position.x - radius,
                 xmax = position.x + radius;
            long yMin = position.y - radius,
                 yMax = position.y + radius;

            //Find the partition tiles we have to search in first
            int gridXMin, gridXMax, gridYMin, gridYMax;

            Partition.GetGridBounds(xMin, xmax, yMin, yMax,
                                    out gridXMin, out gridXMax, out gridYMin, out gridYMax);


            for (int i = gridXMin; i <= gridXMax; i++)
            {
                for (int j = gridYMin; j <= gridYMax; j++)
                {
                    PartitionNode node = Partition.GetNode(i, j);
                    for (int k = 0; k < node.ContainedDynamicObjects.Count; k++)
                    {
                        var  body        = PhysicsManager.SimObjects [node.ContainedDynamicObjects [k]];
                        long minFastDist = body.Radius + radius;
                        //unnormalized distance value for comparison
                        minFastDist *= minFastDist;

                        if (body.Position.FastDistance(position) <= minFastDist)
                        {
                            //Body touches circle!
                            output.Add(body);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public static IEnumerable <LSBody> RaycastAll(Vector2d start, Vector2d end)
 {
     LSBody.PrepareAxisCheck(start, end);
     foreach (FractionalLineAlgorithm.Coordinate coor in
              GetRelevantNodeCoordinates(start, end))
     {
         int indexX = coor.X;
         int indexY = coor.Y;
         if (!Partition.CheckValid(coor.X, coor.Y))
         {
             break;
         }
         PartitionNode node = Partition.GetNode(indexX, indexY);
         for (int i = node.ContainedObjects.Count - 1; i >= 0; i--)
         {
             LSBody body = PhysicsManager.SimObjects [node.ContainedObjects [i]];
             if (body.Overlaps())
             {
                 yield return(body);
             }
         }
     }
     yield break;
 }