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