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

Revision 174, 5.6 KB checked in by mattausch, 19 years ago (diff)
RevLine 
[59]1#include "OgreOctreeHierarchyInterface.h"
2#include "OgreVisibilityOctreeSceneManager.h"
3#include <OgreOctree.h>
[94]4#include <OgreLogManager.h>
[113]5#include <OgreStringConverter.h>
[59]6
[115]7
[59]8namespace Ogre {
[94]9
[59]10//-----------------------------------------------------------------------
[130]11OctreeHierarchyInterface::OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys):
[158]12SceneNodeHierarchyInterface(sm, rsys)
[59]13{
14}
15//-----------------------------------------------------------------------
[158]16void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
[59]17{
[139]18        ++ mNumTraversedNodes;
[59]19
[87]20        Octree *octree = static_cast<Octree *>(node);
21
[59]22        // if we come across some renderable geometry => render it
[87]23        if (octree->mNodes.size() > 0)
24        {
25                RenderNode(node);
26        }
[59]27       
[159]28        //if (octree->numNodes() > (int)octree->mNodes.size()) // if not all subtrees are empty
[94]29        if (!IsLeaf(node))
[59]30        {
[87]31                for(int i=0; i<8; ++i)
[59]32                {
[87]33                        Octree *nextChild =
34                                octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
35
36                        if (nextChild)
37                        {
38                                mDistanceQueue->push(nextChild);
39                        }
[59]40                }
41        }
42}
43//-----------------------------------------------------------------------
[74]44bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
[59]45{
[94]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();
[59]49}
50//-----------------------------------------------------------------------
[74]51bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
[59]52{
[87]53        return static_cast<Octree *>(node)->mNodes.size() > 0;
[59]54}
55//-----------------------------------------------------------------------
[87]56float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
[59]57{
[87]58        AxisAlignedBox *box = &static_cast<Octree *>(node)->mBox;
[101]59        Vector3 mid = ((box->getMaximum() - box->getMinimum()) * 0.5) + box->getMinimum();
[86]60
[94]61        return (mCullCamera->getDerivedPosition() - mid).squaredLength();
[59]62}
63//-----------------------------------------------------------------------
[74]64void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
65                                                                                          const bool visible)
[59]66{
67#ifdef GTP_VISIBILITY_MODIFIED_OGRE
68        static_cast<Octree *>(node)->setOctreeVisible(visible);
69#endif
70}
71//-----------------------------------------------------------------------
[74]72void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
73                                                                                          const unsigned int frameId)
[59]74{
75#ifdef GTP_VISIBILITY_MODIFIED_OGRE
76        static_cast<Octree *>(node)->setLastVisited(frameId);
77#endif
78}
79//-----------------------------------------------------------------------
80void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
81{               
82#ifdef GTP_VISIBILITY_MODIFIED_OGRE
83        Octree *octant = static_cast<Octree *>(node);
84
[155]85        while (octant && !octant->isOctreeVisible())
[59]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
[130]102                dynamic_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera,
[139]103                        octant, mOnlyShadowCasters, mLeavePassesInQueue);
[59]104
[174]105                mVisibleNodes.push_back(node);
[59]106        }
107#endif
108}
109//-----------------------------------------------------------------------
[74]110bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
[59]111{
112#ifdef GTP_VISIBILITY_MODIFIED_OGRE
113        return static_cast<Octree *>(node)->isOctreeVisible();
114#else
115        return true;
116#endif
117}
118//-----------------------------------------------------------------------
[74]119unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
[59]120{
121#ifdef GTP_VISIBILITY_MODIFIED_OGRE
122        return static_cast<Octree *>(node)->lastVisited();
123#else
124        return 0;
125#endif
126}
127//-----------------------------------------------------------------------
128AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
129{
[155]130        if (node != mSavedNode)
[85]131        {
[155]132                mSavedNode = node;
[139]133            //static_cast<Octree *>(node)->_getCullBounds(&mBox);
[135]134                mBox = static_cast<Octree *>(node)->_getWorldAABB();
[85]135        }
[59]136
137        return &mBox;
138}
[112]139//-----------------------------------------------------------------------
140void OctreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
141                                                                                                   GtpVisibility::CullingType type)
142{
143        WireBoundingBox *box = static_cast<Octree *>(node)->getWireBoundingBox();
[59]144
[112]145        if (type == GtpVisibility::FRUSTUM_CULLED)
146        {
147                box->setMaterial("FrustumCulledNodesMaterial");
148        }
149        else // type == GtpVisibility::QUERY_CULLED
150        {
151                box->setMaterial("QueryCulledNodesMaterial");
152        }
[113]153
[130]154        dynamic_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
[112]155}
[130]156//-----------------------------------------------------------------------
[155]157void OctreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node, 
[130]158                                                                                   GtpVisibility::GeometryList *geometryList,
159                                                                                   bool includeChildren)
160{
161        NodeList::const_iterator nodeIt, nodeIt_end;
162        nodeIt_end = static_cast<Octree *>(node)->mNodes.end();
163
164        for (nodeIt = static_cast<Octree *>(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt)
165        {
[155]166                SceneNodeHierarchyInterface::GetNodeGeometryList(*nodeIt, geometryList, includeChildren);
[130]167        }
168}
[174]169
[59]170} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.