[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 |
|
---|
| 28 |
|
---|
[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");
|
---|
| 82 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Particles");
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[1054] | 85 | void createPostproc()
|
---|
[2025] | 86 | {
|
---|
[1054] | 87 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
[2025] | 88 | "GTP/PostProc/Glow");
|
---|
[1054] | 89 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[2025] | 90 | "GTP/PostProc/Glow", true);
|
---|
| 91 |
|
---|
| 92 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 93 | "GTP/PostProc/ToneMap");
|
---|
| 94 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
| 95 | "GTP/PostProc/ToneMap", true);
|
---|
[1054] | 96 | }
|
---|
| 97 |
|
---|
[2175] | 98 | void chooseSceneManager()
|
---|
| 99 | {
|
---|
[1879] | 100 | if(scene == 1)
|
---|
[2175] | 101 | {
|
---|
[2301] | 102 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
| 103 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
[2175] | 104 | }
|
---|
[1879] | 105 | else if(scene == 2)
|
---|
[2175] | 106 | mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
|
---|
| 107 | }
|
---|
[1054] | 108 |
|
---|
| 109 | void createScene(void)
|
---|
| 110 | {
|
---|
[1834] | 111 | //createPostproc();
|
---|
[2252] | 112 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
[2301] | 113 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
[2179] | 114 |
|
---|
[1054] | 115 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 116 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
[1671] | 117 |
|
---|
[1879] | 118 |
|
---|
[1054] | 119 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
[1879] | 120 |
|
---|
[1054] | 121 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
[1879] | 122 | mCamera->setFarClipDistance(5000);
|
---|
[1054] | 123 | // Set ambient light
|
---|
| 124 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
| 125 |
|
---|
| 126 | // Skybox
|
---|
[1442] | 127 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 10);
|
---|
[1879] | 128 |
|
---|
| 129 |
|
---|
[1442] | 130 |
|
---|
[1879] | 131 |
|
---|
[1423] | 132 |
|
---|
[1879] | 133 | // OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PHASE_TEXTURE);
|
---|
| 134 | // OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PHASE_TEXTURE, 1);
|
---|
| 135 | // OgreIlluminationManager::getSingleton().savePhaseTextureToFile("phase.dds");
|
---|
| 136 |
|
---|
[1054] | 137 |
|
---|
[1879] | 138 | if(scene == 1)
|
---|
| 139 | createScene1();
|
---|
| 140 | else if(scene == 2)
|
---|
| 141 | createScene2();
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
| 145 |
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | void createScene1()
|
---|
| 149 | {
|
---|
| 150 | mCamera->setPosition(0,150,100);
|
---|
| 151 | mCamera->setDirection(0,0,-1);
|
---|
| 152 |
|
---|
| 153 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 154 |
|
---|
| 155 | Entity* head = mSceneMgr->createEntity("head", "athene.mesh");
|
---|
| 156 | SceneNode* headNode = rootNode->createChildSceneNode("head");
|
---|
| 157 | head->setMaterialName("GameTools/Standard");
|
---|
| 158 | headNode->attachObject(head);
|
---|
| 159 | //headNode->setScale(1.5,1.5,1.5);
|
---|
| 160 | AxisAlignedBox bbox = head->getBoundingBox();
|
---|
| 161 | headNode->setPosition(0,80,20);
|
---|
| 162 | headNode->_updateBounds();
|
---|
| 163 |
|
---|
| 164 |
|
---|
[2025] | 165 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/HPS/Smoke_Large");
|
---|
[1879] | 166 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
| 167 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
| 168 | pSysNode->attachObject(pSys1);
|
---|
| 169 | pSysNode->setPosition(0,0,0);
|
---|
| 170 |
|
---|
[1054] | 171 | //Init lights
|
---|
| 172 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 173 | mainLight->setType(Light::LT_POINT);
|
---|
| 174 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 175 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 176 | mainLightNode = rootNode->createChildSceneNode();
|
---|
[1423] | 177 | mainLightNode->setPosition(0,500,0);
|
---|
[1054] | 178 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
| 179 | mainLightNode->attachObject(mainLight);
|
---|
[1423] | 180 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
| 181 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
| 182 | bbs->setMaterialName("Flare");
|
---|
| 183 | mainLightNode->attachObject(bbs);
|
---|
[1879] | 184 | }
|
---|
[1059] | 185 |
|
---|
[1879] | 186 | void createScene2()
|
---|
| 187 | {
|
---|
| 188 | mCamera->setPosition(0,150,100);
|
---|
| 189 | mCamera->setDirection(0,0,-1);
|
---|
[1423] | 190 |
|
---|
[1879] | 191 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 192 | std::string terrain_cfg("terrain.cfg");
|
---|
| 193 | mSceneMgr -> setWorldGeometry( terrain_cfg );
|
---|
| 194 |
|
---|
| 195 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GameTools/FogBig");
|
---|
| 196 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
| 197 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
| 198 | pSysNode->attachObject(pSys1);
|
---|
| 199 | pSysNode->setPosition(600,-50,600);
|
---|
[1054] | 200 |
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | void createFrameListener(void)
|
---|
| 204 | {
|
---|
| 205 | // This is where we instantiate our own frame listener
|
---|
| 206 | mFrameListener= new ParticleDemoFrameListener(mWindow,
|
---|
[1423] | 207 | mCamera , mainLightNode);
|
---|
[2175] | 208 | mFrameListener->setPriority(2);
|
---|
| 209 | OgreIlluminationManager::getSingleton().setPriority(10);
|
---|
[1671] | 210 | mRoot->addFrameListener(mFrameListener);
|
---|
[1535] | 211 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
[1879] | 212 |
|
---|
| 213 |
|
---|
[1535] | 214 |
|
---|
[1054] | 215 | }
|
---|
| 216 |
|
---|
| 217 | };
|
---|
| 218 |
|
---|