50class CollisionDetector;
55struct QuadTreeObject {
57 QuadTreeObject * next;
60 QuadTreeObject(QuadTreeObject * next_, Sprite * sprite_)
61 : owner(nullptr), next(next_), sprite(sprite_)
67#define QUADTREE_LEVEL_SPLIT_THRESHOLD 3
70enum QuadTreeQuadrant {
79typedef void (*CollisionDetectionCallback)(
void * callbackObj, Sprite * spriteA, Sprite * spriteB, Point collisionPoint);
86 QuadTree(CollisionDetector * collisionDetector, QuadTree * parent, QuadTreeQuadrant quadrant,
int x,
int y,
int width,
int height);
88 void insert(QuadTreeObject *
object);
90 static void remove(QuadTreeObject *
object);
94 QuadTreeObject * detectCollision(QuadTreeObject *
object, CollisionDetectionCallback callbackFunc =
nullptr,
void * callbackObj =
nullptr);
98 void detachFromParent();
100 static void update(QuadTreeObject *
object);
104 QuadTreeQuadrant getQuadrant(QuadTreeObject *
object);
105 void createQuadrant(QuadTreeQuadrant quadrant);
106 bool objectsIntersect(QuadTreeObject * objectA, QuadTreeObject * objectB);
107 bool objectIntersectsQuadTree(QuadTreeObject *
object, QuadTree * quadTree);
108 bool checkMaskCollision(QuadTreeObject * objectA, QuadTreeObject * objectB, Point * collisionPoint);
110 static bool objectInRect(QuadTreeObject *
object,
int x,
int y,
int width,
int height);
112 CollisionDetector * m_collisionDetector;
114 QuadTreeQuadrant m_quadrant;
119 QuadTreeObject * m_objects;
121 QuadTree * m_children[4];
135friend class QuadTree;
232 QuadTree * initEmptyQuadTree(QuadTree * parent, QuadTreeQuadrant quadrant,
int x,
int y,
int width,
int height);
235 QuadTree * m_rootQuadTree;
236 QuadTree * m_quadTreePool;
237 int m_quadTreePoolSize;
238 QuadTreeObject * m_objectPool;
239 int m_objectPoolSize;
void addSprite(Sprite *sprite)
Adds the specified sprite to collision detector.
CollisionDetector(int maxObjectsCount, int width, int height)
Creates an instance of CollisionDetector.
void update(Sprite *sprite)
Updates collision detector.
Sprite * updateAndDetectCollision(Sprite *sprite, bool removeCollidingSprites=true)
Updates collision detector and detect collision with the specified sprite.
void removeSprite(Sprite *sprite)
Removes the specified sprite from collision detector.
Sprite * detectCollision(Sprite *sprite, bool removeCollidingSprites=true)
Detects first collision with the specified sprite.
A class to detect sprites collisions.
This file contains fabgl::BitmappedDisplayController definition.
This file contains FabGL library configuration settings, like number of supported colors,...