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

Revision 85, 4.8 KB checked in by mattausch, 19 years ago (diff)

corrected bug so chc is much faster than stop and wait

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        // if we come across some renderable geometry => render it
19        RenderNode(node);
20       
21        for(int i=0; i<8; ++i)
22        {
23                Octree *nextChild =
24                        static_cast<Octree *>(node)->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
25
26        if (nextChild)
27                {
28                        mDistanceQueue->push(nextChild);
29                }
30        }
31}
32//-----------------------------------------------------------------------
33bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
34{
35        Octree *octant = static_cast<Octree *>(node);
36
37        for(int i=0; i<8; i++)
38        {
39                if (octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1])
40                        return false;
41        }
42
43        return true;
44}
45//-----------------------------------------------------------------------
46bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
47{
48        return static_cast<Octree *>(node)->numNodes() > 0;
49}
50//-----------------------------------------------------------------------
51void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)
52{
53        mNumOctreeNodes = num;
54}
55//-----------------------------------------------------------------------
56bool OctreeHierarchyInterface::HasGreaterDistance(GtpVisibility::HierarchyNode *node1,
57                                                                                                  GtpVisibility::HierarchyNode *node2) const
58{
59        // matt: change this (inefficient)
60        AxisAlignedBox box1, box2;
61
62        static_cast<Octree *>(node1)->_getCullBounds(&box1);
63        static_cast<Octree *>(node2)->_getCullBounds(&box2);
64
65        return GetSquaredViewDepth(mCamera, &box1) > GetSquaredViewDepth(mCamera, &box2);
66}
67//-----------------------------------------------------------------------
68Real OctreeHierarchyInterface::GetSquaredViewDepth(const Camera* cam,
69                                                                                                   const AxisAlignedBox* box) const
70{
71        Vector3 mid = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum();
72        return (cam->getDerivedPosition() - mid).squaredLength();                                                                   
73}
74//-----------------------------------------------------------------------
75void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
76                                                                                          const bool visible)
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)
85{
86#ifdef GTP_VISIBILITY_MODIFIED_OGRE
87        static_cast<Octree *>(node)->setLastVisited(frameId);
88#endif
89}
90//-----------------------------------------------------------------------
91void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
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
113                if (!HasGeometry(octant)) return;
114
115                static_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera, octant);
116
117                mNumRenderedNodes ++;
118        }
119#endif
120}
121//-----------------------------------------------------------------------
122bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
123{
124#ifdef GTP_VISIBILITY_MODIFIED_OGRE
125        return static_cast<Octree *>(node)->isOctreeVisible();
126#else
127        return true;
128#endif
129}
130//-----------------------------------------------------------------------
131unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
132{
133#ifdef GTP_VISIBILITY_MODIFIED_OGRE
134        return static_cast<Octree *>(node)->lastVisited();
135#else
136        return 0;
137#endif
138}
139//-----------------------------------------------------------------------
140AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
141{
142        if(node != mPreviousNode)
143        {
144                mPreviousNode = node;
145                static_cast<Octree *>(node)->_getCullBounds(&mBox);
146        }
147
148        return &mBox;
149}
150
151//} // namespace GtpVisibility
152} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.