#include <Moof/Aabb.hh>
#include <Moof/Drawable.hh>
#include <Moof/Entity.hh>
+#include <Moof/Log.hh>
#include <Moof/Math.hh>
#include <Moof/Sphere.hh>
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()
{
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();
}
}
- static bool compareZOrder(EntityPtr a, EntityPtr b)
+ static bool compareZOrder(EntityP a, EntityP b)
{
return a->getSphere().point[2] < b->getSphere().point[2];
}
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