source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp @ 880

Revision 880, 6.4 KB checked in by mattausch, 19 years ago (diff)

added filter to online stuff (not fully working, too slow
)

Line 
1#include "OgreOctreeHierarchyInterface.h"
2#include "OgreVisibilityOctreeSceneManager.h"
3#include <OgreOctree.h>
4#include <OgreLogManager.h>
5#include <OgreStringConverter.h>
6
7
8namespace Ogre {
9
10//-----------------------------------------------------------------------
11OctreeHierarchyInterface::OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys):
12SceneNodeHierarchyInterface(sm, rsys)
13{
14}
15//-----------------------------------------------------------------------
16void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
17{
18        ++ mNumTraversedNodes;
19
20        Octree *octree = static_cast<Octree *>(node);
21
22        // if we come across some renderable geometry => render it
23        if (!octree->mNodes.empty())
24        {
25                RenderNode(node);
26        }
27       
28        // if not all subtrees are empty
29        if (!IsLeaf(node))
30        {
31                Octree *nextChild;
32
33                if ((nextChild = octree->mChildren[0][0][0]) != NULL)
34                        mDistanceQueue->push(nextChild);
35                if ((nextChild = octree->mChildren[0][0][1]) != NULL)
36                        mDistanceQueue->push(nextChild);
37                if ((nextChild = octree->mChildren[0][1][0]) != NULL)
38                        mDistanceQueue->push(nextChild);
39                if ((nextChild = octree->mChildren[0][1][1]) != NULL)
40                mDistanceQueue->push(nextChild);
41                if ((nextChild = octree->mChildren[1][0][0]) != NULL)
42                        mDistanceQueue->push(nextChild);
43                if ((nextChild = octree->mChildren[1][0][1]) != NULL)
44                        mDistanceQueue->push(nextChild);
45                if ((nextChild = octree->mChildren[1][1][0]) != NULL)
46                        mDistanceQueue->push(nextChild);
47                if ((nextChild = octree->mChildren[1][1][1]) != NULL)
48                        mDistanceQueue->push(nextChild);
49        }
50}
51//-----------------------------------------------------------------------
52bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
53{
54        Octree *octree = static_cast<Octree *>(node);
55        // HACK: if there are subtrees, they are empty => we are not interested in them
56        return octree->numNodes() == (int)octree->mNodes.size();
57}
58//-----------------------------------------------------------------------
59bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
60{
61        return !(static_cast<Octree *>(node))->mNodes.empty();
62}
63//-----------------------------------------------------------------------
64float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
65{
66        const Vector3 bmin = static_cast<Octree *>(node)->mBox.getMinimum();
67        const Vector3 bmax = static_cast<Octree *>(node)->mBox.getMaximum();
68
69        const Vector3 pos = (bmax - bmin) * 0.5 + bmin;
70       
71        return (mCameraPosition - pos).squaredLength();
72        //return (mCullCamera->getDerivedPosition() - pos).squaredLength();
73}
74//-----------------------------------------------------------------------
75void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
76                                                                                          const bool visible) const
77{
78#ifdef GTP_VISIBILITY_MODIFIED_OGRE
79        static_cast<Octree *>(node)->setOctreeVisible(visible);
80#endif
81}
82//-----------------------------------------------------------------------
83void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
84                                                                                          const unsigned int frameId) const
85{
86#ifdef GTP_VISIBILITY_MODIFIED_OGRE
87        static_cast<Octree *>(node)->setLastVisited(frameId);
88#endif
89}
90//-----------------------------------------------------------------------
91void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
92{               
93#ifdef GTP_VISIBILITY_MODIFIED_OGRE
94        Octree *octant = static_cast<Octree *>(node);
95
96        while (octant && !octant->isOctreeVisible())
97        {
98                octant->setOctreeVisible(true);
99                octant = octant->getParent();
100        }
101#endif
102}
103//-----------------------------------------------------------------------
104void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
105{
106#ifdef GTP_VISIBILITY_MODIFIED_OGRE
107        Octree *octant = static_cast<Octree *>(node);
108
109        if (octant->lastRendered() != mFrameId)
110        {
111                octant->setLastRendered(mFrameId);
112                OctreeSceneManager *ocm =
113                        //dynamic_cast<OctreeSceneManager *>(mSceneManager);
114                        dynamic_cast<OctreeSceneManager *>(mSceneManager);
115                ocm->_renderOctant(mCamera, octant, mOnlyShadowCasters, mLeavePassesInQueue);
116
117                mVisibleNodes.push_back(node);
118        }
119#endif
120       
121}
122//-----------------------------------------------------------------------
123bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
124{
125#ifdef GTP_VISIBILITY_MODIFIED_OGRE
126        return static_cast<Octree *>(node)->isOctreeVisible();
127#else
128        return true;
129#endif
130}
131//-----------------------------------------------------------------------
132unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
133{
134#ifdef GTP_VISIBILITY_MODIFIED_OGRE
135        return static_cast<Octree *>(node)->lastVisited();
136#else
137        return 0;
138#endif
139}
140//-----------------------------------------------------------------------
141AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
142{
143        if (node != mSavedNode)
144        {
145                mSavedNode = node;
146            //static_cast<Octree *>(node)->_getCullBounds(&mBox);
147                mBox = static_cast<Octree *>(node)->_getWorldAABB();
148        }
149
150        return &mBox;
151}
152//-----------------------------------------------------------------------
153void OctreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
154                                                                                                   GtpVisibility::CullingType type) const
155{
156        WireBoundingBox *box = static_cast<Octree *>(node)->getWireBoundingBox();
157
158        if (type == GtpVisibility::FRUSTUM_CULLED)
159        {
160                box->setMaterial("FrustumCulledNodesMaterial");
161        }
162        else // type == GtpVisibility::QUERY_CULLED
163        {
164                box->setMaterial("QueryCulledNodesMaterial");
165        }
166
167        //dynamic_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
168        dynamic_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
169}
170//-----------------------------------------------------------------------
171void OctreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
172                                                                                                   GtpVisibility::GeometryVector *geometryList,
173                                                                                                   bool includeChildren)
174{
175        NodeList::const_iterator nodeIt, nodeIt_end;
176        nodeIt_end = static_cast<Octree *>(node)->mNodes.end();
177
178        for (nodeIt = static_cast<Octree *>(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt)
179        {
180                SceneNodeHierarchyInterface::GetNodeGeometryList(*nodeIt, geometryList, includeChildren);
181        }
182}
183
184} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.