Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_TREENODEOCT_H__
00009 #define __SP_TREENODEOCT_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spTreeNode.hpp"
00014
00015
00016 namespace sp
00017 {
00018 namespace scene
00019 {
00020
00021
00023 class SP_EXPORT OcTreeNode : public TreeNode
00024 {
00025
00026 public:
00027
00028 OcTreeNode(TreeNode* Parent = 0);
00029 ~OcTreeNode();
00030
00031
00032
00033 bool isLeaf() const;
00034
00035 void addChildren();
00036 void removeChildren();
00037
00047 void createTree(Mesh* Model, s8 ForksCount = DEF_TREENODE_FORKSCOUNT);
00048
00058 void createTree(const std::list<SceneNode*> &NodeList, s8 ForksCount = DEF_TREENODE_FORKSCOUNT);
00059
00068 void findTreeNodes(
00069 std::list<const OcTreeNode*> &TreeNodeList, const dim::vector3df &Pos
00070 ) const;
00071
00077 void findTreeNodes(
00078 std::list<const OcTreeNode*> &TreeNodeList, const dim::vector3df &Pos, const dim::vector3df &Radius
00079 ) const;
00080
00088 void findTreeNodes(
00089 std::list<const OcTreeNode*> &TreeNodeList, const dim::line3df &Ray
00090 ) const;
00091
00092
00093
00095 inline OcTreeNode* getChild(u32 Index) const
00096 {
00097 return (Children_ && Index < 8) ? Children_[Index] : 0;
00098 }
00099
00100 private:
00101
00102
00103
00104 void createChildren(
00105 OcTreeNode** pTreeNodeList, s8 &ForksCount,
00106 const dim::vector3df &Min, const dim::vector3df &Max, const s32 LineCount
00107 );
00108
00109 void placeTriangle(
00110 OcTreeNode** pTreeNodeList,
00111 const dim::ptriangle3df &TriangleLink, const u32 TriangleIndex, const u32 CurrentSurface,
00112 const dim::vector3di OffsetPos, const s32 LineCount
00113 );
00114
00115 void placeNode(
00116 OcTreeNode** pTreeNodeList, SceneNode* ObjNode,
00117 const dim::vector3di OffsetPos, const s32 LineCount
00118 );
00119
00120 dim::vector3di getPositionOffset(
00121 dim::vector3df Pos, const dim::vector3df &Min, const dim::vector3df &Max, const s32 LineCount
00122 ) const;
00123
00124 void clampTreeForks(s8 &ForksCount);
00125
00126
00127
00128 inline s32 getOffset(const dim::vector3di &Pos, const s32 LineCount) const
00129 {
00130 return Pos.Z * LineCount * LineCount + Pos.Y * LineCount + Pos.X;
00131 }
00132
00133
00134
00135 OcTreeNode** Children_;
00136
00137 dim::vector3df Min_, Max_;
00138
00139 };
00140
00141
00142 }
00143
00144 }
00145
00146
00147 #endif
00148
00149
00150
00151