X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FOctree.hh;h=ade0a026fdddc13e4507c88a9605e7f28bfd959f;hp=d896844f0379a4ab7ca1cebe32d52cb5a719a775;hb=57b78ebe21b1b48acd337daa5a1cb8c383959cfa;hpb=bfa6212d09d8735d8fd5e2638188e4a99f21ada4 diff --git a/src/Moof/Octree.hh b/src/Moof/Octree.hh index d896844..ade0a02 100644 --- a/src/Moof/Octree.hh +++ b/src/Moof/Octree.hh @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -49,9 +50,16 @@ namespace Mf { class Camera; +struct OctreeNode; +typedef stlplus::ntree::iterator OctreeNodeP; + +class Octree; +typedef boost::shared_ptr OctreeP; + + struct OctreeNode : public Entity { - std::list objects; + std::list objects; OctreeNode() { @@ -69,28 +77,28 @@ struct OctreeNode : public Entity void draw(Scalar alpha) const { - std::list::const_iterator it; + std::list::const_iterator it; for (it = objects.begin(); it != objects.end(); ++it) { (*it)->draw(alpha); } - //if (!objects.empty()) - //aabb_.draw(); // temporary + if (!objects.empty()) + aabb_.draw(); // temporary } void drawIfVisible(Scalar alpha, const Camera& cam) const { - std::list::const_iterator it; + std::list::const_iterator it; for (it = objects.begin(); it != objects.end(); ++it) { (*it)->drawIfVisible(alpha, cam); } - //if (!objects.empty()) - //aabb_.draw(); + if (!objects.empty()) + aabb_.draw(); } @@ -105,7 +113,7 @@ struct OctreeNode : public Entity } - static bool compareZOrder(EntityPtr a, EntityPtr b) + static bool compareZOrder(EntityP a, EntityP b) { return a->getSphere().point[2] < b->getSphere().point[2]; } @@ -120,42 +128,49 @@ struct OctreeNode : public Entity class Octree { + OctreeNodeP insert(EntityP entity, OctreeNodeP node); + + void addChild(OctreeNodeP node, int index); + + void draw(Scalar alpha, OctreeNodeP node); + void drawIfVisible(Scalar alpha, const Camera& cam, OctreeNodeP node); + + stlplus::ntree tree_; + public: + inline void print(OctreeNodeP node) + { + //logDebug("-----"); + //logDebug("depth to node: %d", tree_.depth(node)); + //logDebug("size of node: %d", tree_.size(node)); + } + + inline static OctreeP alloc(const OctreeNode& rootNode) + { + return OctreeP(new Octree(rootNode)); + } + explicit Octree(const OctreeNode& rootNode) { tree_.insert(rootNode); } - stlplus::ntree::iterator insert(EntityPtr entity) + OctreeNodeP insert(EntityP entity) { - return insert(tree_.root(), entity); + return insert(entity, tree_.root()); } - stlplus::ntree::iterator reinsert(EntityPtr entity, - stlplus::ntree::iterator node); + OctreeNodeP reinsert(EntityP entity, OctreeNodeP node); void drawIfVisible(Scalar alpha, const Camera& cam) { - drawIfVisible(tree_.root(), alpha, cam); + drawIfVisible(alpha, cam, tree_.root()); } void sort(); - -private: - stlplus::ntree::iterator insert(stlplus::ntree::iterator node, EntityPtr entity); - - void addChild(stlplus::ntree::iterator node, int index); - - void draw(stlplus::ntree::iterator node, Scalar alpha); - void drawIfVisible(stlplus::ntree::iterator node, - Scalar alpha, const Camera& cam); - - stlplus::ntree tree_; }; -typedef boost::shared_ptr OctreePtr; - } // namespace Mf