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

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