[2348] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of the GameTools Project
|
---|
| 4 | http://www.gametools.org
|
---|
| 5 |
|
---|
| 6 | Author: Martin Szydlowski
|
---|
| 7 | -----------------------------------------------------------------------------
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #include "OgreBihRenderable.h"
|
---|
| 11 | #include "OgreBiHierarchySceneManager.h"
|
---|
| 12 | #include "OgreBiHierarchyInterface.h"
|
---|
| 13 |
|
---|
| 14 | namespace Ogre
|
---|
| 15 | {
|
---|
| 16 |
|
---|
| 17 | BiHierarchyInterface::BiHierarchyInterface(BiHierarchySceneManager *sm, RenderSystem *rsys):
|
---|
| 18 | PlatformHierarchyInterface(sm, rsys)
|
---|
| 19 | {
|
---|
| 20 |
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | bool BiHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
| 24 | {
|
---|
| 25 | return BIHNODEPTR_CAST(node)->isLeaf();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | void BiHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
|
---|
| 29 | {
|
---|
| 30 | ++ mNumTraversedNodes;
|
---|
| 31 |
|
---|
| 32 | BiHierarchy::Node * kdnode = BIHNODEPTR_CAST(node);
|
---|
| 33 |
|
---|
| 34 | // if the node is a leaf and has geometry => render it
|
---|
| 35 | if (kdnode->isLeaf())
|
---|
| 36 | {
|
---|
| 37 | if (!kdnode->isEmpty())
|
---|
| 38 | {
|
---|
| 39 | RenderNode(node);
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | else
|
---|
| 43 | {
|
---|
| 44 | if (kdnode->getLeftChild())
|
---|
| 45 | mDistanceQueue->push(kdnode->getLeftChild());
|
---|
| 46 | if (kdnode->getRightChild())
|
---|
| 47 | mDistanceQueue->push(kdnode->getRightChild());
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void BiHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
| 52 | {
|
---|
| 53 | BiHierarchy::Node * kdnode = BIHNODEPTR_CAST(node);
|
---|
| 54 | if (kdnode->lastRendered() != mFrameId)
|
---|
| 55 | {
|
---|
| 56 | kdnode->setLastRendered(mFrameId);
|
---|
| 57 | BiHierarchySceneManager * ksm = static_cast<BiHierarchySceneManager *>(mSceneManager);
|
---|
| 58 |
|
---|
| 59 | ksm->_renderNode(kdnode, mCamera, mOnlyShadowCasters, mLeavePassesInQueue);
|
---|
| 60 |
|
---|
| 61 | mVisibleNodes.push_back(node);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void BiHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
|
---|
| 66 | {
|
---|
| 67 | BiHierarchy::Node * kdnode = BIHNODEPTR_CAST(node);
|
---|
| 68 |
|
---|
| 69 | while (kdnode && !kdnode->isNodeVisible())
|
---|
| 70 | {
|
---|
| 71 | kdnode->setNodeVisible(true);
|
---|
| 72 | kdnode = kdnode->getParent();
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | float BiHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
| 77 | {
|
---|
| 78 | const Vector3 pos = BIHNODEPTR_CAST(node)->mAABB.getCenter();
|
---|
| 79 | return (mCameraPosition - pos).squaredLength();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | AxisAlignedBox * BiHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
| 83 | {
|
---|
| 84 | // reuse box if node is the same
|
---|
| 85 | // only create renderable bounding box for new node
|
---|
[2455] | 86 | if (node != mOldNode)
|
---|
[2348] | 87 | {
|
---|
[2455] | 88 | mOldNode = node;
|
---|
[2348] | 89 | mBox = BIHNODEPTR_CAST(node)->_getWorldAABB();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | return &mBox;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | bool BiHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
| 96 | {
|
---|
| 97 | return BIHNODEPTR_CAST(node)->hasGeometry();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | void BiHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const
|
---|
| 101 | {
|
---|
| 102 | BIHNODEPTR_CAST(node)->setNodeVisible(visible);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | bool BiHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
| 106 | {
|
---|
| 107 | return BIHNODEPTR_CAST(node)->isNodeVisible();
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | void BiHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const
|
---|
| 111 | {
|
---|
| 112 | BIHNODEPTR_CAST(node)->setLastVisited(frameId);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | unsigned int BiHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
| 116 | {
|
---|
| 117 | return BIHNODEPTR_CAST(node)->lastVisited();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void BiHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
| 121 | GtpVisibility::CullingType type) const
|
---|
| 122 | {
|
---|
| 123 | WireBoundingBox *box = BIHNODEPTR_CAST(node)->getWireBoundingBox();
|
---|
| 124 |
|
---|
| 125 | if (type == GtpVisibility::FRUSTUM_CULLED)
|
---|
| 126 | {
|
---|
| 127 | box->setMaterial("FrustumCulledNodesMaterial");
|
---|
| 128 | }
|
---|
| 129 | else // type == GtpVisibility::QUERY_CULLED
|
---|
| 130 | {
|
---|
| 131 | box->setMaterial("QueryCulledNodesMaterial");
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | static_cast<BiHierarchySceneManager *>(mSceneManager)->getRenderQueue()->addRenderable(box);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | void BiHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
|
---|
| 138 | GeometryVector *geometryList,
|
---|
| 139 | bool includeChildren)
|
---|
| 140 | {
|
---|
| 141 | BIHNODEPTR_CAST(node)->getGeometryList(geometryList);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | } // namespace Ogre |
---|