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 "NXOgre.h"
|
---|
27 | #include "SceneSerializer.h"
|
---|
28 | #include "Characters.h"
|
---|
29 |
|
---|
30 | bool highQuality = true;
|
---|
31 | bool chc = false;
|
---|
32 | bool constantTimeStep = false;
|
---|
33 |
|
---|
34 | Scene* NXScene = 0;
|
---|
35 | FPSPlayer* gFPSPlayer;
|
---|
36 |
|
---|
37 | bool PP_glowON = true;
|
---|
38 | bool PP_tonemapON = true;
|
---|
39 | bool PP_dofON = true;
|
---|
40 |
|
---|
41 | Real lightpower = 32.0;
|
---|
42 | Real glowCut = 50.6;
|
---|
43 | Real glowTimeBlur = 0.6;
|
---|
44 | Real glowStrech = 1.8;
|
---|
45 | Real glowCombine = 0.5;
|
---|
46 |
|
---|
47 | bool hallLightON = true;
|
---|
48 | bool smokeON = true;
|
---|
49 | bool smokeVisible = true;
|
---|
50 | Timer* smokeOffTimer;
|
---|
51 |
|
---|
52 | ParticleSystem* smokeSystem;
|
---|
53 |
|
---|
54 | Entity* LightButton;
|
---|
55 | Entity* SmokeButton;
|
---|
56 | SceneNode* hlNode;
|
---|
57 | SceneNode* rlNode;
|
---|
58 |
|
---|
59 | int targetCount = 6;
|
---|
60 | Vector3 targets[] = {Vector3(-8.5,-1.3, -9.8),
|
---|
61 | Vector3(-9.8,-1.3,-10.7),
|
---|
62 | Vector3(-6.5,-1.3,-11.5),
|
---|
63 | Vector3(-6.3,-1.3,-9.6),
|
---|
64 | Vector3(-7.7,-1.3,-10.6),
|
---|
65 | Vector3(-5.4,-1.3,-10.9)};
|
---|
66 |
|
---|
67 | class Scientist : FrameListener
|
---|
68 | {
|
---|
69 | public:
|
---|
70 | Scientist(String name, SceneManager* mSceneMgr)
|
---|
71 | {
|
---|
72 | scientist = mSceneMgr->createEntity(name, "scientist.mesh");
|
---|
73 | mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
74 | mNode->setPosition(-7.5,-1.3,-11);
|
---|
75 | mNode->setScale(0.02,0.02,0.02);
|
---|
76 | mNode->attachObject(scientist);
|
---|
77 | scientist->setCastShadows(true);
|
---|
78 | mNode->_updateBounds();
|
---|
79 | animState = scientist->getAnimationState("idle");
|
---|
80 | animState->setEnabled(true);
|
---|
81 |
|
---|
82 | setPriority(20);
|
---|
83 | Root::getSingleton().addFrameListener(this);
|
---|
84 |
|
---|
85 | waitTimer = new Timer();
|
---|
86 | waitTimer->reset();
|
---|
87 |
|
---|
88 | wait_min = 2000;
|
---|
89 | wait_max = 5000;
|
---|
90 | waitTime = Math::RangeRandom(wait_min, wait_max);
|
---|
91 |
|
---|
92 | targetReached = true;
|
---|
93 | movespeed = 0.2;
|
---|
94 | }
|
---|
95 |
|
---|
96 | bool frameStarted(const FrameEvent& evt)
|
---|
97 | {
|
---|
98 | animState->addTime(evt.timeSinceLastFrame * 0.75);
|
---|
99 |
|
---|
100 | //mNode->translate(movespeed * 0.001 * Vector3(0,0,1), Node::TS_LOCAL);
|
---|
101 |
|
---|
102 | Vector3 pos = mNode->getWorldPosition();
|
---|
103 | dir = target - pos;
|
---|
104 | if(!targetReached && dir.length() < 0.05)
|
---|
105 | {
|
---|
106 | waitTimer->reset();
|
---|
107 | targetReached = true;
|
---|
108 | animState = scientist->getAnimationState("idle");
|
---|
109 | animState->setEnabled(true);
|
---|
110 | animState->setLoop(true);
|
---|
111 |
|
---|
112 | Vector3 look = FPSPlayer::thePlayer->getPosition() - pos;
|
---|
113 | look.y = 0;
|
---|
114 | look.normalise();
|
---|
115 | Vector3 right = -look.crossProduct(Vector3::UNIT_Y);
|
---|
116 | Quaternion q;
|
---|
117 | q.FromAxes(right,Vector3::UNIT_Y, look);
|
---|
118 | mNode->setOrientation(q);
|
---|
119 |
|
---|
120 | }
|
---|
121 |
|
---|
122 | if(!targetReached)
|
---|
123 | {
|
---|
124 | //move forward to target
|
---|
125 | mNode->translate(movespeed * evt.timeSinceLastFrame * 2 * Vector3(0,0,1), Node::TS_LOCAL);
|
---|
126 | }
|
---|
127 | else
|
---|
128 | {
|
---|
129 | //look for new target
|
---|
130 | if(waitTimer->getMilliseconds() > waitTime)
|
---|
131 | {
|
---|
132 | int nextTarget = (int)(Math::UnitRandom() * targetCount);
|
---|
133 | target = targets[nextTarget];
|
---|
134 | dir = target - mNode->getWorldPosition();
|
---|
135 | dir.normalise();
|
---|
136 | Vector3 right = -dir.crossProduct(Vector3::UNIT_Y);
|
---|
137 | Quaternion q;
|
---|
138 | q.FromAxes(right,Vector3::UNIT_Y, dir);
|
---|
139 | mNode->setOrientation(q);
|
---|
140 |
|
---|
141 | targetReached = false;
|
---|
142 | animState = scientist->getAnimationState("walk");
|
---|
143 | animState->setEnabled(true);
|
---|
144 | animState->setLoop(true);
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | return true;
|
---|
149 | }
|
---|
150 |
|
---|
151 | Entity* scientist;
|
---|
152 | SceneNode* mNode;
|
---|
153 | Vector3 target;
|
---|
154 | Vector3 dir;
|
---|
155 | float movespeed;
|
---|
156 | bool targetReached;
|
---|
157 | Timer* waitTimer;
|
---|
158 | AnimationState* animState;
|
---|
159 | int wait_min;
|
---|
160 | int wait_max;
|
---|
161 | int waitTime;
|
---|
162 |
|
---|
163 | };
|
---|
164 |
|
---|
165 | // Listener class for frame updates
|
---|
166 | class SpaceStationFrameListener : public ExampleFrameListener
|
---|
167 | {
|
---|
168 | protected:
|
---|
169 |
|
---|
170 | unsigned long framecount;
|
---|
171 | SceneNode* mainLightNode;
|
---|
172 | Light* light1;
|
---|
173 | Light* light2;
|
---|
174 | SceneNode* sysNode;
|
---|
175 |
|
---|
176 | public:
|
---|
177 | SpaceStationFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode, Light* l, Light* l2, SceneNode* sysNode)
|
---|
178 | :ExampleFrameListener(window, maincam)
|
---|
179 |
|
---|
180 | {
|
---|
181 | mainLightNode = lightNode;
|
---|
182 | light1 = l;
|
---|
183 | light2 = l2;
|
---|
184 | framecount = 0;
|
---|
185 | mMoveSpeed /= 50.0;
|
---|
186 | this->sysNode = sysNode;
|
---|
187 |
|
---|
188 | mStatsOn = false;
|
---|
189 | showDebugOverlay(mStatsOn);
|
---|
190 | smokeOffTimer = new Timer();
|
---|
191 | smokeOffTimer->reset();
|
---|
192 | }
|
---|
193 |
|
---|
194 | bool frameStarted(const FrameEvent& evt)
|
---|
195 | {
|
---|
196 |
|
---|
197 | if(smokeOffTimer->getMilliseconds()>10)
|
---|
198 | {
|
---|
199 | if(smokeVisible)
|
---|
200 | {
|
---|
201 | smokeVisible = false;
|
---|
202 | smokeSystem->setVisible(false);
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | float dt = evt.timeSinceLastFrame;
|
---|
207 | static float rotate = 0;
|
---|
208 | rotate += dt * 100.0;
|
---|
209 | hlNode->rotate(Vector3(0,1,0),Radian(-Degree(dt * 100.0)));
|
---|
210 | rlNode->rotate(Vector3(0,1,0),Radian(-Degree(dt * 100.0)));
|
---|
211 | Vector3 dir(Math::Cos(Radian(Degree(rotate))), -1.4,Math::Sin(Radian(Degree(rotate))));
|
---|
212 | dir.normalise();
|
---|
213 | if(light1)
|
---|
214 | light1->setDirection(dir);
|
---|
215 |
|
---|
216 | if(light2)
|
---|
217 | {
|
---|
218 | Vector3 pos = Vector3(-1.6,3,-25.5)+ Vector3(dir.x, 0, dir.z) * 0.3;
|
---|
219 | light2->setPosition(pos);
|
---|
220 | dir *= -1;
|
---|
221 | dir.y = -2.0;
|
---|
222 | dir.normalise();
|
---|
223 | light2->setDirection(dir);
|
---|
224 | }
|
---|
225 |
|
---|
226 | return ExampleFrameListener::frameStarted(evt);
|
---|
227 | }
|
---|
228 |
|
---|
229 | void turnSmokeOff()
|
---|
230 | {
|
---|
231 | smokeSystem->getEmitter(0)->setEmissionRate(0);
|
---|
232 | smokeOffTimer->reset();
|
---|
233 | Ogre::Material* blueMat = (Ogre::Material*) MaterialManager::getSingleton().getByName("Station/bluebutton").getPointer();
|
---|
234 | blueMat->getTechnique(0)->getPass(0)->setAmbient(0.01,0.01,0.01);
|
---|
235 | if(smokeON)
|
---|
236 | SmokeButton->getParentSceneNode()->translate(0,0.02,0,Node::TS_LOCAL);
|
---|
237 | }
|
---|
238 | void lightbuttonpressed()
|
---|
239 | {
|
---|
240 | hallLightON = !hallLightON;
|
---|
241 | light2->setVisible(hallLightON);
|
---|
242 | if(!hallLightON)
|
---|
243 | {
|
---|
244 | turnSmokeOff();
|
---|
245 | smokeON = false;
|
---|
246 |
|
---|
247 | LightButton->getParentSceneNode()->translate(0,0.02,0,Node::TS_LOCAL);
|
---|
248 | Ogre::Material* redMat = (Ogre::Material*) MaterialManager::getSingleton().getByName("Station/redbutton").getPointer();
|
---|
249 | redMat->getTechnique(0)->getPass(0)->setAmbient(0.1,0.01,0.01);
|
---|
250 | Ogre::Material* lampMat = (Ogre::Material*) MaterialManager::getSingleton().getByName("Station_lamp").getPointer();
|
---|
251 | lampMat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("color",Vector4(0,0,0,0));
|
---|
252 |
|
---|
253 | }
|
---|
254 | else
|
---|
255 | {
|
---|
256 | LightButton->getParentSceneNode()->translate(0,-0.02,0,Node::TS_LOCAL);
|
---|
257 | Ogre::Material* redMat = (Ogre::Material*) MaterialManager::getSingleton().getByName("Station/redbutton").getPointer();
|
---|
258 | redMat->getTechnique(0)->getPass(0)->setAmbient(1,0.1,0.1);
|
---|
259 | Ogre::Material* lampMat = (Ogre::Material*) MaterialManager::getSingleton().getByName("Station_lamp").getPointer();
|
---|
260 | lampMat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("color",Vector4(20,20,20,20));
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 |
|
---|
265 | }
|
---|
266 | void smokebuttonpressed()
|
---|
267 | {
|
---|
268 | if(hallLightON)
|
---|
269 | {
|
---|
270 | smokeON = !smokeON;
|
---|
271 | if(smokeON)
|
---|
272 | {
|
---|
273 | smokeSystem->getEmitter(0)->setEmissionRate(3);
|
---|
274 | smokeSystem->setVisible(true);
|
---|
275 | smokeVisible = true;
|
---|
276 |
|
---|
277 | SmokeButton->getParentSceneNode()->translate(0,-0.02,0,Node::TS_LOCAL);
|
---|
278 | Ogre::Material* blueMat = (Ogre::Material*) MaterialManager::getSingleton().getByName("Station/bluebutton").getPointer();
|
---|
279 | blueMat->getTechnique(0)->getPass(0)->setAmbient(0.1,0.1,1);
|
---|
280 | }
|
---|
281 | else
|
---|
282 | {
|
---|
283 | turnSmokeOff();
|
---|
284 | SmokeButton->getParentSceneNode()->translate(0,0.02,0,Node::TS_LOCAL);
|
---|
285 | }
|
---|
286 |
|
---|
287 | }
|
---|
288 | }
|
---|
289 |
|
---|
290 | bool processUnbufferedKeyInput(const FrameEvent& evt)
|
---|
291 | {
|
---|
292 | gFPSPlayer->processKeyInputs(mInputDevice);
|
---|
293 |
|
---|
294 | if (mInputDevice->isKeyDown(KC_ADD) && mTimeUntilNextToggle <= 0)
|
---|
295 | {
|
---|
296 | if (mInputDevice->isKeyDown(KC_RSHIFT))
|
---|
297 | lightpower /= 1.2;
|
---|
298 | else
|
---|
299 | lightpower *= 1.2;
|
---|
300 | light2->setPowerScale(lightpower);
|
---|
301 | mTimeUntilNextToggle = 0.2;
|
---|
302 | mWindow->setDebugText(String("LightPower ") + StringConverter::toString(lightpower));
|
---|
303 | }
|
---|
304 | if (mInputDevice->isKeyDown(KC_SUBTRACT) && mTimeUntilNextToggle <= 0)
|
---|
305 | {
|
---|
306 | if (mInputDevice->isKeyDown(KC_RSHIFT))
|
---|
307 | glowCut /= 1.2;
|
---|
308 | else
|
---|
309 | glowCut *= 1.2;
|
---|
310 | Ogre::Material* m = (Ogre::Material*) MaterialManager::getSingleton().getByName("GTP/Station/PostProc/GlowCut").getPointer();
|
---|
311 | m->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("cutValue",glowCut);
|
---|
312 | mTimeUntilNextToggle = 0.2;
|
---|
313 | mWindow->setDebugText(String("GlowCut ") + StringConverter::toString(glowCut));
|
---|
314 | }
|
---|
315 | if (mInputDevice->isKeyDown(KC_MULTIPLY) && mTimeUntilNextToggle <= 0)
|
---|
316 | {
|
---|
317 | if (mInputDevice->isKeyDown(KC_RSHIFT))
|
---|
318 | glowTimeBlur /= 1.2;
|
---|
319 | else
|
---|
320 | glowTimeBlur *= 1.2;
|
---|
321 | Ogre::Material* m = (Ogre::Material*) MaterialManager::getSingleton().getByName("GTP/Station/PostProc/GlowCut").getPointer();
|
---|
322 | m->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("timeBlur", glowTimeBlur);
|
---|
323 | mTimeUntilNextToggle = 0.2;
|
---|
324 | mWindow->setDebugText(String("GlowTimeBlur ") + StringConverter::toString(glowTimeBlur));
|
---|
325 | }
|
---|
326 | if (mInputDevice->isKeyDown(KC_M))
|
---|
327 | {
|
---|
328 | if (mInputDevice->isKeyDown(KC_RSHIFT))
|
---|
329 | glowStrech -= 0.01;
|
---|
330 | else
|
---|
331 | glowStrech += 0.01;
|
---|
332 | Ogre::Material* m = (Ogre::Material*) MaterialManager::getSingleton().getByName("GTP/Station/PostProc/GlowBlurH").getPointer();
|
---|
333 | m->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("Stretch", glowStrech);
|
---|
334 | m = (Ogre::Material*) MaterialManager::getSingleton().getByName("GTP/Station/PostProc/GlowBlurV").getPointer();
|
---|
335 | m->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("Stretch", glowStrech);
|
---|
336 | mWindow->setDebugText(String("GlowStretch ") + StringConverter::toString(glowStrech));
|
---|
337 | }
|
---|
338 | if (mInputDevice->isKeyDown(KC_N))
|
---|
339 | {
|
---|
340 | if (mInputDevice->isKeyDown(KC_RSHIFT))
|
---|
341 | glowCombine -= 0.01;
|
---|
342 | else
|
---|
343 | glowCombine += 0.01;
|
---|
344 | Ogre::Material* m = (Ogre::Material*) MaterialManager::getSingleton().getByName("GTP/Station/GlowFinalCombine").getPointer();
|
---|
345 | m->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("weight2", glowCombine);
|
---|
346 | mTimeUntilNextToggle = 0.2;
|
---|
347 | mWindow->setDebugText(String("GlowCombine ") + StringConverter::toString(glowCombine));
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (mInputDevice->isKeyDown(KC_3) && mTimeUntilNextToggle <= 0)
|
---|
351 | {
|
---|
352 | PP_glowON = !PP_glowON;
|
---|
353 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
354 | "GTP/Station/PostProc/Glow", PP_glowON);
|
---|
355 | mTimeUntilNextToggle = 0.2;
|
---|
356 | }
|
---|
357 | if (mInputDevice->isKeyDown(KC_4) && mTimeUntilNextToggle <= 0)
|
---|
358 | {
|
---|
359 | PP_tonemapON = !PP_tonemapON;
|
---|
360 |
|
---|
361 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
362 | "GTP/PostProc/ToneMap", PP_tonemapON);
|
---|
363 |
|
---|
364 | mTimeUntilNextToggle = 0.2;
|
---|
365 | }
|
---|
366 | if (mInputDevice->isKeyDown(KC_5) && mTimeUntilNextToggle <= 0)
|
---|
367 | {
|
---|
368 | PP_dofON = !PP_dofON;
|
---|
369 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
370 | "GTP/Moria/PostProc/DoF", PP_dofON);
|
---|
371 | mTimeUntilNextToggle = 0.2;
|
---|
372 | }
|
---|
373 |
|
---|
374 | if( mInputDevice->isKeyDown( KC_ESCAPE) )
|
---|
375 | {
|
---|
376 | return false;
|
---|
377 | }
|
---|
378 | if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
|
---|
379 | {
|
---|
380 | mStatsOn = !mStatsOn;
|
---|
381 | showDebugOverlay(mStatsOn);
|
---|
382 |
|
---|
383 | mTimeUntilNextToggle = 1;
|
---|
384 | }
|
---|
385 | if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
|
---|
386 | {
|
---|
387 | char tmp[20];
|
---|
388 | sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
|
---|
389 | mWindow->writeContentsToFile(tmp);
|
---|
390 | mTimeUntilNextToggle = 0.5;
|
---|
391 | mWindow->setDebugText(String("Wrote ") + tmp);
|
---|
392 | }
|
---|
393 | return true;
|
---|
394 | //return ExampleFrameListener::processUnbufferedKeyInput(evt);
|
---|
395 | }
|
---|
396 |
|
---|
397 | bool processUnbufferedMouseInput(const FrameEvent& evt)
|
---|
398 | {
|
---|
399 | gFPSPlayer->processMouseInputs(mInputDevice);
|
---|
400 | // return ExampleFrameListener::processUnbufferedMouseInput(evt);
|
---|
401 |
|
---|
402 | static float lasttime = 0;
|
---|
403 | float thistime = Root::getSingleton().getTimer()->getMilliseconds();
|
---|
404 | float dt = ((float)(thistime - lasttime))/ 1000.0;
|
---|
405 | lasttime = thistime;
|
---|
406 |
|
---|
407 | static float buttonChangeTime = 0;
|
---|
408 | buttonChangeTime += dt;
|
---|
409 | if( mInputDevice->getMouseButton( 1 ) && buttonChangeTime > 0.25)
|
---|
410 | {
|
---|
411 | buttonChangeTime = 0;
|
---|
412 |
|
---|
413 | Vector3 PlayerPos = FPSPlayer::thePlayer->getPosition();
|
---|
414 | float dist = (PlayerPos - Vector3(-1.5375, -0.73,-27.6)).length();
|
---|
415 | if( dist < 1 && FPSPlayer::thePlayer->getDirection().dotProduct(Vector3(0,0,-1))>0)
|
---|
416 | {
|
---|
417 | if(PlayerPos.x > -1.5375)
|
---|
418 | {
|
---|
419 | smokebuttonpressed();
|
---|
420 | }
|
---|
421 | else
|
---|
422 | {
|
---|
423 | lightbuttonpressed();
|
---|
424 | }
|
---|
425 | }
|
---|
426 | }
|
---|
427 | return true;
|
---|
428 | }
|
---|
429 | };
|
---|
430 |
|
---|
431 | /** Application class */
|
---|
432 | class SpaceStationApplication : public ExampleApplication
|
---|
433 | {
|
---|
434 |
|
---|
435 |
|
---|
436 |
|
---|
437 |
|
---|
438 | protected:
|
---|
439 | SceneNode* kupolaNode;
|
---|
440 | SceneNode* roomLightNode;
|
---|
441 | SceneNode* hallLightNode;
|
---|
442 | Light* roomLight;
|
---|
443 | Light* hallLight;
|
---|
444 | SceneNode *pSysNode;
|
---|
445 |
|
---|
446 | void loadResources(void)
|
---|
447 | {
|
---|
448 | // Initialise, parse scripts etc
|
---|
449 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
450 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
451 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
452 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap");
|
---|
453 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic");
|
---|
454 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
455 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Particles");
|
---|
456 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_PathMap");
|
---|
457 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Diffuse");
|
---|
458 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_SpaceStation");
|
---|
459 | }
|
---|
460 |
|
---|
461 | void createPostproc()
|
---|
462 | {
|
---|
463 | /* CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
464 | "GTP/SpaceStation/PostProc/DoF");
|
---|
465 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
466 | "GTP/SpaceStation/PostProc/DoF", true);*/
|
---|
467 | if(highQuality)
|
---|
468 | {
|
---|
469 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
470 | "GTP/Station/PostProc/Glow");
|
---|
471 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
472 | "GTP/Station/PostProc/Glow", true);
|
---|
473 | }
|
---|
474 |
|
---|
475 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
476 | "GTP/PostProc/ToneMap");
|
---|
477 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
478 | "GTP/PostProc/ToneMap", true);
|
---|
479 |
|
---|
480 | /*
|
---|
481 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
482 | "GTP/PostProc/MotionBlur");
|
---|
483 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
484 | "GTP/PostProc/MotionBlur", false);*/
|
---|
485 |
|
---|
486 | }
|
---|
487 |
|
---|
488 | void chooseSceneManager()
|
---|
489 | {
|
---|
490 | if(chc)
|
---|
491 | mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
492 | else
|
---|
493 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
494 | }
|
---|
495 |
|
---|
496 | void createScene(void) ///TOWERS
|
---|
497 | {
|
---|
498 | roomLight = hallLight = 0;
|
---|
499 |
|
---|
500 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
501 | if(chc)
|
---|
502 | mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
503 |
|
---|
504 | //Overlay* mainOverlay = OverlayManager::getSingleton().getByName("MORIA/MainOverlay");
|
---|
505 | //mainOverlay->show();
|
---|
506 |
|
---|
507 | //if(highQuality)
|
---|
508 | createPostproc();
|
---|
509 |
|
---|
510 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
511 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
512 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
513 | OgreIlluminationManager::getSingleton().setShadowMapSize(700);
|
---|
514 | OgreIlluminationManager::getSingleton().setBlurShadowMap(highQuality);
|
---|
515 | if(highQuality)
|
---|
516 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_SPOTLIGHT, "GTP/Basic/Distance_Normalized");
|
---|
517 | else
|
---|
518 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_SPOTLIGHT, "GTP/Basic/Depth");//GTP/Basic/Distance_Normalize
|
---|
519 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_POINT, "GTP/Basic/Distance_Normalized");
|
---|
520 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
521 | OgreIlluminationManager::getSingleton().joinSharedRuns(false);
|
---|
522 |
|
---|
523 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
524 | mCamera->setPosition(0,0,0);
|
---|
525 | //mCamera->setPosition(0,100,0);
|
---|
526 | //mCamera->lookAt(0,-1,0);
|
---|
527 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
528 | mCamera->setNearClipDistance(0.001);
|
---|
529 | mCamera->setFarClipDistance(820);
|
---|
530 | // Set ambient light
|
---|
531 | // mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
532 | //mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
533 |
|
---|
534 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
535 |
|
---|
536 | SceneSerializer s(mSceneMgr);
|
---|
537 | DataStreamPtr inputStream;
|
---|
538 | inputStream = ResourceGroupManager::getSingleton().openResource("station.level");
|
---|
539 | World* NXWorld = new World("FrameListener: no, log: html");
|
---|
540 | NXWorld->getPhysXDriver()->createFrameListener(90);
|
---|
541 | NXScene = NXWorld->createScene("Main", mSceneMgr, "gravity: yes, floor: no");
|
---|
542 | s.setScene(NXScene);
|
---|
543 | s.setWorld(NXWorld);
|
---|
544 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
545 | if(highQuality)
|
---|
546 | s.parseEntryPoints("StationPrmEntryPoints.text");
|
---|
547 |
|
---|
548 | NXScene->createActor("bound", new MeshShape("stationbound.mesh"), Vector3(0,0,0), "static: yes");
|
---|
549 | NXScene->createActor("bound2", new MeshShape("stationbound2.mesh"), Vector3(0,0,0), "static: yes");
|
---|
550 |
|
---|
551 | hallLight = mSceneMgr->createLight("hallLight");
|
---|
552 | hallLight->setType(Light::LT_SPOTLIGHT);
|
---|
553 | hallLight->setCastShadows(true);
|
---|
554 | hallLight->setDiffuseColour(ColourValue::White);
|
---|
555 | hallLight->setSpecularColour(ColourValue::White);
|
---|
556 | hallLightNode = rootNode->createChildSceneNode();
|
---|
557 |
|
---|
558 | //hallLightNode->setPosition(-1.6,3,-25.5);
|
---|
559 | hallLight->setPowerScale(200);
|
---|
560 | hallLight->setDirection(0,0,-1);
|
---|
561 | hallLightNode->attachObject(hallLight);
|
---|
562 | hallLight->setSpotlightRange(Degree(0),Degree(140));
|
---|
563 | hallLight->setAttenuation(20.0, 0, 0, 3);
|
---|
564 | hallLight->setVisible(hallLightON);
|
---|
565 |
|
---|
566 |
|
---|
567 | roomLight = mSceneMgr->createLight("roomLight");
|
---|
568 | roomLight->setType(Light::LT_SPOTLIGHT);
|
---|
569 | roomLight->setCastShadows(true);
|
---|
570 | roomLight->setDiffuseColour(ColourValue::White);
|
---|
571 | roomLight->setSpecularColour(ColourValue::White);
|
---|
572 | roomLightNode = rootNode->createChildSceneNode();
|
---|
573 |
|
---|
574 | roomLightNode->setPosition(-7.5,1,-11);
|
---|
575 | roomLight->setPowerScale(50);
|
---|
576 | roomLight->setDirection(0,0,-1);
|
---|
577 | roomLightNode->attachObject(roomLight);
|
---|
578 | roomLight->setSpotlightRange(Degree(0),Degree(140));
|
---|
579 | roomLight->setAttenuation(20.0, 0, 0, 3);
|
---|
580 | /*
|
---|
581 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
582 | bbs->setDefaultDimensions(0.3, 0.3);
|
---|
583 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
584 | bbs->setMaterialName("Flare");
|
---|
585 | roomLightNode->attachObject(bbs);*/
|
---|
586 |
|
---|
587 |
|
---|
588 | Entity* CauCaster = mSceneMgr->createEntity("CauCaster", "sphere.mesh");
|
---|
589 | SceneNode* casterNode = rootNode->createChildSceneNode();
|
---|
590 | casterNode->setPosition(-1.5, 1.0, -25);
|
---|
591 | casterNode->setScale(0.75, .75, 0.75);
|
---|
592 | CauCaster->setMaterialName("SpaceStation_CausticCaster");
|
---|
593 | casterNode->attachObject(CauCaster);
|
---|
594 | casterNode->_updateBounds();
|
---|
595 | CauCaster->setCastShadows(true);
|
---|
596 |
|
---|
597 | smokeSystem = mSceneMgr->createParticleSystem("psys1", "GTP/Station/Smoke");
|
---|
598 | smokeSystem->setKeepParticlesInLocalSpace(false);
|
---|
599 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
600 | pSysNode->attachObject(smokeSystem);
|
---|
601 | smokeSystem->getEmitter(0)->setPosition(Vector3(0,-3.7,0));
|
---|
602 | smokeSystem->setCastShadows(false);
|
---|
603 | pSysNode->setPosition(-1.5, 3, -25);
|
---|
604 | smokeSystem->setVisible(smokeVisible);
|
---|
605 |
|
---|
606 | LightButton = mSceneMgr->createEntity("lightButton", "cube.mesh");
|
---|
607 | SceneNode* lbNode = rootNode->createChildSceneNode();
|
---|
608 | lbNode->setScale(0.1,0.1,0.1);
|
---|
609 | lbNode->setPosition(-1.8, -0.73, -27.6);
|
---|
610 | lbNode->rotate(Vector3(1,0,0), Degree(30.0));
|
---|
611 | lbNode->attachObject(LightButton);
|
---|
612 | lbNode->translate(0,-0.02,0,Node::TS_LOCAL);
|
---|
613 | LightButton->setMaterialName("Station/redbutton");
|
---|
614 |
|
---|
615 | SmokeButton = mSceneMgr->createEntity("smokeButton", "cube.mesh");
|
---|
616 | SceneNode* sbNode = rootNode->createChildSceneNode();
|
---|
617 | sbNode->setScale(0.1,0.1,0.1);
|
---|
618 | sbNode->setPosition(-1.25, -0.73, -27.6);
|
---|
619 | sbNode->rotate(Vector3(1,0,0), Degree(30.0));
|
---|
620 | sbNode->attachObject(SmokeButton);
|
---|
621 | sbNode->translate(0,-0.02,0,Node::TS_LOCAL);
|
---|
622 | SmokeButton->setMaterialName("Station/bluebutton");
|
---|
623 |
|
---|
624 | Entity* hallLampHolder = mSceneMgr->createEntity("hallLampHolder", "hallLampHolder.mesh");
|
---|
625 | SceneNode* hlhNode = rootNode->createChildSceneNode();
|
---|
626 | hlhNode->setPosition(-1.547, 4.308, -24.242);
|
---|
627 | hlhNode->attachObject(hallLampHolder);
|
---|
628 |
|
---|
629 | Entity* hallLamp = mSceneMgr->createEntity("hallLamp", "hallLamp.mesh");
|
---|
630 | hlNode = rootNode->createChildSceneNode();
|
---|
631 | hlNode->setPosition(-1.547, 2.899, -24.242);
|
---|
632 | hlNode->attachObject(hallLamp);
|
---|
633 | hallLamp->setCastShadows(false);
|
---|
634 |
|
---|
635 | Entity* roomLamp = mSceneMgr->createEntity("roomLamp", "roomLamp.mesh");
|
---|
636 | rlNode = rootNode->createChildSceneNode();
|
---|
637 | rlNode->setPosition(-7.579, 1.000, -10.831);
|
---|
638 | rlNode->attachObject(roomLamp);
|
---|
639 | rlNode->rotate(Vector3(0,1,0),Radian(Degree(180)));
|
---|
640 | roomLamp->setCastShadows(false);
|
---|
641 |
|
---|
642 | new Scientist("scientist", mSceneMgr);
|
---|
643 | PlayerCharacter::frameListenerPriority = 30;
|
---|
644 |
|
---|
645 | gFPSPlayer = new FPSPlayer(NXScene, mSceneMgr, Vector3(0.4, 1.0, 0.35),/*Vector3(-7.5,0.0,-11)*/Vector3(0, 0.0, 11.5), 1.15, mCamera, false);
|
---|
646 | /*gFPSPlayer->addPlayerMesh("FPSarm.mesh", 0.02, false);
|
---|
647 | gFPSPlayer->addWeaponModel("sword.mesh", "joint28");
|
---|
648 |
|
---|
649 | TrollCharacter* troll = new TrollCharacter("troll1", NXScene, mSceneMgr, Vector3(1.5, 3.0, 1.2), Vector3(15, 10, 15), false);
|
---|
650 | troll->addPlayerMesh("troll.mesh", 0.05, false);
|
---|
651 | troll->addWeaponModel("trollMace.mesh", "RightHand");
|
---|
652 |
|
---|
653 | CharacterManager::getSingleton().mScene = NXScene;
|
---|
654 | CharacterManager::getSingleton().mSceneManager = mSceneMgr;*/
|
---|
655 |
|
---|
656 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
657 | }
|
---|
658 |
|
---|
659 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1))
|
---|
660 | {
|
---|
661 | Plane _plane;
|
---|
662 | _plane.normal = Vector3::UNIT_Y;
|
---|
663 | _plane.d = 0;
|
---|
664 |
|
---|
665 |
|
---|
666 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
667 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
668 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
669 |
|
---|
670 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
671 | _entity->setMaterialName(_material);
|
---|
672 |
|
---|
673 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
674 | _node->attachObject(_entity);
|
---|
675 | _node->setPosition(_pos);
|
---|
676 |
|
---|
677 | }
|
---|
678 |
|
---|
679 | void createFrameListener(void)
|
---|
680 | {
|
---|
681 | if(constantTimeStep)
|
---|
682 | {
|
---|
683 | // This is where we instantiate our own frame listener
|
---|
684 | class constantTimeStep : public FrameListener
|
---|
685 | {
|
---|
686 | public:
|
---|
687 | bool frameStarted(const FrameEvent &evt)
|
---|
688 | {
|
---|
689 | FrameEvent* event = (FrameEvent*) &evt;
|
---|
690 | event->timeSinceLastFrame = 1000 / 20;
|
---|
691 | return true;
|
---|
692 | }
|
---|
693 | };
|
---|
694 | constantTimeStep* ct = new constantTimeStep;
|
---|
695 | ct->setPriority(1);
|
---|
696 | mRoot->addFrameListener(ct);
|
---|
697 | }
|
---|
698 |
|
---|
699 | mFrameListener= new SpaceStationFrameListener(mWindow,
|
---|
700 | mCamera, roomLightNode, roomLight, hallLight, pSysNode );
|
---|
701 |
|
---|
702 | mFrameListener->setPriority(10);
|
---|
703 | mRoot->addFrameListener(mFrameListener);
|
---|
704 | // gFPSPlayer->setPriority(20);
|
---|
705 | // mRoot->addFrameListener(gFPSPlayer);
|
---|
706 | OgreIlluminationManager::getSingleton().setPriority(100);
|
---|
707 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
708 |
|
---|
709 | }
|
---|
710 |
|
---|
711 | };
|
---|
712 |
|
---|