[1054] | 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 "SpriteParticleRenderer.h"
|
---|
| 27 |
|
---|
[2426] | 28 | bool visibilitySM = false;
|
---|
[2025] | 29 | int scene = 1;
|
---|
[1879] | 30 |
|
---|
[1054] | 31 | // Listener class for frame updates
|
---|
| 32 | class ParticleDemoFrameListener : public ExampleFrameListener
|
---|
| 33 | {
|
---|
| 34 | protected:
|
---|
| 35 |
|
---|
[1423] | 36 | SceneNode* lightNode;
|
---|
| 37 |
|
---|
[1054] | 38 | public:
|
---|
[1423] | 39 | ParticleDemoFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode)
|
---|
[1054] | 40 | :ExampleFrameListener(window, maincam)
|
---|
| 41 |
|
---|
| 42 | {
|
---|
[1879] | 43 | this->lightNode = lightNode;
|
---|
[1054] | 44 | }
|
---|
| 45 |
|
---|
| 46 | bool frameStarted(const FrameEvent& evt)
|
---|
| 47 | {
|
---|
| 48 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
[1423] | 49 |
|
---|
[1879] | 50 | if(scene == 1)
|
---|
| 51 | {
|
---|
| 52 | Timer* timer = Root::getSingleton().getTimer();
|
---|
| 53 |
|
---|
| 54 | float t = (float) timer->getMilliseconds() / 2000.0;
|
---|
| 55 | float r = 150;
|
---|
| 56 | lightNode->setPosition( r * sin(t), r * sin(5 * t) + 200 , r * cos(t));
|
---|
| 57 | }
|
---|
[1054] | 58 | return result;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | /** Application class */
|
---|
| 66 | class ParticleDemoApplication : public ExampleApplication
|
---|
| 67 | {
|
---|
| 68 |
|
---|
| 69 | public:
|
---|
| 70 |
|
---|
| 71 | protected:
|
---|
| 72 | SceneNode* kupolaNode;
|
---|
| 73 | SceneNode* mainLightNode;
|
---|
| 74 |
|
---|
[2025] | 75 | void loadResources(void)
|
---|
| 76 | {
|
---|
| 77 | // Initialise, parse scripts etc
|
---|
| 78 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
| 79 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
[2301] | 80 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
[2025] | 81 | //ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
[2426] | 82 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
[2025] | 83 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Particles");
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[1054] | 86 | void createPostproc()
|
---|
[2025] | 87 | {
|
---|
[1054] | 88 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
[2025] | 89 | "GTP/PostProc/Glow");
|
---|
[1054] | 90 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[2025] | 91 | "GTP/PostProc/Glow", true);
|
---|
| 92 |
|
---|
| 93 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 94 | "GTP/PostProc/ToneMap");
|
---|
| 95 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
| 96 | "GTP/PostProc/ToneMap", true);
|
---|
[1054] | 97 | }
|
---|
| 98 |
|
---|
[2175] | 99 | void chooseSceneManager()
|
---|
| 100 | {
|
---|
[2426] | 101 | if(visibilitySM)
|
---|
| 102 | mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
| 103 | else
|
---|
[2175] | 104 | {
|
---|
[2426] | 105 |
|
---|
| 106 | if(scene == 1)
|
---|
| 107 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
| 108 | else if(scene == 2)
|
---|
| 109 | mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[2175] | 112 | }
|
---|
[1054] | 113 | void createScene(void)
|
---|
| 114 | {
|
---|
[2426] | 115 |
|
---|
[1054] | 116 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 117 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
[1671] | 118 |
|
---|
[1879] | 119 |
|
---|
[1054] | 120 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
[1879] | 121 |
|
---|
[1054] | 122 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
[1879] | 123 | mCamera->setFarClipDistance(5000);
|
---|
[1054] | 124 | // Set ambient light
|
---|
| 125 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
| 126 |
|
---|
| 127 | // Skybox
|
---|
[1442] | 128 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 10);
|
---|
[1879] | 129 |
|
---|
| 130 |
|
---|
[1442] | 131 |
|
---|
[1879] | 132 |
|
---|
[1423] | 133 |
|
---|
[2426] | 134 | //OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PHASE_TEXTURE);
|
---|
| 135 | //OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PHASE_TEXTURE, 1);
|
---|
| 136 | //OgreIlluminationManager::getSingleton().savePhaseTextureToFile("phase.dds");
|
---|
[1879] | 137 |
|
---|
[1054] | 138 |
|
---|
[1879] | 139 | if(scene == 1)
|
---|
| 140 | createScene1();
|
---|
| 141 | else if(scene == 2)
|
---|
| 142 | createScene2();
|
---|
| 143 |
|
---|
| 144 |
|
---|
[2426] | 145 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[1879] | 146 |
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | void createScene1()
|
---|
| 150 | {
|
---|
[2426] | 151 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
| 152 | if(visibilitySM)
|
---|
| 153 | mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
| 154 |
|
---|
[1879] | 155 | mCamera->setPosition(0,150,100);
|
---|
| 156 | mCamera->setDirection(0,0,-1);
|
---|
| 157 |
|
---|
| 158 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 159 |
|
---|
| 160 | Entity* head = mSceneMgr->createEntity("head", "athene.mesh");
|
---|
| 161 | SceneNode* headNode = rootNode->createChildSceneNode("head");
|
---|
| 162 | head->setMaterialName("GameTools/Standard");
|
---|
| 163 | headNode->attachObject(head);
|
---|
| 164 | //headNode->setScale(1.5,1.5,1.5);
|
---|
| 165 | AxisAlignedBox bbox = head->getBoundingBox();
|
---|
| 166 | headNode->setPosition(0,80,20);
|
---|
| 167 | headNode->_updateBounds();
|
---|
| 168 |
|
---|
| 169 |
|
---|
[2436] | 170 | // ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/HPS/Smoke_Large");
|
---|
| 171 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/Smoke_Large");
|
---|
[1879] | 172 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
| 173 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
| 174 | pSysNode->attachObject(pSys1);
|
---|
| 175 | pSysNode->setPosition(0,0,0);
|
---|
| 176 |
|
---|
[1054] | 177 | //Init lights
|
---|
| 178 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 179 | mainLight->setType(Light::LT_POINT);
|
---|
| 180 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 181 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 182 | mainLightNode = rootNode->createChildSceneNode();
|
---|
[1423] | 183 | mainLightNode->setPosition(0,500,0);
|
---|
[1054] | 184 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
| 185 | mainLightNode->attachObject(mainLight);
|
---|
[1423] | 186 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
| 187 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
| 188 | bbs->setMaterialName("Flare");
|
---|
| 189 | mainLightNode->attachObject(bbs);
|
---|
[1879] | 190 | }
|
---|
[1059] | 191 |
|
---|
[1879] | 192 | void createScene2()
|
---|
| 193 | {
|
---|
| 194 | mCamera->setPosition(0,150,100);
|
---|
| 195 | mCamera->setDirection(0,0,-1);
|
---|
[1423] | 196 |
|
---|
[1879] | 197 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
[2426] | 198 | if(visibilitySM)
|
---|
| 199 | {
|
---|
| 200 | std::string terrain_cfg("VisTerrain.cfg");
|
---|
| 201 | mSceneMgr -> setWorldGeometry( terrain_cfg );
|
---|
| 202 | }
|
---|
| 203 | else
|
---|
| 204 | {
|
---|
| 205 | std::string terrain_cfg("terrain.cfg");
|
---|
| 206 | mSceneMgr -> setWorldGeometry( terrain_cfg );
|
---|
| 207 | }
|
---|
[1879] | 208 |
|
---|
[2426] | 209 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/HPS/Smoke_Large");
|
---|
[1879] | 210 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
| 211 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
| 212 | pSysNode->attachObject(pSys1);
|
---|
| 213 | pSysNode->setPosition(600,-50,600);
|
---|
[2426] | 214 |
|
---|
| 215 | //Init lights
|
---|
| 216 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 217 | mainLight->setType(Light::LT_POINT);
|
---|
| 218 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 219 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 220 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 221 | mainLightNode->setPosition(0,500,0);
|
---|
| 222 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
| 223 | mainLightNode->attachObject(mainLight);
|
---|
| 224 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
| 225 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
| 226 | bbs->setMaterialName("Flare");
|
---|
| 227 | mainLightNode->attachObject(bbs);
|
---|
[1054] | 228 |
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | void createFrameListener(void)
|
---|
| 232 | {
|
---|
| 233 | // This is where we instantiate our own frame listener
|
---|
| 234 | mFrameListener= new ParticleDemoFrameListener(mWindow,
|
---|
[1423] | 235 | mCamera , mainLightNode);
|
---|
[2175] | 236 | mFrameListener->setPriority(2);
|
---|
| 237 | OgreIlluminationManager::getSingleton().setPriority(10);
|
---|
[1671] | 238 | mRoot->addFrameListener(mFrameListener);
|
---|
[1535] | 239 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
[1879] | 240 |
|
---|
| 241 |
|
---|
[1535] | 242 |
|
---|
[1054] | 243 | }
|
---|
| 244 |
|
---|
| 245 | };
|
---|
| 246 |
|
---|