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