1 |
|
---|
2 |
|
---|
3 |
|
---|
4 | /*
|
---|
5 | -----------------------------------------------------------------------------
|
---|
6 | This source file is part of OGRE
|
---|
7 | (Object-oriented Graphics Rendering Engine)
|
---|
8 | For the latest info, see http://www.ogre3d.org/
|
---|
9 |
|
---|
10 | Copyright (c) 2000-2005 The OGRE Team
|
---|
11 | Also see acknowledgements in Readme.html
|
---|
12 |
|
---|
13 | You may use this sample code for anything you like, it is not covered by the
|
---|
14 | LGPL like the rest of the engine.
|
---|
15 | -----------------------------------------------------------------------------
|
---|
16 | */
|
---|
17 |
|
---|
18 | /**
|
---|
19 | \file
|
---|
20 | Lighting.h
|
---|
21 | \brief
|
---|
22 | Shows lighting support in OGRE. Also demonstrates the use of billboards
|
---|
23 | and controllers for automatic time-relative behaviour.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include "ExampleApplication.h"
|
---|
27 | #include "OgreIlluminationManager.h"
|
---|
28 |
|
---|
29 | float causize = 10;
|
---|
30 | float cauintens = 40;
|
---|
31 | int scene = 3;
|
---|
32 | // Listener class for frame updates
|
---|
33 | class RaytraceDemoListener : public ExampleFrameListener
|
---|
34 | {
|
---|
35 | protected:
|
---|
36 |
|
---|
37 | SceneNode* objectNode;
|
---|
38 | unsigned long framecount;
|
---|
39 |
|
---|
40 | public:
|
---|
41 | RaytraceDemoListener(RenderWindow* window, Camera* maincam, SceneNode* objectNode)
|
---|
42 | :ExampleFrameListener(window, maincam)
|
---|
43 |
|
---|
44 | {
|
---|
45 | this->mMoveSpeed = 2.0;
|
---|
46 | framecount = 0;
|
---|
47 | this->objectNode = objectNode;
|
---|
48 | }
|
---|
49 | bool processUnbufferedKeyInput(const FrameEvent& evt)
|
---|
50 | {
|
---|
51 | if (mInputDevice->isKeyDown(KC_UP))
|
---|
52 | {
|
---|
53 | objectNode->translate(0,0,0.1);
|
---|
54 | }
|
---|
55 | if (mInputDevice->isKeyDown(KC_MULTIPLY))
|
---|
56 | {
|
---|
57 | //objectNode->scale(1.1,1.1,1.1);
|
---|
58 | objectNode->rotate(Vector3(0,0,1), Degree(10));
|
---|
59 | mTimeUntilNextToggle = 1;
|
---|
60 | }
|
---|
61 | if (mInputDevice->isKeyDown(KC_DIVIDE))
|
---|
62 | {
|
---|
63 | //objectNode->scale(1.0/1.1,1.0/1.1,1.0/1.1);
|
---|
64 | objectNode->rotate(Vector3(1,0,0), Degree(10));
|
---|
65 | mTimeUntilNextToggle = 1;
|
---|
66 | }
|
---|
67 | if (mInputDevice->isKeyDown(KC_ADD))
|
---|
68 | {
|
---|
69 | objectNode->rotate(Vector3(0,1,0), Degree(10));
|
---|
70 | }
|
---|
71 | if (mInputDevice->isKeyDown(KC_HOME))
|
---|
72 | {
|
---|
73 | objectNode->translate(0,0.1,0);
|
---|
74 | }
|
---|
75 | if (mInputDevice->isKeyDown(KC_END))
|
---|
76 | {
|
---|
77 | objectNode->translate(0,-0.1,0);
|
---|
78 | }
|
---|
79 | if (mInputDevice->isKeyDown(KC_DOWN))
|
---|
80 | {
|
---|
81 | objectNode->translate(0,0,-0.1);
|
---|
82 | }
|
---|
83 | if (mInputDevice->isKeyDown(KC_RIGHT))
|
---|
84 | {
|
---|
85 | objectNode->translate(0.5,0,0);
|
---|
86 | }
|
---|
87 | if (mInputDevice->isKeyDown(KC_LEFT))
|
---|
88 | {
|
---|
89 | objectNode->translate(-0.5,0,0);
|
---|
90 | }
|
---|
91 |
|
---|
92 | if (mInputDevice->isKeyDown(KC_A))
|
---|
93 | {
|
---|
94 | // Move camera left
|
---|
95 | mTranslateVector.x = -mMoveScale;
|
---|
96 | }
|
---|
97 |
|
---|
98 | if (mInputDevice->isKeyDown(KC_D))
|
---|
99 | {
|
---|
100 | // Move camera RIGHT
|
---|
101 | mTranslateVector.x = mMoveScale;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* Move camera forward by keypress. */
|
---|
105 | if ( mInputDevice->isKeyDown(KC_W) )
|
---|
106 | {
|
---|
107 | mTranslateVector.z = -mMoveScale;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /* Move camera backward by keypress. */
|
---|
111 | if (mInputDevice->isKeyDown(KC_S) )
|
---|
112 | {
|
---|
113 | mTranslateVector.z = mMoveScale;
|
---|
114 | }
|
---|
115 |
|
---|
116 | if (mInputDevice->isKeyDown(KC_PGUP))
|
---|
117 | {
|
---|
118 | // Move camera up
|
---|
119 | mTranslateVector.y = mMoveScale;
|
---|
120 | }
|
---|
121 |
|
---|
122 | if (mInputDevice->isKeyDown(KC_PGDOWN))
|
---|
123 | {
|
---|
124 | // Move camera down
|
---|
125 | mTranslateVector.y = -mMoveScale;
|
---|
126 | }
|
---|
127 |
|
---|
128 | if( mInputDevice->isKeyDown( KC_ESCAPE) )
|
---|
129 | {
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 |
|
---|
133 | // see if switching is on, and you want to toggle
|
---|
134 | if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_M) && mTimeUntilNextToggle <= 0)
|
---|
135 | {
|
---|
136 | switchMouseMode();
|
---|
137 | mTimeUntilNextToggle = 1;
|
---|
138 | }
|
---|
139 |
|
---|
140 | if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_K) && mTimeUntilNextToggle <= 0)
|
---|
141 | {
|
---|
142 | // must be going from immediate keyboard to buffered keyboard
|
---|
143 | switchKeyMode();
|
---|
144 | mTimeUntilNextToggle = 1;
|
---|
145 | }
|
---|
146 | if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
|
---|
147 | {
|
---|
148 | mStatsOn = !mStatsOn;
|
---|
149 | showDebugOverlay(mStatsOn);
|
---|
150 |
|
---|
151 | mTimeUntilNextToggle = 1;
|
---|
152 | }
|
---|
153 | if (mInputDevice->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0)
|
---|
154 | {
|
---|
155 | switch(mFiltering)
|
---|
156 | {
|
---|
157 | case TFO_BILINEAR:
|
---|
158 | mFiltering = TFO_TRILINEAR;
|
---|
159 | mAniso = 1;
|
---|
160 | break;
|
---|
161 | case TFO_TRILINEAR:
|
---|
162 | mFiltering = TFO_ANISOTROPIC;
|
---|
163 | mAniso = 8;
|
---|
164 | break;
|
---|
165 | case TFO_ANISOTROPIC:
|
---|
166 | mFiltering = TFO_BILINEAR;
|
---|
167 | mAniso = 1;
|
---|
168 | break;
|
---|
169 | default:
|
---|
170 | break;
|
---|
171 | }
|
---|
172 | MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
|
---|
173 | MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
|
---|
174 |
|
---|
175 |
|
---|
176 | showDebugOverlay(mStatsOn);
|
---|
177 |
|
---|
178 | mTimeUntilNextToggle = 1;
|
---|
179 | }
|
---|
180 |
|
---|
181 | if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
|
---|
182 | {
|
---|
183 | char tmp[20];
|
---|
184 | sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
|
---|
185 | mWindow->writeContentsToFile(tmp);
|
---|
186 | mTimeUntilNextToggle = 0.5;
|
---|
187 | mWindow->setDebugText(String("Wrote ") + tmp);
|
---|
188 | }
|
---|
189 |
|
---|
190 | if (mInputDevice->isKeyDown(KC_R) && mTimeUntilNextToggle <=0)
|
---|
191 | {
|
---|
192 | mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
|
---|
193 | switch(mSceneDetailIndex) {
|
---|
194 | case 0 : mCamera->setPolygonMode(PM_SOLID) ; break ;
|
---|
195 | case 1 : mCamera->setPolygonMode(PM_WIREFRAME) ; break ;
|
---|
196 | case 2 : mCamera->setPolygonMode(PM_POINTS) ; break ;
|
---|
197 | }
|
---|
198 | mTimeUntilNextToggle = 0.5;
|
---|
199 | }
|
---|
200 |
|
---|
201 | static bool displayCameraDetails = false;
|
---|
202 | if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
|
---|
203 | {
|
---|
204 | displayCameraDetails = !displayCameraDetails;
|
---|
205 | mTimeUntilNextToggle = 0.5;
|
---|
206 | if (!displayCameraDetails)
|
---|
207 | mWindow->setDebugText("");
|
---|
208 | }
|
---|
209 | if (displayCameraDetails)
|
---|
210 | {
|
---|
211 | // Print camera details
|
---|
212 | mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " +
|
---|
213 | "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
|
---|
214 | }
|
---|
215 |
|
---|
216 | // Return true to continue rendering
|
---|
217 | return true;
|
---|
218 | }
|
---|
219 | bool frameStarted(const FrameEvent& evt)
|
---|
220 | {
|
---|
221 | static bool first = true;
|
---|
222 |
|
---|
223 |
|
---|
224 | // lightNode->setPosition( 100.0 * Vector3(cos(-(float)framecount/500.0),2.0,sin(-(float)framecount/500.0)));
|
---|
225 |
|
---|
226 |
|
---|
227 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
228 | framecount++;
|
---|
229 | return result;
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|
233 |
|
---|
234 | };
|
---|
235 |
|
---|
236 |
|
---|
237 | class FloorRenderTargetListener : public RenderTargetListener
|
---|
238 | {
|
---|
239 | public:
|
---|
240 | Entity* scene;
|
---|
241 | FloorRenderTargetListener(Entity* scene)
|
---|
242 | {
|
---|
243 | this->scene = scene;
|
---|
244 | }
|
---|
245 | void preRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
246 | {
|
---|
247 | scene->getSubEntity(0)->setVisible(false);
|
---|
248 | scene->getSubEntity(17)->setVisible(false);
|
---|
249 | scene->getSubEntity(35)->setVisible(false);
|
---|
250 | scene->getSubEntity(52)->setVisible(false);
|
---|
251 | }
|
---|
252 | void postRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
253 | {
|
---|
254 | scene->getSubEntity(0)->setVisible(true);
|
---|
255 | scene->getSubEntity(17)->setVisible(true);
|
---|
256 | scene->getSubEntity(35)->setVisible(true);
|
---|
257 | scene->getSubEntity(52)->setVisible(true);
|
---|
258 | }
|
---|
259 |
|
---|
260 | };
|
---|
261 |
|
---|
262 | class CeilRenderTargetListener : public RenderTargetListener
|
---|
263 | {
|
---|
264 | public:
|
---|
265 | Entity* scene;
|
---|
266 | CeilRenderTargetListener(Entity* scene)
|
---|
267 | {
|
---|
268 | this->scene = scene;
|
---|
269 | }
|
---|
270 | void preRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
271 | {
|
---|
272 | scene->getSubEntity(1)->setVisible(false);
|
---|
273 | scene->getSubEntity(18)->setVisible(false);
|
---|
274 | scene->getSubEntity(36)->setVisible(false);
|
---|
275 | scene->getSubEntity(53)->setVisible(false);
|
---|
276 | }
|
---|
277 | void postRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
278 | {
|
---|
279 | scene->getSubEntity(1)->setVisible(true);
|
---|
280 | scene->getSubEntity(18)->setVisible(true);
|
---|
281 | scene->getSubEntity(36)->setVisible(true);
|
---|
282 | scene->getSubEntity(53)->setVisible(true);
|
---|
283 | }
|
---|
284 |
|
---|
285 | };
|
---|
286 |
|
---|
287 | class ReflectionCameraFrameListener : public FrameListener
|
---|
288 | {
|
---|
289 | public:
|
---|
290 | Camera* floorReflCam;
|
---|
291 | Camera* ceilReflCam;
|
---|
292 | Camera* mainCamera;
|
---|
293 | ReflectionCameraFrameListener(Camera* floorcam, Camera* ceilCam, Camera* mainCam)
|
---|
294 | {
|
---|
295 | floorReflCam = floorcam;
|
---|
296 | ceilReflCam = ceilCam;
|
---|
297 | mainCamera = mainCam;
|
---|
298 | }
|
---|
299 | bool frameStarted(const FrameEvent& evt)
|
---|
300 | {
|
---|
301 | floorReflCam->setOrientation(mainCamera->getOrientation());
|
---|
302 | floorReflCam->setPosition(mainCamera->getPosition());
|
---|
303 |
|
---|
304 | // ceilReflCam->setOrientation(mainCamera->getOrientation());
|
---|
305 | // ceilReflCam->setPosition(mainCamera->getPosition());
|
---|
306 |
|
---|
307 | return true;
|
---|
308 | }
|
---|
309 | };
|
---|
310 | /** Application class */
|
---|
311 | class RaytraceDemoApplication : public ExampleApplication
|
---|
312 | {
|
---|
313 |
|
---|
314 | public:
|
---|
315 |
|
---|
316 | protected:
|
---|
317 | SceneNode* objectNode;
|
---|
318 |
|
---|
319 | void createPostproc()
|
---|
320 | {
|
---|
321 | /*CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
322 | "GameTools/Glow");
|
---|
323 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
324 | "GameTools/Glow", true);*/
|
---|
325 |
|
---|
326 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
327 | "GameTools/ToneMap");
|
---|
328 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
329 | "GameTools/ToneMap", true);
|
---|
330 |
|
---|
331 | }
|
---|
332 |
|
---|
333 |
|
---|
334 | void createScene(void)
|
---|
335 | {
|
---|
336 |
|
---|
337 | createPostproc();
|
---|
338 |
|
---|
339 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
340 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
341 |
|
---|
342 | OgreIlluminationManager::getSingleton().setMaxJoinRadius(420);
|
---|
343 |
|
---|
344 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
345 |
|
---|
346 | mCamera->setPosition(0,1,0);
|
---|
347 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
348 | mCamera->setFarClipDistance(200);
|
---|
349 | mCamera->setNearClipDistance(0.1);
|
---|
350 |
|
---|
351 | switch (scene)
|
---|
352 | {
|
---|
353 | case 1:
|
---|
354 | createScene1();break;
|
---|
355 | case 2:
|
---|
356 | createScene2();break;
|
---|
357 | case 3:
|
---|
358 | createScene3();break;
|
---|
359 | }
|
---|
360 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
361 |
|
---|
362 |
|
---|
363 | }
|
---|
364 |
|
---|
365 | void createScene1()
|
---|
366 | {
|
---|
367 |
|
---|
368 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.0537, 0.0));
|
---|
369 | //mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
|
---|
370 |
|
---|
371 |
|
---|
372 | // Skybox
|
---|
373 | //mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
374 |
|
---|
375 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
376 |
|
---|
377 | Entity* object = mSceneMgr->createEntity("object", "chinaman.mesh");
|
---|
378 | object->setMaterialName("GameTools/Diffuse/use");
|
---|
379 | //object->setMaterialName("GameTools/Diffuse2");
|
---|
380 | objectNode = rootNode->createChildSceneNode();
|
---|
381 | objectNode->attachObject(object);
|
---|
382 | // objectNode->scale(0.05,0.05,0.05);
|
---|
383 | objectNode->scale(3,3,3);
|
---|
384 | // objectNode->setPosition(0,4,0);
|
---|
385 | objectNode->_updateBounds();
|
---|
386 |
|
---|
387 | Entity* room = mSceneMgr->createEntity("atlascube", "diffscene.mesh");
|
---|
388 | //room->setMaterialName("GameTools/Phong");
|
---|
389 | SceneNode* roomNode = rootNode->createChildSceneNode();
|
---|
390 | //roomNode->setScale(10,10,10);
|
---|
391 | roomNode->attachObject(room);
|
---|
392 | roomNode->_updateBounds();
|
---|
393 |
|
---|
394 | Light* bluelight = mSceneMgr->createLight("BlueLight");
|
---|
395 | bluelight->setType(Light::LT_POINT);
|
---|
396 | bluelight->setDiffuseColour(ColourValue(0.152,0.824, 1.0));
|
---|
397 | //bluelight->setSpecularColour(ColourValue(0.152,0.824, 1.0));
|
---|
398 | bluelight->setPowerScale(5.726);
|
---|
399 | bluelight->setAttenuation(12, 0, 1, 0);
|
---|
400 | SceneNode* bluelightNode = rootNode->createChildSceneNode();
|
---|
401 | bluelightNode->setPosition(-5.948,9.619,0.980);
|
---|
402 | bluelightNode->attachObject(bluelight);
|
---|
403 |
|
---|
404 | Light* walllight1 = mSceneMgr->createLight("WallLight1");
|
---|
405 | walllight1->setType(Light::LT_POINT);
|
---|
406 | walllight1->setDiffuseColour(ColourValue(0.988,1.0, 0.808));
|
---|
407 | //walllight1->setSpecularColour(ColourValue(0.988,1.0, 0.808));
|
---|
408 | walllight1->setPowerScale(2.5);
|
---|
409 | walllight1->setAttenuation(12, 0, 1, 0);
|
---|
410 | SceneNode* walllight1Node = rootNode->createChildSceneNode();
|
---|
411 | walllight1Node->setPosition(-4.822,9.353,-5.194);
|
---|
412 | walllight1Node->attachObject(walllight1);
|
---|
413 |
|
---|
414 | Light* walllight2 = mSceneMgr->createLight("WallLight2");
|
---|
415 | walllight2->setType(Light::LT_POINT);
|
---|
416 | walllight2->setDiffuseColour(ColourValue(0.988,1.0, 0.808));
|
---|
417 | //walllight2->setSpecularColour(ColourValue(0.988,1.0, 0.808));
|
---|
418 | walllight2->setPowerScale(2.5);
|
---|
419 | walllight2->setAttenuation(12, 0, 1, 0);
|
---|
420 | SceneNode* walllight2Node = rootNode->createChildSceneNode();
|
---|
421 | walllight2Node->setPosition(-4.822,9.353,5.150);
|
---|
422 | walllight2Node->attachObject(walllight2);
|
---|
423 |
|
---|
424 | Light* walllight3 = mSceneMgr->createLight("WallLight3");
|
---|
425 | walllight3->setType(Light::LT_POINT);
|
---|
426 | walllight3->setDiffuseColour(ColourValue(0.988,1.0, 0.808));
|
---|
427 | //walllight3->setSpecularColour(ColourValue(0.988,1.0, 0.808));
|
---|
428 | walllight3->setPowerScale(2.5);
|
---|
429 | walllight3->setAttenuation(12, 0, 1, 0);
|
---|
430 | SceneNode* walllight3Node = rootNode->createChildSceneNode();
|
---|
431 | walllight3Node->setPosition(-11.08,10.07,-24.658);
|
---|
432 | walllight3Node->attachObject(walllight3);
|
---|
433 |
|
---|
434 | Light* walllight4 = mSceneMgr->createLight("WallLight4");
|
---|
435 | walllight4->setType(Light::LT_POINT);
|
---|
436 | walllight4->setDiffuseColour(ColourValue(0.988,1.0, 0.808));
|
---|
437 | //walllight4->setSpecularColour(ColourValue(0.988,1.0, 0.808));
|
---|
438 | walllight4->setPowerScale(2.5);
|
---|
439 | walllight4->setAttenuation(12, 0, 1, 0);
|
---|
440 | SceneNode* walllight4Node = rootNode->createChildSceneNode();
|
---|
441 | walllight4Node->setPosition(-11.08,10.07,-11.474);
|
---|
442 | walllight4Node->attachObject(walllight4);
|
---|
443 |
|
---|
444 | Light* redlight1 = mSceneMgr->createLight("RedLight1");
|
---|
445 | redlight1->setType(Light::LT_POINT);
|
---|
446 | redlight1->setDiffuseColour(ColourValue(1.0,0.367, 0.016));
|
---|
447 | //redlight1->setSpecularColour(ColourValue(1.0,0.367, 0.016));
|
---|
448 | redlight1->setPowerScale(3.59);
|
---|
449 | redlight1->setAttenuation(2, 0, 1, 0);
|
---|
450 | SceneNode* redlight1Node = rootNode->createChildSceneNode();
|
---|
451 | redlight1Node->setPosition(24.958,7.743,-10.838);
|
---|
452 | redlight1Node->attachObject(redlight1);
|
---|
453 |
|
---|
454 | Light* redlight2 = mSceneMgr->createLight("RedLight2");
|
---|
455 | redlight2->setType(Light::LT_POINT);
|
---|
456 | redlight2->setDiffuseColour(ColourValue(1.0,0.367, 0.016));
|
---|
457 | //redlight2->setSpecularColour(ColourValue(1.0,0.367, 0.016));
|
---|
458 | redlight2->setPowerScale(3.59);
|
---|
459 | redlight2->setAttenuation(2, 0, 1, 0);
|
---|
460 | SceneNode* redlight2Node = rootNode->createChildSceneNode();
|
---|
461 | redlight2Node->setPosition(18.689,7.743,-10.838);
|
---|
462 | redlight2Node->attachObject(redlight2);
|
---|
463 | }
|
---|
464 |
|
---|
465 | Camera* mReflectCamFloor;
|
---|
466 | Camera* mReflectCamCeil;
|
---|
467 | ReflectionCameraFrameListener* reflListener;
|
---|
468 | void createScene2()
|
---|
469 | {
|
---|
470 | mCamera->setPosition(0,5,10);
|
---|
471 | MovablePlane *floorPlane = new MovablePlane("ReflectPlaneFloor");
|
---|
472 | floorPlane->d = 0;
|
---|
473 | floorPlane->normal = Vector3::UNIT_Y;
|
---|
474 |
|
---|
475 | RenderTexture* rttTexFloor = mRoot->getRenderSystem()->createRenderTexture( "FloorReflection", 512, 512, TEX_TYPE_2D, PF_R8G8B8 );
|
---|
476 | {
|
---|
477 | mReflectCamFloor = mSceneMgr->createCamera("ReflectCamFloor");
|
---|
478 | mReflectCamFloor->setNearClipDistance(mCamera->getNearClipDistance());
|
---|
479 | mReflectCamFloor->setFarClipDistance(mCamera->getFarClipDistance());
|
---|
480 | /* mReflectCamFloor->setAspectRatio(
|
---|
481 | (Real)mWindow->getViewport(0)->getActualWidth() /
|
---|
482 | (Real)mWindow->getViewport(0)->getActualHeight());*/
|
---|
483 | mReflectCamFloor->setFOVy(mCamera->getFOVy());
|
---|
484 | mReflectCamFloor->setAspectRatio(mCamera->getAspectRatio());
|
---|
485 |
|
---|
486 | Viewport *v = rttTexFloor->addViewport( mReflectCamFloor );
|
---|
487 | v->setClearEveryFrame( true );
|
---|
488 | v->setBackgroundColour( ColourValue::Black );
|
---|
489 |
|
---|
490 |
|
---|
491 | // set up linked reflection
|
---|
492 | mReflectCamFloor->enableReflection(floorPlane);
|
---|
493 | // Also clip
|
---|
494 | mReflectCamFloor->enableCustomNearClipPlane(floorPlane);
|
---|
495 | }
|
---|
496 | /* MovablePlane *ceilPlane = new MovablePlane("ReflectPlaneCeil");
|
---|
497 | ceilPlane->d = -8;
|
---|
498 | ceilPlane->normal = Vector3::NEGATIVE_UNIT_Y;
|
---|
499 | RenderTexture* rttTexCeil = mRoot->getRenderSystem()->createRenderTexture( "CeilReflection", 512, 512, TEX_TYPE_2D, PF_R8G8B8 );
|
---|
500 | {
|
---|
501 | mReflectCamCeil = mSceneMgr->createCamera("ReflectCamCeil");
|
---|
502 | mReflectCamCeil->setNearClipDistance(mCamera->getNearClipDistance());
|
---|
503 | mReflectCamCeil->setFarClipDistance(mCamera->getFarClipDistance());
|
---|
504 | mReflectCamCeil->setAspectRatio(
|
---|
505 | (Real)mWindow->getViewport(0)->getActualWidth() /
|
---|
506 | (Real)mWindow->getViewport(0)->getActualHeight());
|
---|
507 |
|
---|
508 | Viewport *v = rttTexCeil->addViewport( mReflectCamCeil );
|
---|
509 | v->setClearEveryFrame( true );
|
---|
510 | v->setBackgroundColour( ColourValue::Black );
|
---|
511 |
|
---|
512 |
|
---|
513 | // set up linked reflection
|
---|
514 | mReflectCamCeil->enableReflection(floorPlane);
|
---|
515 | // Also clip
|
---|
516 | mReflectCamCeil->enableCustomNearClipPlane(floorPlane);
|
---|
517 | }
|
---|
518 | */
|
---|
519 | reflListener = new ReflectionCameraFrameListener(mReflectCamFloor, mReflectCamCeil, mCamera);
|
---|
520 | reflListener->setPriority(2);
|
---|
521 |
|
---|
522 | // mSceneMgr->setAmbientLight(ColourValue(0.1, 0.0537, 0.0));
|
---|
523 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.25, 0.3));
|
---|
524 |
|
---|
525 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
526 |
|
---|
527 | Entity* object = mSceneMgr->createEntity("object", "buddha.mesh");
|
---|
528 | object->setMaterialName("GameTools/Diffuse/use");
|
---|
529 | //object->setMaterialName("GameTools/Diffuse2");
|
---|
530 | objectNode = rootNode->createChildSceneNode();
|
---|
531 | objectNode->attachObject(object);
|
---|
532 | objectNode->scale(1.8,1.8,1.8);
|
---|
533 | objectNode->rotate(Vector3(0,1,0),Radian(Math::PI));
|
---|
534 | objectNode->setPosition(0,0,0);
|
---|
535 | objectNode->_updateBounds();
|
---|
536 |
|
---|
537 | Entity* room = mSceneMgr->createEntity("scene", "uvegfolyoso2.mesh");
|
---|
538 | //room->setMaterialName("GameTools/Phong");
|
---|
539 | SceneNode* roomNode = rootNode->createChildSceneNode();
|
---|
540 | roomNode->attachObject(room);
|
---|
541 | roomNode->_updateBounds();
|
---|
542 | rttTexFloor->addListener(new FloorRenderTargetListener(room));
|
---|
543 | //rttTexCeil->addListener(new CeilRenderTargetListener(room));
|
---|
544 |
|
---|
545 | Light* light1 = mSceneMgr->createLight("Light1");
|
---|
546 | light1->setType(Light::LT_POINT);
|
---|
547 | light1->setDiffuseColour(ColourValue(0.526,0.535, 0.974));
|
---|
548 | light1->setPowerScale(3);
|
---|
549 | SceneNode* lightNode1 = rootNode->createChildSceneNode();
|
---|
550 | lightNode1->setPosition(-1.266,4.131,-4.438);
|
---|
551 | lightNode1->attachObject(light1);
|
---|
552 |
|
---|
553 | Light* light2 = mSceneMgr->createLight("Light2");
|
---|
554 | light2->setType(Light::LT_POINT);
|
---|
555 | light2->setDiffuseColour(ColourValue(0.391,0.781, 0.974));
|
---|
556 | light2->setPowerScale(3);
|
---|
557 | SceneNode* lightNode2 = rootNode->createChildSceneNode();
|
---|
558 | lightNode2->setPosition(-33.537,4.131,-4.438);
|
---|
559 | lightNode2->attachObject(light2);
|
---|
560 |
|
---|
561 | Light* light3 = mSceneMgr->createLight("Light3");
|
---|
562 | light3->setType(Light::LT_POINT);
|
---|
563 | light3->setDiffuseColour(ColourValue(0.391,0.781, 0.974));
|
---|
564 | light3->setPowerScale(3);
|
---|
565 | SceneNode* lightNode3 = rootNode->createChildSceneNode();
|
---|
566 | lightNode3->setPosition(-97.446,4.131,-4.438);
|
---|
567 | lightNode3->attachObject(light3);
|
---|
568 |
|
---|
569 | Light* light4 = mSceneMgr->createLight("Light4");
|
---|
570 | light4->setType(Light::LT_POINT);
|
---|
571 | light4->setDiffuseColour(ColourValue(0.304,0.974, 0.770));
|
---|
572 | light4->setPowerScale(3);
|
---|
573 | SceneNode* lightNode4 = rootNode->createChildSceneNode();
|
---|
574 | lightNode4->setPosition(-63.277,4.131,-4.438);
|
---|
575 | lightNode4->attachObject(light4);
|
---|
576 |
|
---|
577 |
|
---|
578 |
|
---|
579 |
|
---|
580 |
|
---|
581 | }
|
---|
582 |
|
---|
583 | void createScene3()
|
---|
584 | {
|
---|
585 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
586 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
587 | OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
|
---|
588 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GameTools/ShadowMapDistance");
|
---|
589 | mSceneMgr->setAmbientLight(ColourValue(0.505 * 0.2, 0.897 * 0.2, 0.914 * 0.2));
|
---|
590 |
|
---|
591 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
592 |
|
---|
593 | Entity* object = mSceneMgr->createEntity("object", "buddha.mesh");
|
---|
594 | object->setMaterialName("GameTools/Diffuse/use");
|
---|
595 | //object->setMaterialName("GameTools/DiffuseP2P");
|
---|
596 | objectNode = rootNode->createChildSceneNode();
|
---|
597 | objectNode->attachObject(object);
|
---|
598 | objectNode->scale(0.4,0.4,0.4);
|
---|
599 | objectNode->rotate(Vector3(0,1,0),Radian(Math::PI));
|
---|
600 | objectNode->setPosition(0,0,0);
|
---|
601 | objectNode->_updateBounds();
|
---|
602 |
|
---|
603 | Entity* room = mSceneMgr->createEntity("scene", "difflab.mesh");
|
---|
604 | //room->setMaterialName("GameTools/Phong");
|
---|
605 | SceneNode* roomNode = rootNode->createChildSceneNode();
|
---|
606 | roomNode->attachObject(room);
|
---|
607 | roomNode->_updateBounds();
|
---|
608 |
|
---|
609 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
610 | Light* redLight1 = mSceneMgr->createLight("RedLight1");
|
---|
611 | redLight1->setType(Light::LT_POINT);
|
---|
612 | redLight1->setCastShadows(false);
|
---|
613 | redLight1->setDiffuseColour(ColourValue(1,0.055, 0.0));
|
---|
614 | redLight1->setPowerScale(1.6);
|
---|
615 | SceneNode* redLightNode1 = rootNode->createChildSceneNode();
|
---|
616 | redLightNode1->setPosition(0.05,2.361,-1.07);
|
---|
617 | redLightNode1->attachObject(redLight1);
|
---|
618 |
|
---|
619 | Light* greenLight1 = mSceneMgr->createLight("GreenLight1");
|
---|
620 | greenLight1->setType(Light::LT_POINT);
|
---|
621 | greenLight1->setCastShadows(false);
|
---|
622 | greenLight1->setDiffuseColour(ColourValue(0.362,0.783, 0.685));
|
---|
623 | greenLight1->setPowerScale(2.0);
|
---|
624 | SceneNode* greenLightNode1 = rootNode->createChildSceneNode();
|
---|
625 | greenLightNode1->setPosition(1.312,1.313,0);
|
---|
626 | greenLightNode1->attachObject(greenLight1);
|
---|
627 |
|
---|
628 | Light* mainBlueLight = mSceneMgr->createLight("MainBlueLight");
|
---|
629 | mainBlueLight->setType(Light::LT_SPOTLIGHT);
|
---|
630 | mainBlueLight->setCastShadows(true);
|
---|
631 | mainBlueLight->setDiffuseColour(ColourValue(0.395,0.766, 1.0));
|
---|
632 | mainBlueLight->setPowerScale(5.0);
|
---|
633 | mainBlueLight->setSpotlightRange(Degree(0),Degree(160));
|
---|
634 | mainBlueLight->setAttenuation(2.5, 0, 1, 0);
|
---|
635 | SceneNode* mainBlueLightNode = rootNode->createChildSceneNode();
|
---|
636 | mainBlueLightNode->setPosition(-0.546,2.095,1.035);
|
---|
637 | //mainBlueLightNode->rotate(Vector3::UNIT_X, Degree(161.396));
|
---|
638 | //mainBlueLightNode->rotate(Vector3::UNIT_Y, Degree(53.955));
|
---|
639 | //mainBlueLightNode->rotate(Vector3::UNIT_Z, Degree(-145.065));
|
---|
640 | mainBlueLight->setDirection(-1.5,-2.0,1.0);
|
---|
641 | mainBlueLightNode->attachObject(mainBlueLight);
|
---|
642 | /*
|
---|
643 | Light* blueLight1 = mSceneMgr->createLight("BlueLight1");
|
---|
644 | blueLight1->setType(Light::LT_SPOTLIGHT);
|
---|
645 | blueLight1->setCastShadows(false);
|
---|
646 | blueLight1->setDiffuseColour(ColourValue(0.395,0.766, 1.0));
|
---|
647 | blueLight1->setPowerScale(0.7);
|
---|
648 | blueLight1->setSpotlightRange(Degree(20),Degree(90));
|
---|
649 | SceneNode* blueLightNode = rootNode->createChildSceneNode();
|
---|
650 | blueLightNode->setPosition(-0.9,2.095,0.185);
|
---|
651 | //blueLightNode->rotate(Vector3::UNIT_X, Degree(148.785));
|
---|
652 | //blueLightNode->rotate(Vector3::UNIT_Y, Degree(39.001));
|
---|
653 | //blueLightNode->rotate(Vector3::UNIT_Z, Degree(-154.304));
|
---|
654 | blueLight1->setDirection(-1.5,-2.0,1.0);
|
---|
655 | blueLightNode->attachObject(blueLight1);
|
---|
656 |
|
---|
657 | Light* blueLight2 = mSceneMgr->createLight("BlueLight2");
|
---|
658 | blueLight2->setType(Light::LT_SPOTLIGHT);
|
---|
659 | blueLight2->setCastShadows(false);
|
---|
660 | blueLight2->setDiffuseColour(ColourValue(0.395,0.766, 1.0));
|
---|
661 | blueLight2->setPowerScale(0.7);
|
---|
662 | blueLight2->setSpotlightRange(Degree(20),Degree(90));
|
---|
663 | SceneNode* blueLightNode2 = rootNode->createChildSceneNode();
|
---|
664 | blueLightNode2->setPosition(0.091,2.095,1.556);
|
---|
665 | //blueLightNode2->rotate(Vector3::UNIT_X, Degree(-112.941));
|
---|
666 | //blueLightNode2->rotate(Vector3::UNIT_Y, Degree(68.432));
|
---|
667 | //blueLightNode2->rotate(Vector3::UNIT_Z, Degree(-66.441));
|
---|
668 | blueLight2->setDirection(-1.5,-2.0,1.0);
|
---|
669 | blueLightNode2->attachObject(blueLight2); */
|
---|
670 | }
|
---|
671 |
|
---|
672 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
|
---|
673 |
|
---|
674 | Plane _plane;
|
---|
675 | _plane.normal = Vector3::UNIT_Y;
|
---|
676 | _plane.d = 0;
|
---|
677 |
|
---|
678 |
|
---|
679 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
680 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
681 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
682 |
|
---|
683 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
684 | _entity->setMaterialName(_material);
|
---|
685 |
|
---|
686 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
687 | _node->attachObject(_entity);
|
---|
688 | _node->setPosition(_pos);
|
---|
689 | }
|
---|
690 |
|
---|
691 |
|
---|
692 |
|
---|
693 | void createFrameListener(void)
|
---|
694 | {
|
---|
695 | // This is where we instantiate our own frame listener
|
---|
696 | mFrameListener= new RaytraceDemoListener(mWindow,
|
---|
697 | mCamera,
|
---|
698 | objectNode
|
---|
699 | );
|
---|
700 | mFrameListener->setPriority(1);
|
---|
701 | OgreIlluminationManager::getSingleton().setPriority(10);
|
---|
702 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
703 | mRoot->addFrameListener(mFrameListener);
|
---|
704 | if(scene == 2)
|
---|
705 | mRoot->addFrameListener(reflListener);
|
---|
706 |
|
---|
707 | }
|
---|
708 |
|
---|
709 | };
|
---|
710 |
|
---|
711 |
|
---|