source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp @ 370

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

fixed specular bug in trees
added batched query manager
added t information to ray bsp leaves

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 (octree->numNodes() > (int)octree->mNodes.size()) // if not all subtrees are empty
29        if (!IsLeaf(node))
30        {
31                for(int i=0; i<8; ++i)
32                {
33                        Octree *nextChild =
34                                octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
35                       
36                        if (nextChild)
37                        {
38                                mDistanceQueue->push(nextChild);
39                        }
40                }
41        }
42}
43//-----------------------------------------------------------------------
44bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
45{
46        Octree *octree = static_cast<Octree *>(node);
47        // HACK: if there are subtrees, they are empty => we are not interested in them
48        return octree->numNodes() == (int)octree->mNodes.size();
49}
50//-----------------------------------------------------------------------
51bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
52{
53        return static_cast<Octree *>(node)->mNodes.size() > 0;
54}
55//-----------------------------------------------------------------------
56float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
57{
58        AxisAlignedBox *box = &static_cast<Octree *>(node)->mBox;
59        Vector3 pos = ((box->getMaximum() - box->getMinimum()) * 0.5) + box->getMinimum();
60       
61        return (mCullCamera->getDerivedPosition() - pos).squaredLength();
62}
63//-----------------------------------------------------------------------
64void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
65                                                                                          const bool visible) const
66{
67#ifdef GTP_VISIBILITY_MODIFIED_OGRE
68        static_cast<Octree *>(node)->setOctreeVisible(visible);
69#endif
70}
71//-----------------------------------------------------------------------
72void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
73                                                                                          const unsigned int frameId) const
74{
75#ifdef GTP_VISIBILITY_MODIFIED_OGRE
76        static_cast<Octree *>(node)->setLastVisited(frameId);
77#endif
78}
79//-----------------------------------------------------------------------
80void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
81{               
82#ifdef GTP_VISIBILITY_MODIFIED_OGRE
83        Octree *octant = static_cast<Octree *>(node);
84
85        while (octant && !octant->isOctreeVisible())
86        {
87                octant->setOctreeVisible(true);
88                octant = octant->getParent();
89        }
90#endif
91}
92//-----------------------------------------------------------------------
93void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
94{
95#ifdef GTP_VISIBILITY_MODIFIED_OGRE
96        Octree *octant = static_cast<Octree *>(node);
97
98        if (octant->lastRendered() != mFrameId)
99        {
100                octant->setLastRendered(mFrameId);
101
102                dynamic_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera,
103                        octant, mOnlyShadowCasters, mLeavePassesInQueue);
104
105                mVisibleNodes.push_back(node);
106        }
107#endif
108       
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) const
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::GeometryVector *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
171} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.