X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FOctree.hh;h=186961f00e7b3d28a55ea7e6bef9a69c7aceb945;hp=774eece11c56cb34236a82d2b23ce6f501765351;hb=7e898e8ec0ff716e2fc722b883a626a6c346f107;hpb=fdfba4553433b9b2804c2772c7645211b828c2ea diff --git a/src/Moof/Octree.hh b/src/Moof/Octree.hh index 774eece..186961f 100644 --- a/src/Moof/Octree.hh +++ b/src/Moof/Octree.hh @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -46,7 +47,14 @@ namespace Mf { -class Camera; +class Frustum; + + +struct OctreeNode; +typedef stlplus::ntree::iterator OctreeNodeP; + +class Octree; +typedef boost::shared_ptr OctreeP; struct OctreeNode : public Entity @@ -80,13 +88,13 @@ struct OctreeNode : public Entity aabb_.draw(); // temporary } - void drawIfVisible(Scalar alpha, const Camera& cam) const + void drawIfVisible(Scalar alpha, const Frustum& frustum) const { std::list::const_iterator it; for (it = objects.begin(); it != objects.end(); ++it) { - (*it)->drawIfVisible(alpha, cam); + (*it)->drawIfVisible(alpha, frustum); } if (!objects.empty()) @@ -94,11 +102,11 @@ struct OctreeNode : public Entity } - 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; @@ -118,25 +126,27 @@ struct OctreeNode : public Entity }; -class Octree; -typedef boost::shared_ptr OctreeP; - class Octree { - stlplus::ntree::iterator - insert(stlplus::ntree::iterator node, EntityP entity); + OctreeNodeP insert(EntityP entity, OctreeNodeP node); - void addChild(stlplus::ntree::iterator node, int index); + void addChild(OctreeNodeP node, int index); - void draw(stlplus::ntree::iterator node, Scalar alpha); - void drawIfVisible(stlplus::ntree::iterator node, - Scalar alpha, const Camera& cam); + void draw(Scalar alpha, OctreeNodeP node); + void drawIfVisible(Scalar alpha, const Frustum& frustum, OctreeNodeP node); stlplus::ntree tree_; public: - inline static OctreeP alloc(const OctreeNode& rootNode) + void print(OctreeNodeP node) + { + //logDebug("-----"); + //logDebug("depth to node: %d", tree_.depth(node)); + //logDebug("size of node: %d", tree_.size(node)); + } + + static OctreeP alloc(const OctreeNode& rootNode) { return OctreeP(new Octree(rootNode)); } @@ -146,17 +156,16 @@ public: tree_.insert(rootNode); } - stlplus::ntree::iterator insert(EntityP entity) + OctreeNodeP insert(EntityP entity) { - return insert(tree_.root(), entity); + return insert(entity, tree_.root()); } - stlplus::ntree::iterator reinsert(EntityP entity, - stlplus::ntree::iterator node); + OctreeNodeP reinsert(EntityP entity, OctreeNodeP node); - void drawIfVisible(Scalar alpha, const Camera& cam) + void drawIfVisible(Scalar alpha, const Frustum& frustum) { - drawIfVisible(tree_.root(), alpha, cam); + drawIfVisible(alpha, frustum, tree_.root()); } void sort();