1 | #include "OgreSceneNodeHierarchyInterface.h"
|
---|
2 | #include <OgreIteratorWrappers.h>
|
---|
3 | #include <OgreCamera.h>
|
---|
4 | #include <OgreSceneNode.h>
|
---|
5 |
|
---|
6 | namespace Ogre {
|
---|
7 |
|
---|
8 | //-----------------------------------------------------------------------
|
---|
9 | SceneNodeHierarchyInterface::SceneNodeHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
|
---|
10 | PlatformHierarchyInterface(sm, rsys)
|
---|
11 | {
|
---|
12 | }
|
---|
13 | //-----------------------------------------------------------------------
|
---|
14 | void SceneNodeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
|
---|
15 | {
|
---|
16 | mNumTraversedNodes ++;
|
---|
17 |
|
---|
18 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
19 |
|
---|
20 | if (HasGeometry(node))
|
---|
21 | {
|
---|
22 | RenderNode(node);
|
---|
23 | }
|
---|
24 |
|
---|
25 | // internal node: add children to priority queue for further processing
|
---|
26 | Node::ChildNodeIterator it = sceneNode->getChildIterator();
|
---|
27 |
|
---|
28 | while (it.hasMoreElements())
|
---|
29 | {
|
---|
30 | mDistanceQueue->push(it.getNext());
|
---|
31 | }
|
---|
32 | }
|
---|
33 | //-----------------------------------------------------------------------
|
---|
34 | void SceneNodeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
35 | {
|
---|
36 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
37 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
38 |
|
---|
39 | if (sceneNode->lastRendered() != sceneNode->lastVisited())
|
---|
40 | {
|
---|
41 | sceneNode->setLastRendered(sceneNode->lastVisited());
|
---|
42 | mNumRenderedNodes ++;
|
---|
43 |
|
---|
44 | mSceneManager->_renderSceneNode(mCamera, sceneNode);
|
---|
45 | }
|
---|
46 | #endif
|
---|
47 | }
|
---|
48 | //-----------------------------------------------------------------------
|
---|
49 | bool SceneNodeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
50 | {
|
---|
51 | return (static_cast<SceneNode *>(node)->numChildren() == 0);
|
---|
52 | }
|
---|
53 | //-----------------------------------------------------------------------
|
---|
54 | bool SceneNodeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
55 | {
|
---|
56 | return static_cast<SceneNode *>(node)->numAttachedObjects() > 0;
|
---|
57 | }
|
---|
58 | //-----------------------------------------------------------------------
|
---|
59 | void SceneNodeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
|
---|
60 | {
|
---|
61 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
62 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
63 |
|
---|
64 | while (sceneNode && !sceneNode->isNodeVisible())
|
---|
65 | {
|
---|
66 | sceneNode->setNodeVisible(true);
|
---|
67 | sceneNode = sceneNode->getParentSceneNode();
|
---|
68 | }
|
---|
69 | #endif
|
---|
70 | }
|
---|
71 | //-----------------------------------------------------------------------
|
---|
72 | float SceneNodeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
73 | {
|
---|
74 | return static_cast<SceneNode *>(node)->getSquaredViewDepth(mCamera);
|
---|
75 | }
|
---|
76 | //-----------------------------------------------------------------------
|
---|
77 | void SceneNodeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
|
---|
78 | const bool visible)
|
---|
79 | {
|
---|
80 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
81 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
82 | sceneNode->setNodeVisible(visible);
|
---|
83 | #endif
|
---|
84 | }
|
---|
85 | //-----------------------------------------------------------------------
|
---|
86 | void SceneNodeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
|
---|
87 | const unsigned int frameId)
|
---|
88 | {
|
---|
89 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
90 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
91 | sceneNode->setLastVisited(frameId);
|
---|
92 | #endif
|
---|
93 | }
|
---|
94 | //-----------------------------------------------------------------------
|
---|
95 | bool SceneNodeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
96 | {
|
---|
97 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
98 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
99 | return sceneNode->isNodeVisible();
|
---|
100 | #else
|
---|
101 | return true;
|
---|
102 | #endif
|
---|
103 | }
|
---|
104 | //-----------------------------------------------------------------------
|
---|
105 | unsigned int SceneNodeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
106 | {
|
---|
107 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
108 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
109 | return sceneNode->lastVisited();
|
---|
110 | #else
|
---|
111 | return 0;
|
---|
112 | #endif
|
---|
113 | }
|
---|
114 | //-----------------------------------------------------------------------
|
---|
115 | AxisAlignedBox *SceneNodeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
116 | {
|
---|
117 | // only create renderable bounding box for new node
|
---|
118 | if (node != mPreviousNode)
|
---|
119 | {
|
---|
120 | mPreviousNode = node;
|
---|
121 | mBox = static_cast<SceneNode *>(node)->_getWorldAABB();
|
---|
122 | }
|
---|
123 |
|
---|
124 | return &mBox;
|
---|
125 | }
|
---|
126 | //-----------------------------------------------------------------------
|
---|
127 | void SceneNodeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
128 | GtpVisibility::CullingType type)
|
---|
129 | {
|
---|
130 | // TODO
|
---|
131 | }
|
---|
132 | } // namespace Ogre
|
---|