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

Revision 87, 4.5 KB checked in by mattausch, 20 years ago (diff)
RevLine 
[59]1#include "OgreOctreeHierarchyInterface.h"
2#include "OgreVisibilityOctreeSceneManager.h"
3#include <OgreOctree.h>
[74]4#include <windows.h>
[59]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
[87]18        Octree *octree = static_cast<Octree *>(node);
19
[59]20        // if we come across some renderable geometry => render it
[87]21        if (octree->mNodes.size() > 0)
22        {
23                RenderNode(node);
24        }
[59]25       
[87]26        // if not all subtrees are empty
27        if (octree->numNodes() > (int)octree->mNodes.size())
[59]28        {
[87]29                for(int i=0; i<8; ++i)
[59]30                {
[87]31                        Octree *nextChild =
32                                octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
33
34                        if (nextChild)
35                        {
36                                mDistanceQueue->push(nextChild);
37                        }
[59]38                }
39        }
40}
41//-----------------------------------------------------------------------
[74]42bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
[59]43{
44        Octree *octant = static_cast<Octree *>(node);
45
46        for(int i=0; i<8; i++)
47        {
[74]48                if (octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1])
[59]49                        return false;
50        }
51
52        return true;
53}
54//-----------------------------------------------------------------------
[74]55bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
[59]56{
[87]57        return static_cast<Octree *>(node)->mNodes.size() > 0;
[59]58}
59//-----------------------------------------------------------------------
60void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)
61{
62        mNumOctreeNodes = num;
63}
64//-----------------------------------------------------------------------
[87]65float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
[59]66{
[87]67        AxisAlignedBox *box = &static_cast<Octree *>(node)->mBox;
[74]68        Vector3 mid = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum();
[86]69
[87]70        return (mCamera->getDerivedPosition() - mid).squaredLength();
[59]71}
72//-----------------------------------------------------------------------
[74]73void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
74                                                                                          const bool visible)
[59]75{
76#ifdef GTP_VISIBILITY_MODIFIED_OGRE
77        static_cast<Octree *>(node)->setOctreeVisible(visible);
78#endif
79}
80//-----------------------------------------------------------------------
[74]81void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
82                                                                                          const unsigned int frameId)
[59]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//-----------------------------------------------------------------------
[74]118bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
[59]119{
120#ifdef GTP_VISIBILITY_MODIFIED_OGRE
121        return static_cast<Octree *>(node)->isOctreeVisible();
122#else
123        return true;
124#endif
125}
126//-----------------------------------------------------------------------
[74]127unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
[59]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{
[85]138        if(node != mPreviousNode)
139        {
140                mPreviousNode = node;
141                static_cast<Octree *>(node)->_getCullBounds(&mBox);
142        }
[59]143
144        return &mBox;
145}
146
147//} // namespace GtpVisibility
148} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.