source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp @ 1195

Revision 1195, 4.1 KB checked in by szydlowski, 18 years ago (diff)

visualization workin' fine (TM)
demo recording/playback partially implemented

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