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

Revision 59, 4.7 KB checked in by mattausch, 20 years ago (diff)

completely changed file structure plus software design

RevLine 
[59]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)
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)
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)
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, const AxisAlignedBox* box) const
69{
70        Vector3 mid  = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum();
71        return (cam->getDerivedPosition() - mid).squaredLength();                                                                   
72}
73//-----------------------------------------------------------------------
74void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, 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, const int frameId)
82{
83#ifdef GTP_VISIBILITY_MODIFIED_OGRE
84        static_cast<Octree *>(node)->setLastVisited(frameId);
85#endif
86}
87//-----------------------------------------------------------------------
88void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
89{               
90#ifdef GTP_VISIBILITY_MODIFIED_OGRE
91        Octree *octant = static_cast<Octree *>(node);
92
93        while(octant && !octant->isOctreeVisible())
94        {
95                octant->setOctreeVisible(true);
96                octant = octant->getParent();
97        }
98#endif
99}
100//-----------------------------------------------------------------------
101void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
102{
103#ifdef GTP_VISIBILITY_MODIFIED_OGRE
104        Octree *octant = static_cast<Octree *>(node);
105
106        if (octant->lastRendered() != mFrameId)
107        {
108                octant->setLastRendered(mFrameId);
109
110                if (!HasGeometry(octant)) return;
111
112                static_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera, octant);
113
114                mNumRenderedNodes ++;
115        }
116#endif
117}
118//-----------------------------------------------------------------------
119bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node)
120{
121#ifdef GTP_VISIBILITY_MODIFIED_OGRE
122        return static_cast<Octree *>(node)->isOctreeVisible();
123#else
124        return true;
125#endif
126}
127//-----------------------------------------------------------------------
128int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node)
129{
130#ifdef GTP_VISIBILITY_MODIFIED_OGRE
131        return static_cast<Octree *>(node)->lastVisited();
132#else
133        return 0;
134#endif
135}
136//-----------------------------------------------------------------------
137AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
138{
139        static_cast<Octree *>(node)->_getCullBounds(&mBox);
140
141        return &mBox;
142}
143
144//} // namespace GtpVisibility
145} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.