
#ifndef __WFX_SCENE_OCTREENODE_H__
#define __WFX_SCENE_OCTREENODE_H__

#include <WFX/WFXIncludes.h>
#include <WFX/scene/Node.h>
#include <WFX/scene/TriMesh.h>
#include <WFX/math/Cube.h>

namespace WFX {

    namespace scene {

        /** an Octree Node */
        class OctreeNode : public AbstractNode {
            public:
                static UInt Drawn;
                /** enum describing octree positions */
                enum  OctreeNodeID {
                    TOP_LEFT_FRONT = 0,
                    TOP_LEFT_BACK,
                    TOP_RIGHT_BACK,
                    TOP_RIGHT_FRONT,
                    BOTTOM_LEFT_FRONT,
                    BOTTOM_LEFT_BACK,
                    BOTTOM_RIGHT_BACK,
                    BOTTOM_RIGHT_FRONT
                };
                
                /**
                 * Ctor/Dtor
                 */
                OctreeNode(OctreeNodeID id);
                virtual ~OctreeNode();

                /**
                 * implement draw method
                 * from Spatial
                 */
                void draw(WFX::renderer::Renderer* r);
                /** updates */
                void updateDown();

                /** accept */
                void accept(WFX::scene::SceneGraphVisitor& v);

                /** sets the BoundingCube */
                void setBoundingCube(WFX::math::Cube* c);
               
                /** calculates a new BoundingCube for a child */
                WFX::math::Cube* calcBoundingCube(OctreeNodeID id);
                /** 
                 * adds a TriMesh to the Tree
                 * subdiv describes the numbers of subdivisions that
                 * alread happened
                 */
                void addTriMesh(TriMesh& m, UInt subdiv);

                /** add geometry */
                void addGeometry(Spatial* s);
                /** set a child node */
                void setChild(OctreeNode* n);
                /** returns number of Children */
                UInt childCount();
            protected:
            private:
                friend class SceneGraphSerializer;
                friend class SceneGraphPrinter;
                /** node id */
                OctreeNodeID NodeID;
                /** Bounding Cube */
                WFX::math::Cube* BoundingCube;
                /** Octree Childnodes */
                OctreeNode** Children;
                /** associated geometry */
                std::list<Spatial*> Geometry;
     
        };

    }

}


#endif //include guard


