source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchyInterface.cpp @ 2258

Revision 2258, 3.9 KB checked in by mattausch, 17 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of the GameTools Project
4http://www.gametools.org
5
6Author: Martin Szydlowski
7-----------------------------------------------------------------------------
8*/
9
10#include "OgreBvhRenderable.h"
11#include "OgreBvHierarchySceneManager.h"
12#include "OgreBvHierarchyInterface.h"
13
14namespace Ogre
15{
16
17BvHierarchyInterface::BvHierarchyInterface(BvHierarchySceneManager *sm, RenderSystem *rsys):
18PlatformHierarchyInterface(sm, rsys)
19{
20
21}
22
23bool BvHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
24{
25        return BVHNODEPTR_CAST(node)->isLeaf();
26}
27
28void 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
52void 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
67void 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
78float BvHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
79{
80        const Vector3 pos = BVHNODEPTR_CAST(node)->mAABB.getCenter();
81        return (mCameraPosition - pos).squaredLength();
82}
83
84AxisAlignedBox * 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
97bool BvHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
98{
99        return BVHNODEPTR_CAST(node)->hasGeometry();
100}
101
102void BvHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const
103{
104        BVHNODEPTR_CAST(node)->setNodeVisible(visible);
105}
106
107bool BvHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
108{
109        return BVHNODEPTR_CAST(node)->isNodeVisible();
110}
111
112void BvHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const
113{
114        BVHNODEPTR_CAST(node)->setLastVisited(frameId);
115}
116
117unsigned int BvHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
118{
119        return BVHNODEPTR_CAST(node)->lastVisited();
120}
121
122void 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
139void BvHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
140                                                                                                   GtpVisibility::GeometryVector *geometryList,
141                                                                                                   bool includeChildren)
142{
143        BVHNODEPTR_CAST(node)->getGeometryList(geometryList);
144}
145
146} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.