public UniformGridBroadphase(int width, int height, int cellSize) : this() { Width = width; Height = height; CellSize = cellSize; CellsHigh = Height / cellSize; CellsWide = Width / cellSize; TotalCells = CellsHigh * CellsWide; Offset = new Point(width / 2, height / 2); _invCellSize = 1f / (float)cellSize; _pairs = new OverlappingPairCache(); _cells = new GridCell[TotalCells]; for (int i = 0; i < _cells.Length; i++) { _cells[i] = new GridCell(); } neighbourOffset = new int[] { -CellsWide - 1, // top-left -CellsWide, // top -CellsWide + 1, // top-right -1, // left 0, 1, // right CellsWide - 1, // bottom-left CellsWide, // bottom CellsWide + 1, // bottom-right }; }
public void SolveCollisions(OverlappingPairCache overlappingPairs) { CollisionGlobals.NarrowphaseDetections = 0; foreach (OverlappingPair pair in overlappingPairs._pairs) { CollisionResult result; CollisionBody colA = pair.ProxyA.ClientObject as CollisionBody; CollisionBody colB = pair.ProxyB.ClientObject as CollisionBody; // calculates the collision result if there's an algorithm that matches the pair of shapes. SolveCollision(colA, colB, out result); // handle collision events and resolve shape penetration. if (result.IsColliding) { CollisionGlobals.Results.Push(result); // translate the body to a safe non-penetrating position. if ((result.Us.Flags & CollisionFlags.Response) != 0) result.Us.Position += result.CollisionResponse; if ((result.Them.Flags & CollisionFlags.Response) != 0) result.Them.Position += -result.CollisionResponse; // handle collision events if (colA.OnCollision != null) colA.OnCollision(colB, Vector2.Zero); if (colB.OnCollision != null) colB.OnCollision(colA, Vector2.Zero); CollisionGlobals.NarrowphaseDetections++; } } }
public UniformGridBroadphase(int width, int height, int cellSize) : this() { Width = width; Height = height; CellSize = cellSize; CellsHigh = Height / cellSize; CellsWide = Width / cellSize; TotalCells = CellsHigh * CellsWide; Offset = new Point(width / 2, height / 2); _invCellSize = 1f / (float)cellSize; _pairs = new OverlappingPairCache(); _cells = new GridCell[TotalCells]; for (int i = 0; i < _cells.Length; i++) _cells[i] = new GridCell(); neighbourOffset = new int[] { -CellsWide - 1, // top-left -CellsWide, // top -CellsWide + 1, // top-right -1, // left 0, 1, // right CellsWide - 1, // bottom-left CellsWide, // bottom CellsWide + 1, // bottom-right }; }
public void SolveCollisions(OverlappingPairCache overlappingPairs) { CollisionGlobals.NarrowphaseDetections = 0; foreach (OverlappingPair pair in overlappingPairs._pairs) { CollisionResult result; CollisionBody colA = pair.ProxyA.ClientObject as CollisionBody; CollisionBody colB = pair.ProxyB.ClientObject as CollisionBody; // calculates the collision result if there's an algorithm that matches the pair of shapes. SolveCollision(colA, colB, out result); // handle collision events and resolve shape penetration. if (result.IsColliding) { CollisionGlobals.Results.Push(result); // translate the body to a safe non-penetrating position. if ((result.Us.Flags & CollisionFlags.Response) != 0) { result.Us.Position += result.CollisionResponse; } if ((result.Them.Flags & CollisionFlags.Response) != 0) { result.Them.Position += -result.CollisionResponse; } // handle collision events if (colA.OnCollision != null) { colA.OnCollision(colB, Vector2.Zero); } if (colB.OnCollision != null) { colB.OnCollision(colA, Vector2.Zero); } CollisionGlobals.NarrowphaseDetections++; } } }
public BruteForceBroadphase() { _pairs = new OverlappingPairCache(); }
public BruteForceBroadphase() { _pairs = new OverlappingPairCache(); }
public UniformGridBroadphase() { // keep the collision from complaining if the 'world' isn't defined. _pairs = new OverlappingPairCache(); _cells = new GridCell[0]; }
public UniformGridBroadphase() { // keep the collision from complaining if the 'world' isn't defined. _pairs = new OverlappingPairCache(); _cells = new GridCell[0]; }