source: GTP-Internal/trunk/Lib/Vis/work/iv/TestCullingIVApplication.cpp @ 370

Revision 370, 10.3 KB checked in by mattausch, 19 years ago (diff)

fixed specular bug in trees
added batched query manager
added t information to ray bsp leaves

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 = "E:/svn/gametools/trunk/VUT/Ogre/resources/";
95        String path = "D:/svn/trunk/VUT/Ogre/resources/";
96       
97        SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");
98        SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2");
99        SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node3");
100        SceneNode *node4 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node4");
101        SceneNode *node5 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node5");
102        SceneNode *node6 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node6");
103        SceneNode *node7 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node7");
104        SceneNode *node8 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node8");
105        SceneNode *node9 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node9");
106
107
108        node1->translate(Vector3(-500, 0, 750));
109        node2->translate(Vector3(-400, 0, 750));
110        node3->scale(Vector3(100, 100 ,100));
111        node3->pitch(Radian(3 * Math::HALF_PI));
112        node4->translate(Vector3(-100, 0, 0));
113        node5->translate(Vector3(0, 300, 0));
114       
115        node6->scale(Vector3(100, 100 ,100));
116        node6->pitch(Radian(3 * Math::HALF_PI));
117        node6->roll(Radian(Math::HALF_PI));
118        node6->translate(Vector3(0, -100, 0));
119
120        node7->scale(Vector3(100, 100 ,100));
121        node7->pitch(Radian(3 * Math::HALF_PI));
122        node7->roll(Radian(Math::HALF_PI));
123        node7->translate(Vector3(100, 0, 0));
124       
125        node8->translate(Vector3(-300, -300, 0));
126
127        Log *log = LogManager::getSingleton().createLog("IVLog.log");
128        mIVReader->setLog(log);
129
130        /*if (mIVReader->loadFile("media\\house_test1.iv"))
131        {
132                mIVReader->buildTree(mSceneMgr, node1);
133                mIVReader->buildTree(mSceneMgr, node2);
134        }
135        if (mIVReader->loadFile("media\\anhk.wrl"))
136        {
137                mIVReader->buildTree(mSceneMgr, node3);
138        }
139        if (mIVReader->loadFile("media\\ant.wrl"))
140        {
141                mIVReader->buildTree(mSceneMgr, node4);
142        }
143        if (mIVReader->loadFile("media\\zepplin0.wrl"))
144        {
145                mIVReader->buildTree(mSceneMgr, node5);
146        }
147        if (mIVReader->loadFile("media\\warbird.wrl"))
148        {
149                mIVReader->buildTree(mSceneMgr, node6);
150        }
151        if (mIVReader->loadFile("media\\z_wing.wrl"))
152        {
153                mIVReader->buildTree(mSceneMgr, node7);
154        }*/
155
156        String fileName = path + "media\\city1500_flat_1.iv";
157        if (mIVReader->loadFile(fileName.c_str()))
158        {
159                mIVReader->buildTree(mSceneMgr, node8);
160        }
161
162        fileName = path + "media\\roofs_1500.iv";
163        if (mIVReader->loadFile(fileName.c_str()))
164        {
165                mIVReader->buildTree(mSceneMgr, node8);
166        }
167
168        fileName = path + "media\\CityRoads60.iv";
169        if (mIVReader->loadFile(fileName.c_str()))
170        {
171                mIVReader->buildTree(mSceneMgr, node8);
172        }
173
174        fileName = path + "media\\CityPlane60.iv";
175    if (mIVReader->loadFile(fileName.c_str()))
176        {
177                mIVReader->buildTree(mSceneMgr, node8);
178        }
179       
180        fileName = path + "media\\test.iv";
181        if (mIVReader->loadFile(fileName.c_str()))
182        {
183                mIVReader->buildTree(mSceneMgr, node9);
184        }
185
186        mIVReader->collapse();
187
188       
189        // Set ambient light
190        mAmbientLight = ColourValue(0.5 , 0.5, 0.5);
191        mSceneMgr->setAmbientLight(mAmbientLight);
192       
193        //-- create light
194        mSunLight = mSceneMgr->createLight("SunLight");
195        mSunLight->setType(Light::LT_DIRECTIONAL);
196        //mSunLight->setType(Light::LT_SPOTLIGHT);
197        //mSunLight->setSpotlightRange(Degree(30), Degree(50));
198
199    mSunLight->setPosition(707, 2000, 500);
200        mSunLight->setCastShadows(true);
201
202        // set light angle not too small over the surface, otherwise shadows textures will be broken
203        Vector3 dir(0.5, 1, 0.5);
204        dir.normalise();
205        mSunLight->setDirection(dir);
206        //mSunLight->setDirection(Vector3::NEGATIVE_UNIT_Y);
207        mSunLight->setDiffuseColour(1, 1, 1);
208        mSunLight->setSpecularColour(1, 1, 1);
209
210        // -- Fog
211        // NB it's VERY important to set this before calling setWorldGeometry
212        // because the vertex program picked will be different
213        ColourValue fadeColour(0.93, 0.86, 0.76);
214        mWindow->getViewport(0)->setBackgroundColour(fadeColour);
215        //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
216       
217        // Create a skybox
218        mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true);
219       
220       
221        //-- CEGUI setup
222        setupGui();
223
224        // Use 512x512 texture in GL since we can't go higher than the window res
225        mSceneMgr->setShadowTextureSettings(512, 2);
226
227        mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
228}
229//-----------------------------------------------------------------------
230void TestCullingIVApplication::setupGui()
231{
232         mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY,
233                 false, 3000, ST_EXTERIOR_CLOSE);
234     mGUISystem = new CEGUI::System(mGUIRenderer);
235
236         // Mouse
237     CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
238     CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
239         mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook",
240                                                                           (CEGUI::utf8*)"MouseArrow");
241
242         CEGUI::MouseCursor::getSingleton().show();
243}
244//-----------------------------------------------------------------------
245void TestCullingIVApplication::createFrameListener()
246{
247        mIVFrameListener = new IVFrameListener(mWindow, mCamera, mSceneMgr,
248                mGUIRenderer, mVizCamera, mCamNode, mSunLight, this);
249       
250        mRoot->addFrameListener(mIVFrameListener);
251}
252//-----------------------------------------------------------------------
253void TestCullingIVApplication::chooseSceneManager()
254{
255        mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
256}
257
258
259
260/**************************************************************/
261/*      VisualizationRenderTargetListener implementation      */
262/**************************************************************/
263
264//-----------------------------------------------------------------------
265VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr)
266:RenderTargetListener(), mSceneMgr(sceneMgr)
267{
268}
269//-----------------------------------------------------------------------
270void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
271{
272        // visualization viewport
273        const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER;
274        const bool nShowViz = !showViz;
275
276        mSavedShadowTechnique = mSceneMgr->getShadowTechnique();
277        mSavedAmbientLight = mSceneMgr->getAmbientLight();
278
279        // -- ambient light must be full for visualization, shadows disabled
280    if (showViz)
281        {
282                mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
283                mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
284        }
285       
286    mSceneMgr->setOption("PrepareVisualization", &showViz);
287        mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
288        //mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
289       
290        RenderTargetListener::preViewportUpdate(evt);
291}
292//-----------------------------------------------------------------------
293void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
294{
295        // reset values
296        mSceneMgr->setShadowTechnique(mSavedShadowTechnique);
297        mSceneMgr->setAmbientLight(mSavedAmbientLight);
298       
299        RenderTargetListener::postRenderTargetUpdate(evt);
300}
301//-----------------------------------------------------------------------
302INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
303{
304    // Create application object
305    TestCullingIVApplication app;
306
307        try
308        {
309        app.go();
310    }
311        catch( Ogre::Exception& e )
312        {
313        MessageBox( NULL, e.getFullDescription().c_str(),
314                        "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
315    }   
316
317    return 0;
318}
Note: See TracBrowser for help on using the repository browser.