You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,13 @@ When doing game development you've all come across a point when you'd like to do
50
50
The problem is that the number of checks grow very fast (N² for N sprites) when the number of your sprites grow.
51
51
52
52
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.
54
58
59
+
## Getting Started
55
60
The first thing is: You have to set-up a grid. Usually you'd take your game-coordinate-system's bounds.
56
61
Then you have to tell the grid how many cells it has by setting the number of cells on the X and Y axis.
57
62
@@ -68,8 +73,9 @@ Then you may add your sprites or other objects to the grid by calling `Add(objec
68
73
By specifying this you tell the grid that you mean the cell that contains these game-coordinates.
69
74
#### Rectangle
70
75
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).
73
79
#### Rect
74
80
This is a special parameter in our utility-package. It's essentially a Rectangle, but with all float parameters.
75
81
By specifying this you give the grid a rectangle in the game-coordinate-system.
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.
130
148
149
+
...when reading the explanation of the CollisionGrid.
0 commit comments