source: GTP/trunk/App/Demos/Illum/Ogre/src/HierarchicalSystem/include/HierarchicalSystem.h @ 2175

Revision 2175, 6.3 KB checked in by szirmay, 17 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL 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
29int scene = 1;
30
31// Listener class for frame updates
32class ParticleDemoFrameListener : public ExampleFrameListener
33{
34protected:
35       
36        SceneNode* lightNode;
37
38public:
39    ParticleDemoFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode)
40        :ExampleFrameListener(window, maincam)
41                                 
42    {
43                this->lightNode = lightNode;           
44    }
45
46    bool frameStarted(const FrameEvent& evt)
47    {           
48                bool result = ExampleFrameListener::frameStarted(evt);
49               
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                }     
58        return result;     
59    }
60
61       
62
63};
64
65/** Application class */
66class ParticleDemoApplication : public ExampleApplication
67{
68
69public:
70
71protected:
72        SceneNode* kupolaNode;
73        SceneNode* mainLightNode;
74
75        void loadResources(void)
76        {
77                // Initialise, parse scripts etc
78                ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
79                ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
80                //ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
81                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Particles");
82        }
83
84        void createPostproc()
85        {               
86                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
87                                                                                                                "GTP/PostProc/Glow");
88                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
89                                                                                                                "GTP/PostProc/Glow", true);
90
91                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
92                                                                                                                "GTP/PostProc/ToneMap");
93                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
94                                                                                                                "GTP/PostProc/ToneMap", true);         
95        }
96   
97        void chooseSceneManager()
98        {
99                if(scene == 1)
100                {
101                  mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
102                  //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
103                }
104                else if(scene == 2)
105           mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
106        }
107
108        void createScene(void)
109    {
110                //createPostproc();
111
112                OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
113                OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
114               
115               
116                Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
117               
118                mCamera->setFOVy(Radian(Degree(80)));
119                mCamera->setFarClipDistance(5000);
120                // Set ambient light
121        mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
122
123                // Skybox
124        mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 10);
125               
126               
127
128               
129
130        //      OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PHASE_TEXTURE);
131        //      OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PHASE_TEXTURE, 1);
132        //      OgreIlluminationManager::getSingleton().savePhaseTextureToFile("phase.dds");
133
134               
135                if(scene == 1)
136                        createScene1();
137                else if(scene == 2)
138                        createScene2();
139
140
141                OgreIlluminationManager::getSingleton().initTechniques();
142
143   }
144       
145   void createScene1()
146   {
147           mCamera->setPosition(0,150,100);
148           mCamera->setDirection(0,0,-1);
149
150           SceneNode* rootNode = mSceneMgr->getRootSceneNode();
151
152           Entity* head = mSceneMgr->createEntity("head", "athene.mesh");
153           SceneNode* headNode = rootNode->createChildSceneNode("head");
154           head->setMaterialName("GameTools/Standard");
155           headNode->attachObject(head);
156           //headNode->setScale(1.5,1.5,1.5);
157           AxisAlignedBox bbox = head->getBoundingBox();
158           headNode->setPosition(0,80,20);             
159           headNode->_updateBounds();
160
161
162       ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/HPS/Smoke_Large");
163           pSys1->setKeepParticlesInLocalSpace(false);
164           SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
165           pSysNode->attachObject(pSys1);
166           pSysNode->setPosition(0,0,0);
167               
168                //Init lights
169                Light* mainLight = mSceneMgr->createLight("MainLight");
170                mainLight->setType(Light::LT_POINT);
171        mainLight->setDiffuseColour(ColourValue::White);
172                mainLight->setSpecularColour(ColourValue::White);
173                mainLightNode = rootNode->createChildSceneNode();
174                mainLightNode->setPosition(0,500,0);
175                mainLight->setPosition(mainLightNode->getWorldPosition());
176                mainLightNode->attachObject(mainLight);
177                BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
178                bbs->createBillboard(Vector3::ZERO, ColourValue::White);
179                bbs->setMaterialName("Flare");
180                mainLightNode->attachObject(bbs);
181   }
182
183   void createScene2()
184   {
185        mCamera->setPosition(0,150,100);
186           mCamera->setDirection(0,0,-1);
187
188           SceneNode* rootNode = mSceneMgr->getRootSceneNode();
189           std::string terrain_cfg("terrain.cfg");
190           mSceneMgr -> setWorldGeometry( terrain_cfg );
191
192           ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GameTools/FogBig");
193           pSys1->setKeepParticlesInLocalSpace(false);
194           SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
195           pSysNode->attachObject(pSys1);
196           pSysNode->setPosition(600,-50,600);
197               
198   }
199
200        void createFrameListener(void)
201    {
202                // This is where we instantiate our own frame listener
203                mFrameListener= new ParticleDemoFrameListener(mWindow,
204                                                                                        mCamera , mainLightNode);
205       mFrameListener->setPriority(2);
206                OgreIlluminationManager::getSingleton().setPriority(10);
207                 mRoot->addFrameListener(mFrameListener);
208                 mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
209
210                 
211               
212    }
213
214};
215
Note: See TracBrowser for help on using the repository browser.