#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
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())
}
- 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;
};
-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));
}
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 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();