[1165] | 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 |
|
---|
[1173] | 10 | #include "OgreKdRenderable.h"
|
---|
[1165] | 11 | #include "OgreKdTreeSceneManager.h"
|
---|
| 12 | #include "OgreKdTreeHierarchyInterface.h"
|
---|
| 13 |
|
---|
| 14 | namespace Ogre
|
---|
| 15 | {
|
---|
| 16 |
|
---|
| 17 | KdTreeHierarchyInterface::KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys):
|
---|
[1170] | 18 | PlatformHierarchyInterface(sm, rsys)
|
---|
[1165] | 19 | {
|
---|
| 20 |
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | bool KdTreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
| 24 | {
|
---|
[1170] | 25 | return KDNODEPTR_CAST(node)->isLeaf();
|
---|
[1165] | 26 | }
|
---|
| 27 |
|
---|
[1170] | 28 | void KdTreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
|
---|
| 29 | {
|
---|
| 30 | ++ mNumTraversedNodes;
|
---|
[1165] | 31 |
|
---|
[1170] | 32 | KdTree::Node * kdnode = KDNODEPTR_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 | {
|
---|
[1195] | 44 | //KdTree::Branch * kdbranch = KDBRANCHPTR_CAST(node);
|
---|
| 45 | //if (kdbranch->mLeft)
|
---|
| 46 | // mDistanceQueue->push(kdbranch->mLeft);
|
---|
| 47 | //if (kdbranch->mRight)
|
---|
| 48 | // mDistanceQueue->push(kdbranch->mRight);
|
---|
| 49 | if (kdnode->getLeftChild())
|
---|
| 50 | mDistanceQueue->push(kdnode->getLeftChild());
|
---|
| 51 | if (kdnode->getRightChild())
|
---|
| 52 | mDistanceQueue->push(kdnode->getRightChild());
|
---|
[1170] | 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | void KdTreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
| 57 | {
|
---|
[1173] | 58 | KdTree::Node * kdnode = KDNODEPTR_CAST(node);
|
---|
| 59 | if (kdnode->lastRendered() != mFrameId)
|
---|
| 60 | {
|
---|
| 61 | kdnode->setLastRendered(mFrameId);
|
---|
| 62 | KdTreeSceneManager * ksm = static_cast<KdTreeSceneManager *>(mSceneManager);
|
---|
| 63 |
|
---|
[1187] | 64 | ksm->_renderNode(kdnode, mCamera, mOnlyShadowCasters, mLeavePassesInQueue);
|
---|
[1173] | 65 |
|
---|
| 66 | mVisibleNodes.push_back(node);
|
---|
| 67 | }
|
---|
[1170] | 68 | }
|
---|
| 69 |
|
---|
| 70 | void KdTreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
|
---|
| 71 | {
|
---|
[1173] | 72 | KdTree::Node * kdnode = KDNODEPTR_CAST(node);
|
---|
| 73 |
|
---|
| 74 | while (kdnode && !kdnode->isNodeVisible())
|
---|
| 75 | {
|
---|
| 76 | kdnode->setNodeVisible(true);
|
---|
| 77 | kdnode = kdnode->getParent();
|
---|
| 78 | }
|
---|
[1170] | 79 | }
|
---|
| 80 |
|
---|
| 81 | float KdTreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
| 82 | {
|
---|
[1173] | 83 | const Vector3 pos = KDNODEPTR_CAST(node)->mAABB.getCenter();
|
---|
| 84 | return (mCameraPosition - pos).squaredLength();
|
---|
[1170] | 85 | }
|
---|
| 86 |
|
---|
| 87 | AxisAlignedBox * KdTreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
| 88 | {
|
---|
[1173] | 89 | // reuse box if node is the same
|
---|
| 90 | // only create renderable bounding box for new node
|
---|
| 91 | if (node != mSavedNode)
|
---|
| 92 | {
|
---|
| 93 | mSavedNode = node;
|
---|
| 94 | mBox = KDNODEPTR_CAST(node)->_getWorldAABB();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | return &mBox;
|
---|
[1170] | 98 | }
|
---|
| 99 |
|
---|
| 100 | bool KdTreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
| 101 | {
|
---|
| 102 | return KDNODEPTR_CAST(node)->hasGeometry();
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | void KdTreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const
|
---|
| 106 | {
|
---|
[1173] | 107 | KDNODEPTR_CAST(node)->setNodeVisible(visible);
|
---|
[1170] | 108 | }
|
---|
| 109 |
|
---|
| 110 | bool KdTreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
| 111 | {
|
---|
[1173] | 112 | return KDNODEPTR_CAST(node)->isNodeVisible();
|
---|
[1170] | 113 | }
|
---|
| 114 |
|
---|
| 115 | void KdTreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const
|
---|
| 116 | {
|
---|
[1173] | 117 | KDNODEPTR_CAST(node)->setLastVisited(frameId);
|
---|
[1170] | 118 | }
|
---|
| 119 |
|
---|
| 120 | unsigned int KdTreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
| 121 | {
|
---|
[1173] | 122 | return KDNODEPTR_CAST(node)->lastVisited();
|
---|
[1170] | 123 | }
|
---|
| 124 |
|
---|
| 125 | void KdTreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
| 126 | GtpVisibility::CullingType type) const
|
---|
| 127 | {
|
---|
[1173] | 128 | WireBoundingBox *box = KDNODEPTR_CAST(node)->getWireBoundingBox();
|
---|
| 129 |
|
---|
| 130 | if (type == GtpVisibility::FRUSTUM_CULLED)
|
---|
| 131 | {
|
---|
| 132 | box->setMaterial("FrustumCulledNodesMaterial");
|
---|
| 133 | }
|
---|
| 134 | else // type == GtpVisibility::QUERY_CULLED
|
---|
| 135 | {
|
---|
| 136 | box->setMaterial("QueryCulledNodesMaterial");
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | dynamic_cast<KdTreeSceneManager *>(mSceneManager)->getRenderQueue()->addRenderable(box);
|
---|
[1170] | 140 | }
|
---|
| 141 |
|
---|
| 142 | void KdTreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
|
---|
| 143 | GtpVisibility::GeometryVector *geometryList,
|
---|
| 144 | bool includeChildren)
|
---|
| 145 | {
|
---|
[1195] | 146 | KDNODEPTR_CAST(node)->getGeometryList(geometryList);
|
---|
[1170] | 147 | }
|
---|
| 148 |
|
---|
| 149 | } // namespace Ogre |
---|