source: trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp @ 345

Revision 345, 5.3 KB checked in by mattausch, 19 years ago (diff)

fixed bug in chc when traversing node two times because of priority queue. left debug info in there

RevLine 
[59]1#include <OgreIteratorWrappers.h>
2#include <OgreCamera.h>
3#include <OgreSceneNode.h>
[130]4#include <OgreEntity.h>
5#include <OgreSubEntity.h>
6#include <OgreLogManager.h>
7#include "OgreSceneNodeHierarchyInterface.h"
8#include "OgrePlatformOcclusionQuery.h"
[59]9
[130]10
[59]11namespace Ogre {
12
13//-----------------------------------------------------------------------
14SceneNodeHierarchyInterface::SceneNodeHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
15PlatformHierarchyInterface(sm, rsys)
16{               
17}
18//-----------------------------------------------------------------------
[158]19void SceneNodeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
[59]20{
[139]21        ++ mNumTraversedNodes;
[59]22       
23        SceneNode *sceneNode = static_cast<SceneNode *>(node);
24
25        if (HasGeometry(node))
26        {
27                RenderNode(node);
28        }
29
30        // internal node: add children to priority queue for further processing
31        Node::ChildNodeIterator it = sceneNode->getChildIterator();
32                               
33        while (it.hasMoreElements())                   
34        {
35                mDistanceQueue->push(it.getNext());
36        }
37}
38//-----------------------------------------------------------------------
39void SceneNodeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
40{
41#ifdef GTP_VISIBILITY_MODIFIED_OGRE
42        SceneNode *sceneNode = static_cast<SceneNode *>(node);
43
44        if (sceneNode->lastRendered() != sceneNode->lastVisited())
45        {
46                sceneNode->setLastRendered(sceneNode->lastVisited());
[174]47                mVisibleNodes.push_back(node);
[59]48
[139]49                mSceneManager->_renderSceneNode(mCamera, sceneNode, mLeavePassesInQueue);
[59]50        }
51#endif
52}
53//-----------------------------------------------------------------------
[74]54bool SceneNodeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
[59]55{
56        return (static_cast<SceneNode *>(node)->numChildren() == 0);
57}
58//-----------------------------------------------------------------------
[74]59bool SceneNodeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
[59]60{
[87]61        return static_cast<SceneNode *>(node)->numAttachedObjects() > 0;
[59]62}
63//-----------------------------------------------------------------------
[345]64void SceneNodeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
[59]65{
66#ifdef GTP_VISIBILITY_MODIFIED_OGRE
67        SceneNode *sceneNode = static_cast<SceneNode *>(node);
68
[100]69        while (sceneNode && !sceneNode->isNodeVisible())
[59]70        {
71                sceneNode->setNodeVisible(true);
72                sceneNode = sceneNode->getParentSceneNode();
73        }
74#endif
75}
76//-----------------------------------------------------------------------
[87]77float SceneNodeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
[59]78{
[87]79        return static_cast<SceneNode *>(node)->getSquaredViewDepth(mCamera);
[59]80}
81//-----------------------------------------------------------------------
82void SceneNodeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
[345]83                                                                                                 const bool visible) const
[59]84{
85#ifdef GTP_VISIBILITY_MODIFIED_OGRE
86        SceneNode *sceneNode = static_cast<SceneNode *>(node);
87        sceneNode->setNodeVisible(visible);
88#endif
89}
90//-----------------------------------------------------------------------
[74]91void SceneNodeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
[345]92                                                                                                 const unsigned int frameId) const
[59]93{
94#ifdef GTP_VISIBILITY_MODIFIED_OGRE
95        SceneNode *sceneNode = static_cast<SceneNode *>(node);
96        sceneNode->setLastVisited(frameId);
97#endif
98}
99//-----------------------------------------------------------------------
[74]100bool SceneNodeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
[59]101{
102#ifdef GTP_VISIBILITY_MODIFIED_OGRE
103        SceneNode *sceneNode = static_cast<SceneNode *>(node);
104        return sceneNode->isNodeVisible();
105#else
106        return true;
107#endif
108}
109//-----------------------------------------------------------------------
[74]110unsigned int SceneNodeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
[59]111{
112#ifdef GTP_VISIBILITY_MODIFIED_OGRE
113        SceneNode *sceneNode = static_cast<SceneNode *>(node);
114        return sceneNode->lastVisited();
115#else
116        return 0;
117#endif
118}
119//-----------------------------------------------------------------------
120AxisAlignedBox *SceneNodeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
121{
[103]122        // only create renderable bounding box for new node
[155]123        if (node != mSavedNode)
[85]124        {
[155]125                mSavedNode = node;
[85]126                mBox = static_cast<SceneNode *>(node)->_getWorldAABB();
127        }
128
[59]129        return &mBox;
130}
[112]131//-----------------------------------------------------------------------
132void SceneNodeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
[345]133                                                                                                          GtpVisibility::CullingType type) const
[112]134{
135        // TODO
136}
[130]137//-----------------------------------------------------------------------
[155]138void SceneNodeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,       
[130]139                                                                                          GtpVisibility::GeometryList *geometryList,
140                                                                                          bool includeChildren)
141{
142        SceneNode::ObjectIterator objIt =
143                static_cast<SceneNode *>(node)->getAttachedObjectIterator();
144
145        while (objIt.hasMoreElements())
146    {
147                MovableObject *movable = objIt.getNext();
148               
[154]149                // we are interested only in the entities, i.e., instances of geometry
[130]150                if (movable->getMovableType() == "Entity")
151                {
152                        Entity *ent = static_cast<Entity *>(movable);
[155]153                        //std::stringstream d; d << "ent " << ent->getName();
154                        //LogManager::getSingleton().logMessage(d.str());
[130]155                        geometryList->push_back(ent);
156                }
157    }
158}
[158]159
[59]160} // namespace Ogre     
Note: See TracBrowser for help on using the repository browser.