[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 |
|
---|
[1320] | 51 | void BvHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
[1318] | 52 | {
|
---|
[1320] | 53 | BvHierarchy::Node * kdnode = BVHNODEPTR_CAST(node);
|
---|
[1318] | 54 | if (kdnode->lastRendered() != mFrameId)
|
---|
| 55 | {
|
---|
| 56 | kdnode->setLastRendered(mFrameId);
|
---|
[1320] | 57 | BvHierarchySceneManager * ksm = static_cast<BvHierarchySceneManager *>(mSceneManager);
|
---|
[1318] | 58 |
|
---|
| 59 | ksm->_renderNode(kdnode, mCamera, mOnlyShadowCasters, mLeavePassesInQueue);
|
---|
| 60 |
|
---|
| 61 | mVisibleNodes.push_back(node);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[1320] | 65 | void BvHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
|
---|
[1318] | 66 | {
|
---|
[1320] | 67 | BvHierarchy::Node * kdnode = BVHNODEPTR_CAST(node);
|
---|
[1318] | 68 |
|
---|
| 69 | while (kdnode && !kdnode->isNodeVisible())
|
---|
| 70 | {
|
---|
| 71 | kdnode->setNodeVisible(true);
|
---|
| 72 | kdnode = kdnode->getParent();
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[1320] | 76 | float BvHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
[1318] | 77 | {
|
---|
[1320] | 78 | const Vector3 pos = BVHNODEPTR_CAST(node)->mAABB.getCenter();
|
---|
[1318] | 79 | return (mCameraPosition - pos).squaredLength();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[1320] | 82 | AxisAlignedBox * BvHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
[1318] | 83 | {
|
---|
| 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;
|
---|
[1320] | 89 | mBox = BVHNODEPTR_CAST(node)->_getWorldAABB();
|
---|
[1318] | 90 | }
|
---|
| 91 |
|
---|
| 92 | return &mBox;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[1320] | 95 | bool BvHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
[1318] | 96 | {
|
---|
[1320] | 97 | return BVHNODEPTR_CAST(node)->hasGeometry();
|
---|
[1318] | 98 | }
|
---|
| 99 |
|
---|
[1320] | 100 | void BvHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const
|
---|
[1318] | 101 | {
|
---|
[1320] | 102 | BVHNODEPTR_CAST(node)->setNodeVisible(visible);
|
---|
[1318] | 103 | }
|
---|
| 104 |
|
---|
[1320] | 105 | bool BvHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
[1318] | 106 | {
|
---|
[1320] | 107 | return BVHNODEPTR_CAST(node)->isNodeVisible();
|
---|
[1318] | 108 | }
|
---|
| 109 |
|
---|
[1320] | 110 | void BvHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const
|
---|
[1318] | 111 | {
|
---|
[1320] | 112 | BVHNODEPTR_CAST(node)->setLastVisited(frameId);
|
---|
[1318] | 113 | }
|
---|
| 114 |
|
---|
[1320] | 115 | unsigned int BvHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
[1318] | 116 | {
|
---|
[1320] | 117 | return BVHNODEPTR_CAST(node)->lastVisited();
|
---|
[1318] | 118 | }
|
---|
| 119 |
|
---|
[1320] | 120 | void BvHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
[1318] | 121 | GtpVisibility::CullingType type) const
|
---|
| 122 | {
|
---|
[1320] | 123 | WireBoundingBox *box = BVHNODEPTR_CAST(node)->getWireBoundingBox();
|
---|
[1318] | 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 |
|
---|
[2066] | 134 | static_cast<BvHierarchySceneManager *>(mSceneManager)->getRenderQueue()->addRenderable(box);
|
---|
[1318] | 135 | }
|
---|
| 136 |
|
---|
[1320] | 137 | void BvHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
|
---|
[1318] | 138 | GtpVisibility::GeometryVector *geometryList,
|
---|
| 139 | bool includeChildren)
|
---|
| 140 | {
|
---|
[1320] | 141 | BVHNODEPTR_CAST(node)->getGeometryList(geometryList);
|
---|
[1318] | 142 | }
|
---|
| 143 |
|
---|
| 144 | } // namespace Ogre |
---|