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
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,11 +14,11 @@ If you want to contribute to our repository (push, open pull requests), please u
14
14
# CollisionGrid
15
15
16
16
This class implements a collision-grid.
17
-
When doing game development you've all come across a point when you'd like to do some collision-checks and that's usually the time when you realize that just checking all sprites against each other just doesn't cut it.
18
-
The problem is that the number of checks grow very fast (N² for N sprites) when the number of your sprites grow.
17
+
When doing game development you've probably come across a point when you'd liked to do some collision-checks and that's usually the time when you've realize that just checking all sprites against each other doesn't cut it.
18
+
The problem with that brute-force-approach is, that the number of checks grow very fast (N² for N sprites) when the number of your sprites increase.
19
19
20
-
So you somehow have to narrow down your collision-candidates.
21
-
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...
20
+
So you somehow have to narrow down your collision-candidates.
21
+
This piece of software does that for you. It does not do the collision checks themself. It just tells you if a sprite may be near enough to a second one to maybe collide with it, which allows you to do a collision test for those two, or three, or five sprites instead of the whole bunch.
22
22
## What It Really Does...
23
23
...is a simple trade-off.
24
24
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.
Maybe you've heard of such a data-structure that does essentially exactly the same things as this grid with one major difference:
107
107
108
-
The QuadTree divides the space itself.
109
-
It doesn't need a fixed grid, but divides it unevenly and only when another partition is needed.
110
-
And that's good and bad at the same time.
111
-
Unfortunately that costs a lot of time (the updating of this data-structure); At least when compared to the grid.
112
-
[Here's a very good implementation on GitHub with an excellent explanation what it does.][quadtree]
108
+
The QuadTree divides the space all by itself, dynamically whenever you add new items.
109
+
It doesn't need a fixed uniform grid, but divides space unevenly and only when another partition is needed.
110
+
And that's good and bad at the same time.
111
+
The good thing is that it can cope with unevenly distributed items very well.
112
+
The bad thing is that it costs a lot more time (the updating of this data-structure); At least when compared to this grid here.
113
+
[Here's a very good implementation of a QuadTree on GitHub with an excellent explanation what it exactly does.][quadtree]
113
114
114
-
The good news about the QuadTree is that it's exactly what you're looking for if you thought...
115
-
> 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.
115
+
The good news about the QuadTree is that it's exactly what you're looking for if you are thinking...
116
+
> 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 to segment those clusters in a helpful way.
116
117
117
118
...when reading the explanation of the CollisionGrid.
0 commit comments