#ifndef __VIEWCELLSTREE #define __VIEWCELLSTREE #include #include "Pvs.h" #include "AxisAlignedBox3.h" #include "common.h" namespace CHCDemoEngine { /** basic view cell structure */ struct ViewCell { public: ViewCell(): mPvs() {} int GetId() const { return mId; } void SetId(int id) { mId = id; } void SetBox(const AxisAlignedBox3 &box) { mBox = box; } AxisAlignedBox3 GetBox() const { return mBox; } // the pvs associated with the viewcell Pvs mPvs; protected: // id of this viewcell int mId; // bounding box of the viewcell AxisAlignedBox3 mBox; }; struct ViewCellsTreeNode { ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {} bool IsLeaf() { return mAxis == -1; } /////////////////////// /// split mAxis int mAxis; union { // split position - 4B float mPosition; // the viewcell associated with this node (NULL for non terminal nodes) ViewCell *mViewCell; }; /// children of the node ViewCellsTreeNode *mBack; ViewCellsTreeNode *mFront; }; class ViewCellsTree { friend class VisibilitySolutionLoader; public: ViewCellsTree(): mRoot(NULL) {} void SubdivideNode(ViewCellsTreeNode *node, const AxisAlignedBox3 &box, int depth); int CastLineSegment(const Vector3 &origin, const Vector3 &termination, ViewCell **viewcells); ViewCell *GetViewCell(const Vector3 &point) const; /** Hack: Sometimes the scene has to be scaled, then also the view cells must be scaled accordingly. */ bool LoadFromFile(const std::string &filename, float scaleFactor = 1.0f); protected: bool _LoadFromFile(FILE *file, float scaleFactor); //////////////////////// int mMaxDepth; AxisAlignedBox3 mBox; ViewCellsTreeNode *mRoot; }; } #endif