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

Revision 87, 4.5 KB checked in by mattausch, 19 years ago (diff)
Line 
1#include "OgreOctreeHierarchyInterface.h"
2#include "OgreVisibilityOctreeSceneManager.h"
3#include <OgreOctree.h>
4#include <windows.h>
5
6namespace Ogre {
7//namespace GtpVisibility {
8//-----------------------------------------------------------------------
9OctreeHierarchyInterface::OctreeHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
10PlatformHierarchyInterface(sm, rsys)
11{
12}
13//-----------------------------------------------------------------------
14void 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//-----------------------------------------------------------------------
42bool 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//-----------------------------------------------------------------------
55bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
56{
57        return static_cast<Octree *>(node)->mNodes.size() > 0;
58}
59//-----------------------------------------------------------------------
60void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)
61{
62        mNumOctreeNodes = num;
63}
64//-----------------------------------------------------------------------
65float 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//-----------------------------------------------------------------------
73void 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//-----------------------------------------------------------------------
81void 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//-----------------------------------------------------------------------
89void 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//-----------------------------------------------------------------------
102void 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//-----------------------------------------------------------------------
118bool 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//-----------------------------------------------------------------------
127unsigned 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//-----------------------------------------------------------------------
136AxisAlignedBox *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
Note: See TracBrowser for help on using the repository browser.