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 | bool visibilitySM = false;
|
---|
29 | int scene = 1;
|
---|
30 |
|
---|
31 | // Listener class for frame updates
|
---|
32 | class ParticleDemoFrameListener : public ExampleFrameListener
|
---|
33 | {
|
---|
34 | protected:
|
---|
35 |
|
---|
36 | SceneNode* lightNode;
|
---|
37 |
|
---|
38 | public:
|
---|
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 */
|
---|
66 | class ParticleDemoApplication : public ExampleApplication
|
---|
67 | {
|
---|
68 |
|
---|
69 | public:
|
---|
70 |
|
---|
71 | protected:
|
---|
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("GTP_Basic");
|
---|
81 | //ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
82 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
83 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Particles");
|
---|
84 | }
|
---|
85 |
|
---|
86 | void createPostproc()
|
---|
87 | {
|
---|
88 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
89 | "GTP/PostProc/Glow");
|
---|
90 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
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);
|
---|
97 | }
|
---|
98 |
|
---|
99 | void chooseSceneManager()
|
---|
100 | {
|
---|
101 | if(visibilitySM)
|
---|
102 | mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
103 | else
|
---|
104 | {
|
---|
105 |
|
---|
106 | if(scene == 1)
|
---|
107 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
108 | else if(scene == 2)
|
---|
109 | mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
|
---|
110 | }
|
---|
111 |
|
---|
112 | }
|
---|
113 | void createScene(void)
|
---|
114 | {
|
---|
115 |
|
---|
116 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
117 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
118 |
|
---|
119 |
|
---|
120 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
121 |
|
---|
122 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
123 | mCamera->setFarClipDistance(5000);
|
---|
124 | // Set ambient light
|
---|
125 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
126 |
|
---|
127 | // Skybox
|
---|
128 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 10);
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | //OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PHASE_TEXTURE);
|
---|
135 | //OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PHASE_TEXTURE, 1);
|
---|
136 | //OgreIlluminationManager::getSingleton().savePhaseTextureToFile("phase.dds");
|
---|
137 |
|
---|
138 |
|
---|
139 | if(scene == 1)
|
---|
140 | createScene1();
|
---|
141 | else if(scene == 2)
|
---|
142 | createScene2();
|
---|
143 |
|
---|
144 |
|
---|
145 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
146 |
|
---|
147 | }
|
---|
148 |
|
---|
149 | void createScene1()
|
---|
150 | {
|
---|
151 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
152 | if(visibilitySM)
|
---|
153 | mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
154 |
|
---|
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 |
|
---|
170 | // ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/HPS/Smoke_Large");
|
---|
171 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/Smoke_Large");
|
---|
172 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
173 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
174 | pSysNode->attachObject(pSys1);
|
---|
175 | pSysNode->setPosition(0,0,0);
|
---|
176 |
|
---|
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();
|
---|
183 | mainLightNode->setPosition(0,500,0);
|
---|
184 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
185 | mainLightNode->attachObject(mainLight);
|
---|
186 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
187 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
188 | bbs->setMaterialName("Flare");
|
---|
189 | mainLightNode->attachObject(bbs);
|
---|
190 | }
|
---|
191 |
|
---|
192 | void createScene2()
|
---|
193 | {
|
---|
194 | mCamera->setPosition(0,150,100);
|
---|
195 | mCamera->setDirection(0,0,-1);
|
---|
196 |
|
---|
197 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
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 | }
|
---|
208 |
|
---|
209 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/HPS/Smoke_Large");
|
---|
210 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
211 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
212 | pSysNode->attachObject(pSys1);
|
---|
213 | pSysNode->setPosition(600,-50,600);
|
---|
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);
|
---|
228 |
|
---|
229 | }
|
---|
230 |
|
---|
231 | void createFrameListener(void)
|
---|
232 | {
|
---|
233 | // This is where we instantiate our own frame listener
|
---|
234 | mFrameListener= new ParticleDemoFrameListener(mWindow,
|
---|
235 | mCamera , mainLightNode);
|
---|
236 | mFrameListener->setPriority(2);
|
---|
237 | OgreIlluminationManager::getSingleton().setPriority(10);
|
---|
238 | mRoot->addFrameListener(mFrameListener);
|
---|
239 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
240 |
|
---|
241 |
|
---|
242 |
|
---|
243 | }
|
---|
244 |
|
---|
245 | };
|
---|
246 |
|
---|