public List <PhysicsObject> GetNeighbours(BlobParticle particle) { if (!setup) { throw new Exception("SetDimensions must be called first!"); } int x = (int)(particle.Position.X / gridSize); int y = (int)(particle.Position.Y / gridSize); List <PhysicsObject> returnList = new List <PhysicsObject>(100); /*for (int i = x - (x == 0 ? 0 : 1); i <= x + (x == width + 1 ? 0 : 1); i++) * { * for (int j = y - (y == 0 ? 0 : 1); j <= y + (y == height + 1 ? 0 : 1); j++) * { * returnList.AddRange(grid[i][j]); * } * }*/ int xStart = x - 1; int xEnd = x + 1; int yStart = y - 1; int yEnd = y + 1; if (xStart <= 0) { xStart = 0; } if (xEnd >= width) { xEnd = width; } if (yStart <= 0) { yStart = 0; } if (yEnd >= height) { yEnd = height; } for (int i = xStart; i <= xEnd; i++) { for (int j = yStart; j <= yEnd; j++) { returnList.AddRange(grid[i][j].Values); } } returnList.Remove(particle); return(returnList); }
public Spring(BlobParticle object1, BlobParticle object2, float springConstant, float springLength, float frictionConstant) { this.object1 = object1; this.object2 = object2; this.springConstant = springConstant; this.springLength = springLength; this.frictionConstant = frictionConstant; }
public float CalculateFieldStrength(BlobParticle particle, Vector2 point) { float fieldStrength = 0.0f; float distance = Vector2.Distance(particle.Position, point); if (distance < particle.radiusSquared) { fieldStrength = 1.0f; } return(fieldStrength); }
public void addParticles(int num) { for (int i = 0; i < num; i++) { Random RandomGenerator = new Random(); float randomXVelocity = 5; Vector2 mousePos = camera.MouseToWorld(); float xPos = mousePos.X; float yPos = mousePos.Y; if (xPos < drawingOffset) { xPos = drawingOffset + 1; } else if (xPos > 800 - drawingOffset) { xPos = 800 - drawingOffset - 1; } if (yPos < 0) { yPos = 1; } else if (yPos > 500) { yPos = 499; } BlobParticle theParticle = new BlobParticle(Game, new Vector2(xPos, yPos), theSprite, PhysicsOverlord.GetInstance().GetID(), particleRadius); theParticle.colour = Color.Red; theParticle.velocity = new Vector2(5, 5); theParticles.Add(theParticle); SpatialGrid.GetInstance().AddObject(theParticle); particleCount++; currentNumParticles--; } }
private void simpleCollisionDetection(BlobParticle theParticle) { if (theParticle.Position.X < 0 + drawingOffset) { theParticle.velocity.X *= -0.5f; if (theParticle.velocity.X < 2.0f && theParticle.velocity.X > -2.0f) { theParticle.velocity.X = 0.0f; } theParticle.Position.X = 0 + drawingOffset; } else if (theParticle.Position.X > 800 - drawingOffset) { theParticle.velocity.X *= -0.5f; if (theParticle.velocity.X < 2.0f && theParticle.velocity.X > -2.0f) { theParticle.velocity.X = 0.0f; } theParticle.Position.X = 800 - drawingOffset; } if (theParticle.Position.Y < 0) { theParticle.velocity.Y *= -0.5f; theParticle.Position.Y = 1; } else if (theParticle.Position.Y > 500) { theParticle.velocity.Y *= -0.5f; if (theParticle.velocity.Y < 2.0f && theParticle.velocity.Y > -2.0f) { theParticle.velocity.Y = 0.0f; } theParticle.Position.Y = 500; } }
public void removeNeighbour(BlobParticle theNeighbour) { neighbours.Remove(theNeighbour); }
public void addNeighbour(BlobParticle theNeighbour) { neighbours.Add(theNeighbour); }