source: trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp @ 158

Revision 158, 5.6 KB checked in by mattausch, 19 years ago (diff)

removed node visibility for item buffer

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