[1080] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | You may use this sample code for anything you like, it is not covered by the
|
---|
| 11 | LGPL like the rest of the engine.
|
---|
| 12 | -----------------------------------------------------------------------------
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | /**
|
---|
| 16 | \file
|
---|
| 17 | Lighting.h
|
---|
| 18 | \brief
|
---|
| 19 | Shows lighting support in OGRE. Also demonstrates the use of billboards
|
---|
| 20 | and controllers for automatic time-relative behaviour.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | #include "ExampleApplication.h"
|
---|
| 25 | #include "OgreIlluminationManager.h"
|
---|
| 26 | #include "SceneSerializer.h"
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | // Listener class for frame updates
|
---|
| 30 | class PRMDemoFrameListener : public ExampleFrameListener
|
---|
| 31 | {
|
---|
| 32 | protected:
|
---|
| 33 |
|
---|
| 34 | unsigned long framecount;
|
---|
| 35 |
|
---|
| 36 | public:
|
---|
| 37 | PRMDemoFrameListener(RenderWindow* window, Camera* maincam)
|
---|
| 38 | :ExampleFrameListener(window, maincam)
|
---|
| 39 |
|
---|
| 40 | {
|
---|
| 41 | framecount = 0;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | bool frameStarted(const FrameEvent& evt)
|
---|
| 45 | {
|
---|
| 46 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
| 47 | framecount++;
|
---|
| 48 | return result;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | };
|
---|
| 54 |
|
---|
| 55 | /** Application class */
|
---|
| 56 | class PRMDemoApplication : public ExampleApplication
|
---|
| 57 | {
|
---|
| 58 |
|
---|
| 59 | public:
|
---|
| 60 | virtual void go(void)
|
---|
| 61 | {
|
---|
| 62 | if (!setup())
|
---|
| 63 | return;
|
---|
| 64 |
|
---|
| 65 | renderScene();
|
---|
| 66 |
|
---|
| 67 | // clean up
|
---|
| 68 | destroyScene();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | protected:
|
---|
| 72 | SceneNode* kupolaNode;
|
---|
| 73 | SceneNode* mainLightNode;
|
---|
| 74 |
|
---|
| 75 | void renderScene(){
|
---|
| 76 |
|
---|
| 77 | mWindow->resetStatistics();
|
---|
| 78 | while(true){
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 82 | // Pump events on Win32
|
---|
| 83 | MSG msg;
|
---|
| 84 | while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
|
---|
| 85 | {
|
---|
| 86 | TranslateMessage( &msg );
|
---|
| 87 | DispatchMessage( &msg );
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | #endif
|
---|
| 91 |
|
---|
| 92 | if(!mRoot->_fireFrameStarted()){
|
---|
| 93 | break;
|
---|
| 94 | }
|
---|
| 95 | unsigned long framenum = mRoot->getCurrentFrameNumber();
|
---|
| 96 |
|
---|
| 97 | OgreIlluminationManager::getSingleton().update(framenum, mWindow);
|
---|
| 98 |
|
---|
| 99 | //mRoot->renderOneFrame();
|
---|
| 100 | mRoot->_updateAllRenderTargets();
|
---|
| 101 |
|
---|
| 102 | mRoot->_fireFrameEnded();
|
---|
| 103 |
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | void createPostproc()
|
---|
| 108 | {
|
---|
| 109 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 110 | "GameTools/Glow");
|
---|
| 111 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
| 112 | "GameTools/Glow", true);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | void createScene(void)
|
---|
| 117 | {
|
---|
| 118 | //createPostproc();
|
---|
| 119 |
|
---|
| 120 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 121 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
| 122 |
|
---|
| 123 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
| 124 | mCamera->setPosition(0,100,240);
|
---|
| 125 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
| 126 | //mCamera->setFarClipDistance(1000);
|
---|
| 127 | // Set ambient light
|
---|
| 128 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
| 129 | mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
| 130 |
|
---|
| 131 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 132 |
|
---|
| 133 | SceneSerializer s(mSceneMgr);
|
---|
| 134 | DataStreamPtr inputStream;
|
---|
| 135 | inputStream = ResourceGroupManager::getSingleton().openResource("level.txt");
|
---|
| 136 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 137 |
|
---|
| 138 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
[1086] | 139 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
[1080] | 140 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 141 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 142 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 143 |
|
---|
| 144 | mainLightNode->setPosition(0,0,0);
|
---|
| 145 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
[1086] | 146 | mainLight->setDirection(-1,-1,-1);
|
---|
[1080] | 147 | mainLightNode->attachObject(mainLight);
|
---|
[1086] | 148 |
|
---|
| 149 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[1080] | 150 | }
|
---|
| 151 |
|
---|
| 152 | void createFrameListener(void)
|
---|
| 153 | {
|
---|
| 154 | // This is where we instantiate our own frame listener
|
---|
| 155 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
| 156 | mCamera );
|
---|
| 157 | mRoot->addFrameListener(mFrameListener);
|
---|
| 158 |
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | };
|
---|
| 162 |
|
---|