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

Line 
1#include <OgreIteratorWrappers.h>
2#include <OgreCamera.h>
3#include <OgreSceneNode.h>
4#include <OgreEntity.h>
5#include <OgreSubEntity.h>
6#include <OgreLogManager.h>
7#include "OgreSceneNodeHierarchyInterface.h"
8#include "OgrePlatformOcclusionQuery.h"
9
10
11namespace Ogre {
12
13//-----------------------------------------------------------------------
14SceneNodeHierarchyInterface::SceneNodeHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
15PlatformHierarchyInterface(sm, rsys)
16{               
17}
18//-----------------------------------------------------------------------
19void SceneNodeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
20{
21        ++ mNumTraversedNodes;
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());
47                mVisibleNodes.push_back(node);
48
49                mSceneManager->_renderSceneNode(mCamera, sceneNode, mLeavePassesInQueue);
50        }
51#endif
52}
53//-----------------------------------------------------------------------
54bool SceneNodeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
55{
56        return (static_cast<SceneNode *>(node)->numChildren() == 0);
57}
58//-----------------------------------------------------------------------
59bool SceneNodeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
60{
61        return static_cast<SceneNode *>(node)->numAttachedObjects() > 0;
62}
63//-----------------------------------------------------------------------
64void SceneNodeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
65{
66#ifdef GTP_VISIBILITY_MODIFIED_OGRE
67        SceneNode *sceneNode = static_cast<SceneNode *>(node);
68
69        while (sceneNode && !sceneNode->isNodeVisible())
70        {
71                sceneNode->setNodeVisible(true);
72                sceneNode = sceneNode->getParentSceneNode();
73        }
74#endif
75}
76//-----------------------------------------------------------------------
77float SceneNodeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
78{
79        return static_cast<SceneNode *>(node)->getSquaredViewDepth(mCamera);
80}
81//-----------------------------------------------------------------------
82void SceneNodeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
83                                                                                                 const bool visible) const
84{
85#ifdef GTP_VISIBILITY_MODIFIED_OGRE
86        SceneNode *sceneNode = static_cast<SceneNode *>(node);
87        sceneNode->setNodeVisible(visible);
88#endif
89}
90//-----------------------------------------------------------------------
91void SceneNodeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
92                                                                                                 const unsigned int frameId) const
93{
94#ifdef GTP_VISIBILITY_MODIFIED_OGRE
95        SceneNode *sceneNode = static_cast<SceneNode *>(node);
96        sceneNode->setLastVisited(frameId);
97#endif
98}
99//-----------------------------------------------------------------------
100bool SceneNodeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
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//-----------------------------------------------------------------------
110unsigned int SceneNodeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
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{
122        // only create renderable bounding box for new node
123        if (node != mSavedNode)
124        {
125                mSavedNode = node;
126                mBox = static_cast<SceneNode *>(node)->_getWorldAABB();
127        }
128
129        return &mBox;
130}
131//-----------------------------------------------------------------------
132void SceneNodeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
133                                                                                                          GtpVisibility::CullingType type) const
134{
135        // TODO
136}
137//-----------------------------------------------------------------------
138void SceneNodeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,       
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               
149                // we are interested only in the entities, i.e., instances of geometry
150                if (movable->getMovableType() == "Entity")
151                {
152                        Entity *ent = static_cast<Entity *>(movable);
153                        //std::stringstream d; d << "ent " << ent->getName();
154                        //LogManager::getSingleton().logMessage(d.str());
155                        geometryList->push_back(ent);
156                }
157    }
158}
159
160} // namespace Ogre     
Note: See TracBrowser for help on using the repository browser.