Exemplo n.º 1
0
        public void AddParticle(BlobParticle particle)
        {
            int x = Convert.ToInt32(Math.Floor(particle.pX / gridSize));
            int y = Convert.ToInt32(Math.Floor(particle.pY / gridSize));

            if (y < 0)
            {
                y = 0;
            }
            else if (y > height)
            {
                y = height;
            }

            if (x < 0)
            {
                x = 0;
            }
            else if (x > width)
            {
                x = width;
            }

            grid[y][x].Add(particle);
            numElements++;
        }
Exemplo n.º 2
0
 public Spring(float springLength, BlobParticle parentParticle, BlobParticle childParticle)
 {
     this.springLength   = springLength;
     this.parentParticle = parentParticle;
     this.childParticle  = childParticle;
     this.restLength     = springLength;
 }
Exemplo n.º 3
0
        public void addParticle()
        {
            Random RandomGenerator = new Random();

            float randomXVelocity = RandomGenerator.Next(20);
            float randomYVelocity = RandomGenerator.Next(20);

            BlobParticle theParticle = new BlobParticle(new Vector2(300, 100), theParticles.Count, theSprite);

            theParticle.vX = randomXVelocity / 20 - 0.5f;
            theParticle.vY = randomYVelocity / 20 - 0.5f;

            theParticles.Add(theParticle);

            theGrid.AddParticle(theParticle);
        }
Exemplo n.º 4
0
        public List <BlobParticle> GetNeighbours(BlobParticle particle)
        {
            int x = Convert.ToInt32(Math.Floor(particle.pX / gridSize));
            int y = Convert.ToInt32(Math.Floor(particle.pY / gridSize));

            if (y < 0)
            {
                y = 0;
            }
            else if (y > height)
            {
                y = height;
            }

            if (x < 0)
            {
                x = 0;
            }
            else if (x > width)
            {
                x = width;
            }

            float checkX = particle.pX - (x * gridSize);
            float checkY = particle.pY - (y * gridSize);

            List <BlobParticle> returnList = new List <BlobParticle>();

            // if (checkX == quadrantMarker || checkY == quadrantMarker)
            // {
            // If the particle is *exactly* on the centre line, go with normal code for now
            for (int i = y - (y == 0 ? 0 : 1); i < y + (y == height ? 0 : 1); i++)
            {
                for (int j = x - (x == 0 ? 0 : 1); j < x + (x == width ? 0 : 1); j++)
                {
                    if (grid[i][j] != null)
                    {
                        returnList.AddRange(grid[i][j]);

                        //for (int p = 0; p < grid[i][j].Count; p++)
                        //{
                        //    returnList.Add(grid[i][j][p]);
                        //}
                    }
                }
            }
            // }

            /*
             * else
             * {
             *  // Figure out which quadrant it's in, and go from there.  Can simplify this later, cant be arsed writing that fancy s***e!
             *  if (checkX < quadrantMarker && checkY < quadrantMarker)
             *  {
             *      // 1
             *      // Needs to check : (x-1,y-1), (x,y-1), (x-1,y), and (x,y)
             *      for (int i = y - (y == 0 ? 0 : 1); i < y; i++)
             *      {
             *          for (int j = x - (x == 0 ? 0 : 1); j < x; j++)
             *          {
             *              if (grid[i][j] != null && grid[i][j].Count > 0)
             *              {
             *                  returnList.AddRange(grid[i][j]);
             *              }
             *          }
             *      }
             *  }
             *  else if (checkX > quadrantMarker && checkY < quadrantMarker)
             *  {
             *      // 2
             *      // Needs to check (x,y-1), (x+1,y-1), (x+1,y), and (x,y)
             *      for (int i = y - (y == 0 ? 0 : 1); i < y; i++)
             *      {
             *          for (int j = x; j < x + (y == width ? 0 : 1); j++)
             *          {
             *              if (grid[i][j] != null && grid[i][j].Count > 0)
             *              {
             *                  returnList.AddRange(grid[i][j]);
             *              }
             *          }
             *      }
             *  }
             *  else if (checkX < quadrantMarker && checkY > quadrantMarker)
             *  {
             *      // 3
             *      // Needs to check (x-1,y), (x-1,y+1), (x,y+1), and (x,y)
             *      for (int i = y; i < y + (y == height ? 0 : 1); i++)
             *      {
             *          for (int j = x - (x == 0 ? 0 : 1); j < x; j++)
             *          {
             *              if (grid[i][j] != null && grid[i][j].Count > 0)
             *              {
             *                  returnList.AddRange(grid[i][j]);
             *              }
             *          }
             *      }
             *  }
             *  else if (checkX > quadrantMarker && checkY > quadrantMarker)
             *  {
             *      // 4
             *      // Needs to check (x,y+1), (x+1,y+1), (x+1,y), and (x,y)
             *      for (int i = y; i < y + (y == height ? 0 : 1); i++)
             *      {
             *          for (int j = x; j < x + (y == width ? 0 : 1); j++)
             *          {
             *              if (grid[i][j] != null && grid[i][j].Count > 0)
             *              {
             *                  returnList.AddRange(grid[i][j]);
             *              }
             *          }
             *      }
             *  }
             * }*/

            /*List<BlobParticle> returnList = new List<BlobParticle>();
             *
             * for (int i = 0; i < grid.Length; i++)
             * {
             *  for (int j = 0; j < grid[i].Length; j++)
             *  {
             *      if (grid[i][j] != null)
             *      {
             *          for (int p = 0; p < grid[i][j].Count; p++)
             *          {
             *              returnList.Add(grid[i][j][p]);
             *          }
             *      }
             *  }
             * }*/

            returnList.Remove(particle);

            return(returnList);
        }
Exemplo n.º 5
0
 public Neighbour(BlobParticle theParticle)
 {
     this.theParticle = theParticle;
 }