Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef QUADTREE_H
- #define QUADTREE_H
- #include <SFML/Graphics.hpp>
- #include "Boundable.h"
- #include <set>
- #include <algorithm>
- class Quadtree
- {
- public:
- typedef std::pair<Boundable*, Boundable*> Pair;
- public:
- Quadtree(sf::FloatRect bounds = sf::FloatRect(0,0,800,600), Quadtree* parent = nullptr);
- void drawDebugRect(sf::RenderTarget& target);
- void insertObject(Boundable* object);
- void removeObject(Boundable* object);
- std::set<Pair> collisionPairs();
- int count();
- static int getObjectLimit();
- static void setObjectLimit(int limit);
- void manage();
- void clear();
- private:
- void updateAll();
- void subdivide();
- void removeWrecks();
- bool isMarkedForRemoval();
- bool intersects(Boundable* object);
- int getObjIndex(Boundable* object);
- int getLocalObjectCount();
- void getTotalObjectCount(int& count);
- void getOldestParent(Quadtree*& parent);
- void getCollisionPairs(std::set<Pair> & collisionSet);
- void getCollisionPairsFromChildren(std::set<Pair> & collisionSet, Boundable* obj);
- private:
- Boundable* node = nullptr;
- Quadtree* mParent;
- std::vector<Quadtree*> mChildren;
- std::vector<Boundable*> mObjects;
- static int MAX_OBJECTS;
- sf::RectangleShape mDebugRect;
- sf::FloatRect mAABB;
- };
- bool isColliding(Boundable* obj1, Boundable* obj2);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement