]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Octree.hh
added missing octree method
[chaz/yoink] / src / Moof / Octree.hh
index 774eece11c56cb34236a82d2b23ce6f501765351..e3e2225f03299636137b21aa3a54aeb38fd25b38 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>
        
 namespace Mf {
 
 
-class Camera;
+class Frustum;
+
+
+struct OctreeNode;
+typedef stlplus::ntree<OctreeNode>::iterator OctreeNodeP;
+
+class Octree;
+typedef boost::shared_ptr<Octree> OctreeP;
 
 
 struct OctreeNode : public Entity
@@ -80,25 +88,28 @@ 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<EntityP>::const_iterator it;
 
                for (it = objects.begin(); it != objects.end(); ++it)
                {
-                       (*it)->drawIfVisible(alpha, cam);
+                       (*it)->drawIfVisible(alpha, frustum);
                }
 
                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;
@@ -118,25 +129,27 @@ struct OctreeNode : public Entity
 };
 
 
-class Octree;
-typedef boost::shared_ptr<Octree> OctreeP;
-
 class Octree
 {
-       stlplus::ntree<OctreeNode>::iterator
-               insert(stlplus::ntree<OctreeNode>::iterator node, EntityP entity);
+       OctreeNodeP insert(EntityP entity, OctreeNodeP node);
        
-       void addChild(stlplus::ntree<OctreeNode>::iterator node, int index);
+       void addChild(OctreeNodeP node, int index);
 
-       void draw(stlplus::ntree<OctreeNode>::iterator node, Scalar alpha);
-       void drawIfVisible(stlplus::ntree<OctreeNode>::iterator node,
-                       Scalar alpha, const Camera& cam);
+       void draw(Scalar alpha, OctreeNodeP node);
+       void drawIfVisible(Scalar alpha, const Frustum& frustum, OctreeNodeP node);
 
        stlplus::ntree<OctreeNode> 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 +159,21 @@ public:
                tree_.insert(rootNode);
        }
 
-       stlplus::ntree<OctreeNode>::iterator insert(EntityP entity)
+       OctreeNodeP insert(EntityP entity)
        {
-               return insert(tree_.root(), entity);
+               return insert(entity, tree_.root());
        }
 
-       stlplus::ntree<OctreeNode>::iterator reinsert(EntityP entity,
-                       stlplus::ntree<OctreeNode>::iterator node);
+       OctreeNodeP reinsert(EntityP entity, OctreeNodeP node);
+
+       void draw(Scalar alpha)
+       {
+               draw(alpha, tree_.root());
+       }
 
-       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();
This page took 0.022183 seconds and 4 git commands to generate.