]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Octree.hh
more cleanup
[chaz/yoink] / src / Moof / Octree.hh
index d896844f0379a4ab7ca1cebe32d52cb5a719a775..3614606fd911882dc96195cb28cedd3f83282120 100644 (file)
@@ -39,6 +39,7 @@
 #include <Moof/Aabb.hh>
 #include <Moof/Drawable.hh>
 #include <Moof/Entity.hh>
+#include <Moof/Log.hh>
 #include <Moof/Math.hh>
 #include <Moof/Sphere.hh>
        
@@ -49,9 +50,16 @@ namespace Mf {
 class Camera;
 
 
+struct OctreeNode;
+typedef stlplus::ntree<OctreeNode>::iterator OctreeNodeP;
+
+class Octree;
+typedef boost::shared_ptr<Octree> OctreeP;
+
+
 struct OctreeNode : public Entity
 {
-       std::list<EntityPtr> objects;
+       std::list<EntityP> objects;
 
        OctreeNode()
        {
@@ -69,28 +77,28 @@ struct OctreeNode : public Entity
 
        void draw(Scalar alpha) const
        {
-               std::list<EntityPtr>::const_iterator it;
+               std::list<EntityP>::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<EntityPtr>::const_iterator it;
+               std::list<EntityP>::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<OctreeNode> 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<OctreeNode>::iterator insert(EntityPtr entity)
+       OctreeNodeP insert(EntityP entity)
        {
-               return insert(tree_.root(), entity);
+               return insert(entity, tree_.root());
        }
 
-       stlplus::ntree<OctreeNode>::iterator reinsert(EntityPtr entity,
-                       stlplus::ntree<OctreeNode>::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<OctreeNode>::iterator insert(stlplus::ntree<OctreeNode>::iterator node, EntityPtr entity);
-       
-       void addChild(stlplus::ntree<OctreeNode>::iterator node, int index);
-
-       void draw(stlplus::ntree<OctreeNode>::iterator node, Scalar alpha);
-       void drawIfVisible(stlplus::ntree<OctreeNode>::iterator node,
-                       Scalar alpha, const Camera& cam);
-
-       stlplus::ntree<OctreeNode> tree_;
 };
 
-typedef boost::shared_ptr<Octree> OctreePtr;
-
 
 } // namespace Mf
 
This page took 0.023297 seconds and 4 git commands to generate.