X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FOctree.hh;h=e3e2225f03299636137b21aa3a54aeb38fd25b38;hp=d896844f0379a4ab7ca1cebe32d52cb5a719a775;hb=660e768e64c2c30928c7f157d5ff34195a4347fa;hpb=bfa6212d09d8735d8fd5e2638188e4a99f21ada4 diff --git a/src/Moof/Octree.hh b/src/Moof/Octree.hh index d896844..e3e2225 100644 --- a/src/Moof/Octree.hh +++ b/src/Moof/Octree.hh @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -46,12 +47,19 @@ namespace Mf { -class Camera; +class Frustum; + + +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,43 +77,46 @@ 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 + void drawIfVisible(Scalar alpha, const Frustum& frustum) const { - std::list::const_iterator it; + std::list::const_iterator it; for (it = objects.begin(); it != objects.end(); ++it) { - (*it)->drawIfVisible(alpha, cam); + (*it)->drawIfVisible(alpha, frustum); } - //if (!objects.empty()) - //aabb_.draw(); + if (!objects.empty()) + { + aabb_.draw(); + //sphere_.draw(); + } } - bool isVisible(const Camera& cam) const + bool isVisible(const Frustum& frustum) const { - if (sphere_.isVisible(cam)) + if (sphere_.isVisible(frustum)) { - return aabb_.isVisible(cam); + return aabb_.isVisible(frustum); } return false; } - 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 +131,54 @@ 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 Frustum& frustum, OctreeNodeP node); + + stlplus::ntree tree_; + public: - explicit Octree(const OctreeNode& rootNode) + void print(OctreeNodeP node) { - tree_.insert(rootNode); + //logDebug("-----"); + //logDebug("depth to node: %d", tree_.depth(node)); + //logDebug("size of node: %d", tree_.size(node)); } - stlplus::ntree::iterator insert(EntityPtr entity) + static OctreeP alloc(const OctreeNode& rootNode) { - return insert(tree_.root(), entity); + return OctreeP(new Octree(rootNode)); } - stlplus::ntree::iterator reinsert(EntityPtr entity, - stlplus::ntree::iterator node); + explicit Octree(const OctreeNode& rootNode) + { + tree_.insert(rootNode); + } - void drawIfVisible(Scalar alpha, const Camera& cam) + OctreeNodeP insert(EntityP entity) { - drawIfVisible(tree_.root(), alpha, cam); + return insert(entity, tree_.root()); } - void sort(); + OctreeNodeP reinsert(EntityP entity, OctreeNodeP node); -private: - stlplus::ntree::iterator insert(stlplus::ntree::iterator node, EntityPtr entity); - - void addChild(stlplus::ntree::iterator node, int index); + void draw(Scalar alpha) + { + draw(alpha, tree_.root()); + } - void draw(stlplus::ntree::iterator node, Scalar alpha); - void drawIfVisible(stlplus::ntree::iterator node, - Scalar alpha, const Camera& cam); + void drawIfVisible(Scalar alpha, const Frustum& frustum) + { + drawIfVisible(alpha, frustum, tree_.root()); + } - stlplus::ntree tree_; + void sort(); }; -typedef boost::shared_ptr OctreePtr; - } // namespace Mf