1 | #include "OgreOctreeHierarchyInterface.h"
|
---|
2 | #include "OgreVisibilityOctreeSceneManager.h"
|
---|
3 | #include <OgreOctree.h>
|
---|
4 | #include <windows.h>
|
---|
5 |
|
---|
6 | namespace Ogre {
|
---|
7 | //namespace GtpVisibility {
|
---|
8 | //-----------------------------------------------------------------------
|
---|
9 | OctreeHierarchyInterface::OctreeHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
|
---|
10 | PlatformHierarchyInterface(sm, rsys)
|
---|
11 | {
|
---|
12 | }
|
---|
13 | //-----------------------------------------------------------------------
|
---|
14 | void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
|
---|
15 | {
|
---|
16 | mNumTraversedNodes ++;
|
---|
17 |
|
---|
18 | Octree *octree = static_cast<Octree *>(node);
|
---|
19 |
|
---|
20 | // if we come across some renderable geometry => render it
|
---|
21 | if (octree->mNodes.size() > 0)
|
---|
22 | {
|
---|
23 | RenderNode(node);
|
---|
24 | }
|
---|
25 |
|
---|
26 | // if not all subtrees are empty
|
---|
27 | if (octree->numNodes() > (int)octree->mNodes.size())
|
---|
28 | {
|
---|
29 | for(int i=0; i<8; ++i)
|
---|
30 | {
|
---|
31 | Octree *nextChild =
|
---|
32 | octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
|
---|
33 |
|
---|
34 | if (nextChild)
|
---|
35 | {
|
---|
36 | mDistanceQueue->push(nextChild);
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 | //-----------------------------------------------------------------------
|
---|
42 | bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
43 | {
|
---|
44 | Octree *octant = static_cast<Octree *>(node);
|
---|
45 |
|
---|
46 | for(int i=0; i<8; i++)
|
---|
47 | {
|
---|
48 | if (octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1])
|
---|
49 | return false;
|
---|
50 | }
|
---|
51 |
|
---|
52 | return true;
|
---|
53 | }
|
---|
54 | //-----------------------------------------------------------------------
|
---|
55 | bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
56 | {
|
---|
57 | return static_cast<Octree *>(node)->mNodes.size() > 0;
|
---|
58 | }
|
---|
59 | //-----------------------------------------------------------------------
|
---|
60 | void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)
|
---|
61 | {
|
---|
62 | mNumOctreeNodes = num;
|
---|
63 | }
|
---|
64 | //-----------------------------------------------------------------------
|
---|
65 | float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
66 | {
|
---|
67 | AxisAlignedBox *box = &static_cast<Octree *>(node)->mBox;
|
---|
68 | Vector3 mid = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum();
|
---|
69 |
|
---|
70 | return (mCamera->getDerivedPosition() - mid).squaredLength();
|
---|
71 | }
|
---|
72 | //-----------------------------------------------------------------------
|
---|
73 | void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
|
---|
74 | const bool visible)
|
---|
75 | {
|
---|
76 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
77 | static_cast<Octree *>(node)->setOctreeVisible(visible);
|
---|
78 | #endif
|
---|
79 | }
|
---|
80 | //-----------------------------------------------------------------------
|
---|
81 | void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
|
---|
82 | const unsigned int frameId)
|
---|
83 | {
|
---|
84 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
85 | static_cast<Octree *>(node)->setLastVisited(frameId);
|
---|
86 | #endif
|
---|
87 | }
|
---|
88 | //-----------------------------------------------------------------------
|
---|
89 | void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
|
---|
90 | {
|
---|
91 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
92 | Octree *octant = static_cast<Octree *>(node);
|
---|
93 |
|
---|
94 | while(octant && !octant->isOctreeVisible())
|
---|
95 | {
|
---|
96 | octant->setOctreeVisible(true);
|
---|
97 | octant = octant->getParent();
|
---|
98 | }
|
---|
99 | #endif
|
---|
100 | }
|
---|
101 | //-----------------------------------------------------------------------
|
---|
102 | void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
103 | {
|
---|
104 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
105 | Octree *octant = static_cast<Octree *>(node);
|
---|
106 |
|
---|
107 | if (octant->lastRendered() != mFrameId)
|
---|
108 | {
|
---|
109 | octant->setLastRendered(mFrameId);
|
---|
110 |
|
---|
111 | static_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera, octant);
|
---|
112 |
|
---|
113 | mNumRenderedNodes ++;
|
---|
114 | }
|
---|
115 | #endif
|
---|
116 | }
|
---|
117 | //-----------------------------------------------------------------------
|
---|
118 | bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
119 | {
|
---|
120 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
121 | return static_cast<Octree *>(node)->isOctreeVisible();
|
---|
122 | #else
|
---|
123 | return true;
|
---|
124 | #endif
|
---|
125 | }
|
---|
126 | //-----------------------------------------------------------------------
|
---|
127 | unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
128 | {
|
---|
129 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
130 | return static_cast<Octree *>(node)->lastVisited();
|
---|
131 | #else
|
---|
132 | return 0;
|
---|
133 | #endif
|
---|
134 | }
|
---|
135 | //-----------------------------------------------------------------------
|
---|
136 | AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
137 | {
|
---|
138 | if(node != mPreviousNode)
|
---|
139 | {
|
---|
140 | mPreviousNode = node;
|
---|
141 | static_cast<Octree *>(node)->_getCullBounds(&mBox);
|
---|
142 | }
|
---|
143 |
|
---|
144 | return &mBox;
|
---|
145 | }
|
---|
146 |
|
---|
147 | //} // namespace GtpVisibility
|
---|
148 | } // namespace Ogre
|
---|