source: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp @ 92

Revision 92, 4.2 KB checked in by mattausch, 19 years ago (diff)

exchanged halfbounding box with full bounding box

RevLine 
[59]1#include <OgreCamera.h>
2
[92]3//#include "OgreSolidHalfBoundingBox.h"
4#include "OgreSolidBoundingBox.h"
[59]5#include "OgrePlatformHierarchyInterface.h"
6#include "OgrePlatformOcclusionQuery.h"
[86]7#include <windows.h>
[59]8
9namespace Ogre {
10
11//-----------------------------------------------------------------------
[74]12PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
[92]13mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL)/*, mSolidHalfBoundingBox(NULL)*/
[85]14{
[59]15}
16//-----------------------------------------------------------------------
17PlatformHierarchyInterface::~PlatformHierarchyInterface()
18{
19        DeleteQueries();
20
[92]21        if(mSolidBoundingBox)
22                delete mSolidBoundingBox;
[59]23}
24//-----------------------------------------------------------------------
25void PlatformHierarchyInterface::DeleteQueries()
26{
[87]27        for(int i=0; i < (int)mOcclusionQueries.size(); ++i)
[59]28                delete mOcclusionQueries[i];
29
30        mOcclusionQueries.clear();
31}
32//-----------------------------------------------------------------------
33void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box)
34{
[86]35        static RenderOperation ro;
36
37        //TODO: this should be the full bounding box
[92]38        SolidBoundingBox *solidBox = GetSolidBoundingBox();
[86]39       
40        mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
[92]41        mSceneManager->useRenderableViewProjMode(solidBox);
42    mSceneManager->setPass(solidBox->getTechnique()->getPass(0));
[86]43
[92]44        solidBox->SetupBoundingBoxVertices(*box);
45                               
46        solidBox->getRenderOperation(ro);
47        ro.srcRenderable = solidBox;
48        mRenderSystem->_render(ro);
49
[59]50        // Render two halfes of the bounding box (using triangle fans)
[92]51        /*for(int halfIdx = 0; halfIdx < 2; ++halfIdx)
[59]52        {
[92]53                solidBox->SetupBoundingBoxVertices(*box, halfIdx == 1);
[85]54                               
[92]55                solidBox->getRenderOperation(ro);
56                ro.srcRenderable = solidBox;
[91]57                mRenderSystem->_render(ro);
[92]58        }*/
[59]59}
60//-----------------------------------------------------------------------
61void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
62{
63        mCamera = cam;
64}
65//-----------------------------------------------------------------------
66GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
67{
68        if(mCurrentTestIdx == mOcclusionQueries.size())
69        {
70                mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
71        }
72       
73        return mOcclusionQueries[mCurrentTestIdx ++];
74}
75//-----------------------------------------------------------------------
76void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam)
77{
78        GtpVisibility::HierarchyInterface::InitFrame(root);
[86]79        mPreviousNode = NULL;
[59]80        SetCamera(cam);
81}
82//-----------------------------------------------------------------------
83void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
84{
85        mSceneManager = sm;
86}
87//-----------------------------------------------------------------------
88void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
89{
90        mRenderSystem = rsys;
91}
92//-----------------------------------------------------------------------
[85]93bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node,
94                                                                                                         bool &intersects)
[59]95{
96#ifdef GTP_VISIBILITY_MODIFIED_OGRE
97        return mCamera->isVisible(*GetBoundingBox(node), intersects);
98#else
99        return true;
100#endif
101}
102//-----------------------------------------------------------------------
[85]103GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(
[86]104        GtpVisibility::HierarchyNode *node, const bool wasVisible)
[59]105{
106        // get next available test id
107        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
108
109        //-- the actual query test
110        query->BeginQuery();
111                       
[91]112        // if node is leaf and was visible => will be rendered anyway.
[87]113        // In this case we can also test with the real geometry.
[89]114        if(mUseOptimization && wasVisible && IsLeaf(node))
[86]115        {
116                RenderNode(node);
117        }
118        else
[89]119        {
[86]120                RenderBoundingBox(GetBoundingBox(node));
[89]121        }
[59]122
123        query->EndQuery();
124       
125        return query;
126}
[85]127//-----------------------------------------------------------------------
[92]128SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
[85]129{
[92]130        if(!mSolidBoundingBox)
131                mSolidBoundingBox = new SolidBoundingBox;
[59]132
[92]133        return mSolidBoundingBox;
[85]134}
135
[59]136} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.