Skip to content

Commit 9ac74a5

Browse files
author
psilo
committed
updated readme.md
1 parent b50e8a1 commit 9ac74a5

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ When doing game development you've all come across a point when you'd like to do
5050
The problem is that the number of checks grow very fast (N² for N sprites) when the number of your sprites grow.
5151

5252
So you somehow have to narrow down your collision-candidates.
53-
This piece of software does that for you. It does not do collision checking itself. It just tells you if a sprite is near enough to a second one to maybe collide which allows you to do a collision test for those two, or three, or five...
53+
This piece of software does that for you. It does not do collision checking itself. It just tells you if a sprite is near enough to a second one to maybe collide which allows you to do a collision test for those two, or three, or five...
54+
## What It Really Does...
55+
...is a simple trade-off.
56+
You may query it about the sprites around your coordinate or rectangle, but your sprites have to register with it and update their position/AABB on every update.
57+
But all in all this is a lot faster than a simple brute-force check.
5458

59+
## Getting Started
5560
The first thing is: You have to set-up a grid. Usually you'd take your game-coordinate-system's bounds.
5661
Then you have to tell the grid how many cells it has by setting the number of cells on the X and Y axis.
5762

@@ -68,8 +73,9 @@ Then you may add your sprites or other objects to the grid by calling `Add(objec
6873
By specifying this you tell the grid that you mean the cell that contains these game-coordinates.
6974
#### Rectangle
7075
This is a basic int-rectangle.
71-
It is not rotated and therefore axis-alinged. So it's an Axis-Aligned-Bounding-Box or AABB.
72-
By specifying this you give the grid a rectangle in the cell-coordinate-system (0-numberOfCellsX, 0-numberOfCellsY).
76+
It is not rotated and therefore axis-aligned. So it's an Axis-Aligned-Bounding-Box or AABB.
77+
By specifying this you give the grid a rectangle in the cell-coordinate-system
78+
(0-numberOfCellsX, 0-numberOfCellsY).
7379
#### Rect
7480
This is a special parameter in our utility-package. It's essentially a Rectangle, but with all float parameters.
7581
By specifying this you give the grid a rectangle in the game-coordinate-system.
@@ -127,9 +133,25 @@ protected override void UnloadContent()
127133
Grid.Dispose();
128134
}
129135
```
136+
137+
## So What's A QuadTree Then?
138+
Maybe you've heard of such a data-structure that does essentially exactly the same things as this grid with one major difference:
139+
140+
The QuadTree divides the space itself.
141+
It doesn't need a fixed grid, but divides it unevenly and only when another partition is needed.
142+
And that's good and bad at the same time.
143+
Unfortunately that costs a lot of time (the updating of this data-structure); At least when compared to the grid.
144+
[Here's a very good implementation on GitHub with an excellent explanation what it does.][quadtree]
145+
146+
The good news about the QuadTree is that it's exactly what you're looking for if you thought...
147+
> Oh! Nice thing this grid. But the space I have to check is REALLY BIG and my sprites are very unevenly distributed. Most of the time they are clustered with much space in between those clusters. So my cells become way too big for those clusters to help in any way.
130148
149+
...when reading the explanation of the CollisionGrid.
150+
151+
131152
[homepage]: http://www.unterrainer.info
132153
[coding]: http://www.unterrainer.info/Home/Coding
133154
[github]: https://github.com/UnterrainerInformatik/collisiongrid
155+
[quadtree]: https://github.com/ChevyRay/QuadTree
134156
[testrectangle]: https://github.com/UnterrainerInformatik/collisiongrid/blob/master/testrectangle.gif
135157
[testposition]: https://github.com/UnterrainerInformatik/collisiongrid/blob/master/testposition.gif

0 commit comments

Comments
 (0)