[59] | 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 | //-----------------------------------------------------------------------
|
---|
[74] | 49 | bool SceneNodeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 50 | {
|
---|
| 51 | return (static_cast<SceneNode *>(node)->numChildren() == 0);
|
---|
| 52 | }
|
---|
| 53 | //-----------------------------------------------------------------------
|
---|
[74] | 54 | bool SceneNodeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 55 | {
|
---|
[87] | 56 | return static_cast<SceneNode *>(node)->numAttachedObjects() > 0;
|
---|
[59] | 57 | }
|
---|
| 58 | //-----------------------------------------------------------------------
|
---|
| 59 | void SceneNodeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
|
---|
| 60 | {
|
---|
| 61 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 62 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
| 63 |
|
---|
[100] | 64 | while (sceneNode && !sceneNode->isNodeVisible())
|
---|
[59] | 65 | {
|
---|
| 66 | sceneNode->setNodeVisible(true);
|
---|
| 67 | sceneNode = sceneNode->getParentSceneNode();
|
---|
| 68 | }
|
---|
| 69 | #endif
|
---|
| 70 | }
|
---|
| 71 | //-----------------------------------------------------------------------
|
---|
[87] | 72 | float SceneNodeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 73 | {
|
---|
[87] | 74 | return static_cast<SceneNode *>(node)->getSquaredViewDepth(mCamera);
|
---|
[59] | 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 | //-----------------------------------------------------------------------
|
---|
[74] | 86 | void SceneNodeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
|
---|
| 87 | const unsigned int frameId)
|
---|
[59] | 88 | {
|
---|
| 89 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 90 | SceneNode *sceneNode = static_cast<SceneNode *>(node);
|
---|
| 91 | sceneNode->setLastVisited(frameId);
|
---|
| 92 | #endif
|
---|
| 93 | }
|
---|
| 94 | //-----------------------------------------------------------------------
|
---|
[74] | 95 | bool SceneNodeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 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 | //-----------------------------------------------------------------------
|
---|
[74] | 105 | unsigned int SceneNodeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 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 | {
|
---|
[103] | 117 | // only create renderable bounding box for new node
|
---|
[100] | 118 | if (node != mPreviousNode)
|
---|
[85] | 119 | {
|
---|
| 120 | mPreviousNode = node;
|
---|
| 121 | mBox = static_cast<SceneNode *>(node)->_getWorldAABB();
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[59] | 124 | return &mBox;
|
---|
| 125 | }
|
---|
[112] | 126 | //-----------------------------------------------------------------------
|
---|
| 127 | void SceneNodeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
| 128 | GtpVisibility::CullingType type)
|
---|
| 129 | {
|
---|
| 130 | // TODO
|
---|
| 131 | }
|
---|
[59] | 132 | } // namespace Ogre
|
---|