source: trunk/VUT/work/iv/TestCullingIVApplication.cpp @ 343

Revision 343, 10.2 KB checked in by mattausch, 19 years ago (diff)

added switch between NV and ARB queries in the render system and in the demos.
Fixed render queue bug: when clearing queue, we traversed through all priority groups
to clear the passmaps. This became very slow because had to traverse many elements (over 1000
for city demo). Now all we destroy the priority groups for each rendering (per hierarchy node).

Line 
1#include <OgreNoMemoryMacros.h>
2#include <CEGUI/CEGUI.h>
3#include <../CEGUIRenderer/include/OgreCEGUIRenderer.h>
4#include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h>
5#include <../CEGUIRenderer/include/OgreCEGUITexture.h>
6#include <OgreMemoryMacros.h>
7
8#include <Ogre.h>
9
10//#include "OgreReferenceAppLayer.h"
11//#include "OgreRefAppWorld.h"
12#include "TestCullingIVApplication.h"
13#include "IVFrameListener.h"
14
15#define WIN32_LEAN_AND_MEAN
16#include <windows.h>
17
18
19/*********************************************************/
20/*        TestCullingIVApplication implementation        */
21/*********************************************************/
22
23//-----------------------------------------------------------------------
24TestCullingIVApplication::TestCullingIVApplication()
25{
26        mIVReader = new IVReader();
27}
28//-----------------------------------------------------------------------
29TestCullingIVApplication::~TestCullingIVApplication()
30{
31        OGRE_DELETE(mIVReader);
32}
33//-----------------------------------------------------------------------
34void TestCullingIVApplication::createCamera()
35{
36        // create the camera
37        mCamera = mSceneMgr->createCamera("PlayerCam");
38        // Look back along -Z
39    mCamera->lookAt(Vector3(0, 0, -300));
40       
41        /** set a nice viewpoint
42        *       we use a camera node here and apply all transformations on it instead
43        *       of applying all transformations directly to the camera
44        *       because then the camera is displayed correctly in the visualization
45        */
46        mCamNode = mSceneMgr->getRootSceneNode()->
47                createChildSceneNode("CamNode1", Vector3(0, -100, -200));
48
49        mCamNode->attachObject(mCamera);
50        //mCamNode->lookAt(Vector3(0, 0, -300), Node::TS_WORLD);
51        //mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
52
53        //-- create visualization camera
54        mVizCamera = mSceneMgr->createCamera("VizCam");
55        mVizCamera->setPosition(mCamNode->getPosition());
56
57        mVizCamera->setNearClipDistance(1);
58        mCamera->setNearClipDistance(1);
59
60        // infinite far plane?
61        if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
62        {
63                mVizCamera->setFarClipDistance(0);
64                mCamera->setFarClipDistance(0);
65        }
66        else
67        {
68                 mVizCamera->setFarClipDistance(20000);
69                 mCamera->setFarClipDistance(20000);
70        }       
71}
72
73//-----------------------------------------------------------------------
74bool TestCullingIVApplication::setup()
75{
76        bool carryOn = ExampleApplication::setup();
77
78        if (carryOn)
79                createRenderTargetListener();
80
81        return carryOn;
82}
83//-----------------------------------------------------------------------
84void TestCullingIVApplication::createRenderTargetListener()
85{
86        mWindow->addListener(new VisualizationRenderTargetListener(mSceneMgr));
87}
88//-----------------------------------------------------------------------
89void TestCullingIVApplication::createScene()
90{
91        Real scale = 1;
92        mSceneMgr->setOption("NodeVizScale", &scale);
93        // HACK: change this to relative path
94        String path = "D:/svn/trunk/VUT/Ogre/resources/";
95               
96        SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");
97        SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2");
98        SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node3");
99        SceneNode *node4 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node4");
100        SceneNode *node5 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node5");
101        SceneNode *node6 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node6");
102        SceneNode *node7 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node7");
103        SceneNode *node8 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node8");
104        SceneNode *node9 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node9");
105
106
107        node1->translate(Vector3(-500, 0, 750));
108        node2->translate(Vector3(-400, 0, 750));
109        node3->scale(Vector3(100, 100 ,100));
110        node3->pitch(Radian(3 * Math::HALF_PI));
111        node4->translate(Vector3(-100, 0, 0));
112        node5->translate(Vector3(0, 300, 0));
113       
114        node6->scale(Vector3(100, 100 ,100));
115        node6->pitch(Radian(3 * Math::HALF_PI));
116        node6->roll(Radian(Math::HALF_PI));
117        node6->translate(Vector3(0, -100, 0));
118
119        node7->scale(Vector3(100, 100 ,100));
120        node7->pitch(Radian(3 * Math::HALF_PI));
121        node7->roll(Radian(Math::HALF_PI));
122        node7->translate(Vector3(100, 0, 0));
123       
124        node8->translate(Vector3(-300, -300, 0));
125
126        Log *log = LogManager::getSingleton().createLog("IVLog.log");
127        mIVReader->setLog(log);
128
129        /*if (mIVReader->loadFile("media\\house_test1.iv"))
130        {
131                mIVReader->buildTree(mSceneMgr, node1);
132                mIVReader->buildTree(mSceneMgr, node2);
133        }
134        if (mIVReader->loadFile("media\\anhk.wrl"))
135        {
136                mIVReader->buildTree(mSceneMgr, node3);
137        }
138        if (mIVReader->loadFile("media\\ant.wrl"))
139        {
140                mIVReader->buildTree(mSceneMgr, node4);
141        }
142        if (mIVReader->loadFile("media\\zepplin0.wrl"))
143        {
144                mIVReader->buildTree(mSceneMgr, node5);
145        }
146        if (mIVReader->loadFile("media\\warbird.wrl"))
147        {
148                mIVReader->buildTree(mSceneMgr, node6);
149        }
150        if (mIVReader->loadFile("media\\z_wing.wrl"))
151        {
152                mIVReader->buildTree(mSceneMgr, node7);
153        }*/
154
155        String fileName = path + "media\\city1500_flat_1.iv";
156        if (mIVReader->loadFile(fileName.c_str()))
157        {
158                mIVReader->buildTree(mSceneMgr, node8);
159        }
160
161        fileName = path + "media\\roofs_1500.iv";
162        if (mIVReader->loadFile(fileName.c_str()))
163        {
164                mIVReader->buildTree(mSceneMgr, node8);
165        }
166
167        fileName = path + "media\\CityRoads60.iv";
168        if (mIVReader->loadFile(fileName.c_str()))
169        {
170                mIVReader->buildTree(mSceneMgr, node8);
171        }
172
173        fileName = path + "media\\CityPlane60.iv";
174    if (mIVReader->loadFile(fileName.c_str()))
175        {
176                mIVReader->buildTree(mSceneMgr, node8);
177        }
178       
179        fileName = path + "media\\test.iv";
180        if (mIVReader->loadFile(fileName.c_str()))
181        {
182                mIVReader->buildTree(mSceneMgr, node9);
183        }
184
185        mIVReader->collapse();
186
187       
188        // Set ambient light
189        mAmbientLight = ColourValue(0.5 , 0.5, 0.5);
190        mSceneMgr->setAmbientLight(mAmbientLight);
191       
192        //-- create light
193        mSunLight = mSceneMgr->createLight("SunLight");
194        mSunLight->setType(Light::LT_DIRECTIONAL);
195        //mSunLight->setType(Light::LT_SPOTLIGHT);
196        //mSunLight->setSpotlightRange(Degree(30), Degree(50));
197
198    mSunLight->setPosition(707, 2000, 500);
199        mSunLight->setCastShadows(true);
200
201        // set light angle not too small over the surface, otherwise shadows textures will be broken
202        Vector3 dir(0.5, 1, 0.5);
203        dir.normalise();
204        mSunLight->setDirection(dir);
205        //mSunLight->setDirection(Vector3::NEGATIVE_UNIT_Y);
206        mSunLight->setDiffuseColour(1, 1, 1);
207        mSunLight->setSpecularColour(1, 1, 1);
208
209        // -- Fog
210        // NB it's VERY important to set this before calling setWorldGeometry
211        // because the vertex program picked will be different
212        ColourValue fadeColour(0.93, 0.86, 0.76);
213        mWindow->getViewport(0)->setBackgroundColour(fadeColour);
214        //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
215       
216        // Create a skybox
217        mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true);
218       
219       
220        //-- CEGUI setup
221        setupGui();
222
223        // Use 512x512 texture in GL since we can't go higher than the window res
224        mSceneMgr->setShadowTextureSettings(512, 2);
225
226        mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
227}
228//-----------------------------------------------------------------------
229void TestCullingIVApplication::setupGui()
230{
231         mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY,
232                 false, 3000, ST_EXTERIOR_CLOSE);
233     mGUISystem = new CEGUI::System(mGUIRenderer);
234
235         // Mouse
236     CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
237     CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
238         mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook",
239                                                                           (CEGUI::utf8*)"MouseArrow");
240
241         CEGUI::MouseCursor::getSingleton().show();
242}
243//-----------------------------------------------------------------------
244void TestCullingIVApplication::createFrameListener()
245{
246        mIVFrameListener = new IVFrameListener(mWindow, mCamera, mSceneMgr,
247                mGUIRenderer, mVizCamera, mCamNode, mSunLight, this);
248       
249        mRoot->addFrameListener(mIVFrameListener);
250}
251//-----------------------------------------------------------------------
252void TestCullingIVApplication::chooseSceneManager()
253{
254        mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
255}
256
257
258
259/**************************************************************/
260/*      VisualizationRenderTargetListener implementation      */
261/**************************************************************/
262
263//-----------------------------------------------------------------------
264VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr)
265:RenderTargetListener(), mSceneMgr(sceneMgr)
266{
267}
268//-----------------------------------------------------------------------
269void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
270{
271        // visualization viewport
272        const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER;
273        const bool nShowViz = !showViz;
274
275        mSavedShadowTechnique = mSceneMgr->getShadowTechnique();
276        mSavedAmbientLight = mSceneMgr->getAmbientLight();
277
278        // -- ambient light must be full for visualization, shadows disabled
279    if (showViz)
280        {
281                mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
282                mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
283        }
284       
285    mSceneMgr->setOption("PrepareVisualization", &showViz);
286        mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
287        //mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
288       
289        RenderTargetListener::preViewportUpdate(evt);
290}
291//-----------------------------------------------------------------------
292void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
293{
294        // reset values
295        mSceneMgr->setShadowTechnique(mSavedShadowTechnique);
296        mSceneMgr->setAmbientLight(mSavedAmbientLight);
297       
298        RenderTargetListener::postRenderTargetUpdate(evt);
299}
300//-----------------------------------------------------------------------
301INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
302{
303    // Create application object
304    TestCullingIVApplication app;
305
306        try
307        {
308        app.go();
309    }
310        catch( Ogre::Exception& e )
311        {
312        MessageBox( NULL, e.getFullDescription().c_str(),
313                        "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
314    }   
315
316    return 0;
317}
Note: See TracBrowser for help on using the repository browser.