[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 | if (kdnode->getLeftChild())
|
---|
| 45 | mDistanceQueue->push(kdnode->getLeftChild());
|
---|
| 46 | if (kdnode->getRightChild())
|
---|
| 47 | mDistanceQueue->push(kdnode->getRightChild());
|
---|
[1170] | 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void KdTreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
| 52 | {
|
---|
[1173] | 53 | KdTree::Node * kdnode = KDNODEPTR_CAST(node);
|
---|
| 54 | if (kdnode->lastRendered() != mFrameId)
|
---|
| 55 | {
|
---|
| 56 | kdnode->setLastRendered(mFrameId);
|
---|
| 57 | KdTreeSceneManager * ksm = static_cast<KdTreeSceneManager *>(mSceneManager);
|
---|
| 58 |
|
---|
[1187] | 59 | ksm->_renderNode(kdnode, mCamera, mOnlyShadowCasters, mLeavePassesInQueue);
|
---|
[1173] | 60 |
|
---|
| 61 | mVisibleNodes.push_back(node);
|
---|
| 62 | }
|
---|
[1170] | 63 | }
|
---|
| 64 |
|
---|
| 65 | void KdTreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
|
---|
| 66 | {
|
---|
[1173] | 67 | KdTree::Node * kdnode = KDNODEPTR_CAST(node);
|
---|
| 68 |
|
---|
| 69 | while (kdnode && !kdnode->isNodeVisible())
|
---|
| 70 | {
|
---|
| 71 | kdnode->setNodeVisible(true);
|
---|
| 72 | kdnode = kdnode->getParent();
|
---|
| 73 | }
|
---|
[1170] | 74 | }
|
---|
| 75 |
|
---|
| 76 | float KdTreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
| 77 | {
|
---|
[1173] | 78 | const Vector3 pos = KDNODEPTR_CAST(node)->mAABB.getCenter();
|
---|
| 79 | return (mCameraPosition - pos).squaredLength();
|
---|
[1170] | 80 | }
|
---|
| 81 |
|
---|
| 82 | AxisAlignedBox * KdTreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
| 83 | {
|
---|
[1173] | 84 | // reuse box if node is the same
|
---|
| 85 | // only create renderable bounding box for new node
|
---|
| 86 | if (node != mSavedNode)
|
---|
| 87 | {
|
---|
| 88 | mSavedNode = node;
|
---|
| 89 | mBox = KDNODEPTR_CAST(node)->_getWorldAABB();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | return &mBox;
|
---|
[1170] | 93 | }
|
---|
| 94 |
|
---|
| 95 | bool KdTreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
| 96 | {
|
---|
| 97 | return KDNODEPTR_CAST(node)->hasGeometry();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | void KdTreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const
|
---|
| 101 | {
|
---|
[1173] | 102 | KDNODEPTR_CAST(node)->setNodeVisible(visible);
|
---|
[1170] | 103 | }
|
---|
| 104 |
|
---|
| 105 | bool KdTreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
| 106 | {
|
---|
[1173] | 107 | return KDNODEPTR_CAST(node)->isNodeVisible();
|
---|
[1170] | 108 | }
|
---|
| 109 |
|
---|
| 110 | void KdTreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const
|
---|
| 111 | {
|
---|
[1173] | 112 | KDNODEPTR_CAST(node)->setLastVisited(frameId);
|
---|
[1170] | 113 | }
|
---|
| 114 |
|
---|
| 115 | unsigned int KdTreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
| 116 | {
|
---|
[1173] | 117 | return KDNODEPTR_CAST(node)->lastVisited();
|
---|
[1170] | 118 | }
|
---|
| 119 |
|
---|
| 120 | void KdTreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
| 121 | GtpVisibility::CullingType type) const
|
---|
| 122 | {
|
---|
[1173] | 123 | WireBoundingBox *box = KDNODEPTR_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 | dynamic_cast<KdTreeSceneManager *>(mSceneManager)->getRenderQueue()->addRenderable(box);
|
---|
[1170] | 135 | }
|
---|
| 136 |
|
---|
| 137 | void KdTreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
|
---|
| 138 | GtpVisibility::GeometryVector *geometryList,
|
---|
| 139 | bool includeChildren)
|
---|
| 140 | {
|
---|
[1195] | 141 | KDNODEPTR_CAST(node)->getGeometryList(geometryList);
|
---|
[1170] | 142 | }
|
---|
| 143 |
|
---|
| 144 | } // namespace Ogre |
---|