Advertisement
Guest User

Quadtree.h

a guest
Apr 26th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #ifndef QUADTREE_H
  2. #define QUADTREE_H
  3.  
  4. #include <SFML/Graphics.hpp>
  5. #include "Boundable.h"
  6. #include <set>
  7. #include <algorithm>
  8.  
  9.  
  10. class Quadtree
  11. {
  12.     public:
  13.     typedef std::pair<Boundable*, Boundable*> Pair;
  14.  
  15. public:
  16.     Quadtree(sf::FloatRect bounds = sf::FloatRect(0,0,800,600), Quadtree* parent = nullptr);
  17.  
  18.     void drawDebugRect(sf::RenderTarget& target);
  19.  
  20.     void insertObject(Boundable* object);
  21.     void removeObject(Boundable* object);
  22.  
  23.     std::set<Pair> collisionPairs();
  24.     int                     count();
  25.  
  26.     static int           getObjectLimit();
  27.     static void setObjectLimit(int limit);
  28.  
  29.     void manage();
  30.  
  31.     void clear();
  32.  
  33.     private:
  34.  
  35.     void                        updateAll();
  36.     void                        subdivide();
  37.     void                     removeWrecks();
  38.     bool               isMarkedForRemoval();
  39.     bool      intersects(Boundable* object);
  40.     int      getObjIndex(Boundable* object);
  41.  
  42.  
  43.     int                                                         getLocalObjectCount();
  44.     void                                              getTotalObjectCount(int& count);
  45.     void                                           getOldestParent(Quadtree*& parent);
  46.     void                             getCollisionPairs(std::set<Pair> & collisionSet);
  47.     void getCollisionPairsFromChildren(std::set<Pair> & collisionSet, Boundable* obj);
  48.  
  49.     private:
  50.     Boundable*         node = nullptr;
  51.     Quadtree*                mParent;
  52.     std::vector<Quadtree*> mChildren;
  53.     std::vector<Boundable*> mObjects;
  54.  
  55.     static int MAX_OBJECTS;
  56.  
  57.     sf::RectangleShape mDebugRect;
  58.  
  59.     sf::FloatRect mAABB;
  60.  
  61. };
  62.  
  63. bool isColliding(Boundable* obj1, Boundable* obj2);
  64.  
  65. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement