source: branches/VUT/DummyModules/Ogre/src/OgrePlatformHierarchyInterface.cpp @ 59

Revision 59, 4.1 KB checked in by mattausch, 19 years ago (diff)

completely changed file structure plus software design

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