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