[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 |
|
---|
| 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:
|
---|
| 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 |
|
---|
| 130 | // Skybox
|
---|
| 131 | mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
| 132 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 133 |
|
---|
| 134 |
|
---|
[1059] | 135 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GameTools/DemoParticle1");
|
---|
[1054] | 136 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
| 137 | SceneNode *pSysNode = rootNode->createChildSceneNode();
|
---|
| 138 | pSysNode->attachObject(pSys1);
|
---|
[1059] | 139 |
|
---|
[1054] | 140 | //pSysNode->setPosition(0,100,0);
|
---|
| 141 | /*
|
---|
| 142 |
|
---|
| 143 | //init objects
|
---|
| 144 | Entity* kupola = mSceneMgr->createEntity("kupola", "kupola.mesh");
|
---|
| 145 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
| 146 |
|
---|
| 147 | //init nodes
|
---|
| 148 | kupolaNode = rootNode->createChildSceneNode( "kupola" );
|
---|
| 149 | kupolaNode->rotate(Vector3(0,1,0),Radian(Degree(90)));
|
---|
| 150 | kupolaNode->attachObject( kupola );
|
---|
| 151 | kupolaNode->scale(25,21,25);
|
---|
| 152 | kupolaNode->_updateBounds();
|
---|
| 153 | MeshPtr kmesh = kupola->getMesh();
|
---|
| 154 | kmesh->buildTangentVectors(0,1);
|
---|
| 155 |
|
---|
| 156 | SceneNode* headNode = rootNode->createChildSceneNode("head");
|
---|
| 157 | headNode->attachObject(head);
|
---|
| 158 | headNode->setScale(2,2,2);
|
---|
| 159 | AxisAlignedBox bbox = head->getBoundingBox();
|
---|
| 160 | headNode->setPosition(0, 100,0);
|
---|
| 161 | headNode->_updateBounds();
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | //Init lights
|
---|
| 165 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 166 | mainLight->setType(Light::LT_POINT);
|
---|
| 167 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 168 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 169 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 170 | mainLightNode->setPosition(0,150,0);
|
---|
| 171 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
| 172 | mainLightNode->attachObject(mainLight);
|
---|
| 173 | */
|
---|
[1059] | 174 |
|
---|
| 175 |
|
---|
| 176 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[1054] | 177 |
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | void createFrameListener(void)
|
---|
| 181 | {
|
---|
| 182 | // This is where we instantiate our own frame listener
|
---|
| 183 | mFrameListener= new ParticleDemoFrameListener(mWindow,
|
---|
| 184 | mCamera );
|
---|
| 185 | mRoot->addFrameListener(mFrameListener);
|
---|
| 186 |
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | };
|
---|
| 190 |
|
---|