[777] | 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 |
|
---|
| 29 | // Listener class for frame updates
|
---|
| 30 | class ParticleDemoFrameListener : public ExampleFrameListener
|
---|
| 31 | {
|
---|
| 32 | protected:
|
---|
| 33 |
|
---|
| 34 | unsigned long framecount;
|
---|
| 35 |
|
---|
| 36 | public:
|
---|
| 37 | ParticleDemoFrameListener(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 ParticleDemoApplication : public ExampleApplication
|
---|
| 57 | {
|
---|
| 58 |
|
---|
| 59 | public:
|
---|
[1487] | 60 | /* virtual void go(void)
|
---|
[777] | 61 | {
|
---|
| 62 | if (!setup())
|
---|
| 63 | return;
|
---|
| 64 |
|
---|
| 65 | renderScene();
|
---|
| 66 |
|
---|
| 67 | // clean up
|
---|
| 68 | destroyScene();
|
---|
[1487] | 69 | }*/
|
---|
[777] | 70 |
|
---|
| 71 | protected:
|
---|
| 72 | SceneNode* kupolaNode;
|
---|
| 73 | SceneNode* mainLightNode;
|
---|
[1487] | 74 | /*
|
---|
[777] | 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 |
|
---|
[875] | 99 | //mRoot->renderOneFrame();
|
---|
| 100 | mRoot->_updateAllRenderTargets();
|
---|
| 101 |
|
---|
[777] | 102 | mRoot->_fireFrameEnded();
|
---|
| 103 |
|
---|
| 104 | }
|
---|
[1487] | 105 | }*/
|
---|
[777] | 106 |
|
---|
[2025] | 107 | void loadResources(void)
|
---|
| 108 | {
|
---|
| 109 | // Initialise, parse scripts etc
|
---|
| 110 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
| 111 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
| 112 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
[2125] | 113 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
| 114 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap");
|
---|
| 115 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic");
|
---|
[2057] | 116 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Particles");
|
---|
[2025] | 117 | }
|
---|
| 118 |
|
---|
[788] | 119 | void createPostproc()
|
---|
[2025] | 120 | {
|
---|
[788] | 121 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
[2025] | 122 | "GTP/PostProc/Glow");
|
---|
[788] | 123 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[2025] | 124 | "GTP/PostProc/Glow", true);
|
---|
| 125 |
|
---|
| 126 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 127 | "GTP/PostProc/ToneMap");
|
---|
| 128 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
| 129 | "GTP/PostProc/ToneMap", true);
|
---|
[788] | 130 | }
|
---|
[777] | 131 |
|
---|
[2175] | 132 | void chooseSceneManager()
|
---|
| 133 | {
|
---|
| 134 | //mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
| 135 | mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
| 136 | }
|
---|
[777] | 137 |
|
---|
| 138 | void createScene(void)
|
---|
| 139 | {
|
---|
[2315] | 140 | //createPostproc();
|
---|
[777] | 141 |
|
---|
[2260] | 142 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
| 143 | mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
| 144 |
|
---|
[777] | 145 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 146 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
| 147 |
|
---|
| 148 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
| 149 | mCamera->setPosition(0,100,240);
|
---|
| 150 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
| 151 | //mCamera->setFarClipDistance(1000);
|
---|
| 152 | // Set ambient light
|
---|
| 153 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
| 154 |
|
---|
| 155 | // Skybox
|
---|
| 156 | mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
| 157 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 158 |
|
---|
| 159 |
|
---|
[2057] | 160 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("tuzecske", "GTP/SBB");
|
---|
[777] | 161 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
| 162 | SceneNode *pSysNode = rootNode->createChildSceneNode();
|
---|
| 163 | pSysNode->attachObject(pSys1);
|
---|
[1054] | 164 | //pSysNode->setPosition(0,100,0);
|
---|
[777] | 165 |
|
---|
| 166 |
|
---|
| 167 | //init objects
|
---|
| 168 | Entity* kupola = mSceneMgr->createEntity("kupola", "kupola.mesh");
|
---|
| 169 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
| 170 |
|
---|
| 171 | //init nodes
|
---|
| 172 | kupolaNode = rootNode->createChildSceneNode( "kupola" );
|
---|
| 173 | kupolaNode->rotate(Vector3(0,1,0),Radian(Degree(90)));
|
---|
| 174 | kupolaNode->attachObject( kupola );
|
---|
| 175 | kupolaNode->scale(25,21,25);
|
---|
| 176 | kupolaNode->_updateBounds();
|
---|
| 177 | MeshPtr kmesh = kupola->getMesh();
|
---|
| 178 | kmesh->buildTangentVectors(0,1);
|
---|
| 179 |
|
---|
| 180 | SceneNode* headNode = rootNode->createChildSceneNode("head");
|
---|
| 181 | headNode->attachObject(head);
|
---|
| 182 | headNode->setScale(2,2,2);
|
---|
| 183 | AxisAlignedBox bbox = head->getBoundingBox();
|
---|
| 184 | headNode->setPosition(0, 100,0);
|
---|
| 185 | headNode->_updateBounds();
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | //Init lights
|
---|
| 189 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 190 | mainLight->setType(Light::LT_POINT);
|
---|
| 191 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 192 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 193 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 194 | mainLightNode->setPosition(0,150,0);
|
---|
| 195 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
| 196 | mainLightNode->attachObject(mainLight);
|
---|
| 197 |
|
---|
[2057] | 198 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
| 199 | /*
|
---|
[777] | 200 | {//SBB
|
---|
| 201 | OgreSharedRuns* sharedruns = new OgreSharedRuns();
|
---|
| 202 | OgreIlluminationManager::getSingleton().addSharedRuns(sharedruns);
|
---|
| 203 | OgreTechniqueGroup* group = new OgreTechniqueGroup();
|
---|
| 204 | group->addSharedRun(sharedruns);
|
---|
| 205 | SpriteParticleRenderer* renderer = (SpriteParticleRenderer*)pSys1->getRenderer();
|
---|
[1356] | 206 | OgreRenderable* rend = new OgreRenderable(renderer->getSpriteSet(), pSys1);
|
---|
[777] | 207 | sharedruns->addRenderable(rend);
|
---|
| 208 | sharedruns->updateBounds();
|
---|
| 209 | Material* mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/SBB").getPointer();
|
---|
| 210 |
|
---|
| 211 | OgreSBBRenderTechnique* techn =
|
---|
| 212 | new OgreSBBRenderTechnique(1,
|
---|
| 213 | mat->getTechnique(0)->getPass(0),
|
---|
| 214 | rend,
|
---|
| 215 | group
|
---|
| 216 | );
|
---|
| 217 | group->addRenderTechnique(techn);
|
---|
| 218 | renderer->getSpriteSet()->setRenderTechniqueGroup(group);
|
---|
[2057] | 219 | }*/
|
---|
[777] | 220 |
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | void createFrameListener(void)
|
---|
| 224 | {
|
---|
| 225 | // This is where we instantiate our own frame listener
|
---|
| 226 | mFrameListener= new ParticleDemoFrameListener(mWindow,
|
---|
| 227 | mCamera );
|
---|
[2175] | 228 | mFrameListener->setPriority(2);
|
---|
| 229 | OgreIlluminationManager::getSingleton().setPriority(3);
|
---|
| 230 | mRoot->addFrameListener(mFrameListener);
|
---|
| 231 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
[1487] | 232 | }
|
---|
[777] | 233 |
|
---|
| 234 | };
|
---|
| 235 |
|
---|