[1720] | 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 |
|
---|
| 27 | #include "ExampleApplication.h"
|
---|
| 28 | #include "OgreIlluminationManager.h"
|
---|
| 29 | #include "SpriteParticleRenderer.h"
|
---|
[1847] | 30 | #include "FrameCapture.h"
|
---|
[2140] | 31 | #include "OgreCausticCubeMapRenderingRun.h"
|
---|
[1720] | 32 |
|
---|
[2140] | 33 | float worldSizeVar = 0.002;
|
---|
| 34 | float refIndex = 0.995;
|
---|
| 35 | int scene = 1;
|
---|
[1847] | 36 | FrameCapture* capture;
|
---|
[1720] | 37 |
|
---|
[1856] | 38 | bool multiplebounce = true;
|
---|
[2140] | 39 | bool useCauInt = true;
|
---|
[1856] | 40 |
|
---|
[2175] | 41 | int currentMaterial = 1;
|
---|
[2140] | 42 | int currentObject = 1;
|
---|
[2057] | 43 | String objectNames[] = {String("sphere.mesh"),
|
---|
[2095] | 44 | String("teapot.mesh"),
|
---|
[2175] | 45 | String("colorcube.mesh"),
|
---|
[2140] | 46 | String("head.mesh")};
|
---|
[2057] | 47 |
|
---|
[2140] | 48 | float objectscales[] = {0.01,1,1,0.1};
|
---|
| 49 | float scenescales[] = {0.3,1, 2.7};
|
---|
| 50 |
|
---|
[2057] | 51 | String materialNames[] = {String("GTP/MultiBounce/Reflector"),
|
---|
| 52 | String("GTP/MultiBounce/Refractor"),
|
---|
| 53 | String("GTP/MultiBounce/CausticRefractor"),
|
---|
| 54 | String("GTP/MultiBounce/Reflector_MinMax"),
|
---|
| 55 | String("GTP/MultiBounce/Refractor_MinMax"),
|
---|
[2140] | 56 | String("GTP/MultiBounce/CausticRefractor_MinMax"),
|
---|
| 57 | String("semmi")
|
---|
| 58 | };
|
---|
[2057] | 59 |
|
---|
| 60 | String resourceGroupName[] = { String("GTP_MultipleReflection"),
|
---|
| 61 | String("GTP_MultipleRefraction"),
|
---|
| 62 | String("GTP_MultipleRefraction"),
|
---|
| 63 | String("GTP_MultipleReflection_MinMax"),
|
---|
| 64 | String("GTP_MultipleRefraction_MinMax"),
|
---|
[2140] | 65 | String("GTP_MultipleRefraction_MinMax"),
|
---|
| 66 | String("GTP_Basic")};
|
---|
[2057] | 67 |
|
---|
[1720] | 68 | // Listener class for frame updates
|
---|
| 69 | class RaytraceDemoListener : public ExampleFrameListener
|
---|
| 70 | {
|
---|
| 71 | protected:
|
---|
| 72 | unsigned long framecount;
|
---|
[1724] | 73 | SceneNode* objectNode;
|
---|
[2140] | 74 | Entity *object;
|
---|
[1720] | 75 |
|
---|
| 76 | public:
|
---|
[1862] | 77 | void setMoveSpeed(float speed){mMoveSpeed = speed;}
|
---|
[2140] | 78 | RaytraceDemoListener(RenderWindow* window, Camera* maincam, SceneNode* objectNode, Entity* object)
|
---|
[1720] | 79 | :ExampleFrameListener(window, maincam)
|
---|
| 80 |
|
---|
| 81 | {
|
---|
[2140] | 82 | this->object = object;
|
---|
| 83 | this->mMoveSpeed = 1;
|
---|
[1862] | 84 | if(scene == 2)
|
---|
| 85 | this->mMoveSpeed = 1.0;
|
---|
| 86 | if(scene == 3)
|
---|
[2057] | 87 | this->mMoveSpeed = 10.0;
|
---|
[1862] | 88 | mStatsOn = false;
|
---|
| 89 | showDebugOverlay(mStatsOn);
|
---|
| 90 |
|
---|
[1720] | 91 | framecount = 0;
|
---|
[1856] | 92 | this->objectNode = objectNode;
|
---|
[1847] | 93 |
|
---|
[1720] | 94 | }
|
---|
[1847] | 95 |
|
---|
| 96 | void moveCamera()
|
---|
| 97 | {/*
|
---|
| 98 | mCamera->yaw(mRotX);
|
---|
| 99 | mCamera->pitch(mRotY);
|
---|
| 100 | mCamera->moveRelative(mTranslateVector);*/
|
---|
| 101 |
|
---|
| 102 | mCamera->getParentSceneNode()->yaw(mRotX, Node::TransformSpace::TS_WORLD);
|
---|
| 103 | mCamera->getParentSceneNode()->pitch(mRotY, Node::TransformSpace::TS_LOCAL);
|
---|
| 104 | mCamera->getParentSceneNode()->translate(mTranslateVector, Node::TransformSpace::TS_LOCAL);
|
---|
| 105 |
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[1720] | 108 | bool processUnbufferedKeyInput(const FrameEvent& evt)
|
---|
| 109 | {
|
---|
[1849] | 110 | static float lastTime = 0.0;
|
---|
| 111 | float thisTime = (float) Root::getSingleton().getTimer()->getMilliseconds() / 1000.0f;
|
---|
| 112 | float elapsed = thisTime - lastTime;
|
---|
[2140] | 113 | float move = elapsed * 0.5;
|
---|
| 114 | if(scene == 3 )
|
---|
[2057] | 115 | move *= 10;
|
---|
[1849] | 116 | float rotate = 80.0 * move;
|
---|
[2140] | 117 | if (mInputDevice->isKeyDown(KC_G))
|
---|
| 118 | {
|
---|
| 119 | worldSizeVar -= 0.002;
|
---|
| 120 | if(worldSizeVar < 0.002)worldSizeVar = 0.002;
|
---|
| 121 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/MultiBounce/CauCube_Trianglesobject_SE_0_clone");
|
---|
| 122 | if(!mat.isNull())
|
---|
| 123 | {
|
---|
| 124 | GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer();
|
---|
| 125 | Vparams->setNamedConstant("WorldSize", worldSizeVar);
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | if (mInputDevice->isKeyDown(KC_H))
|
---|
| 129 | {
|
---|
| 130 | worldSizeVar += 0.002;
|
---|
| 131 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/MultiBounce/CauCube_Trianglesobject_SE_0_clone");
|
---|
| 132 | if(!mat.isNull())
|
---|
| 133 | {
|
---|
| 134 | GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer();
|
---|
| 135 | Vparams->setNamedConstant("WorldSize", worldSizeVar);
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | if (mInputDevice->isKeyDown(KC_I) && mTimeUntilNextToggle <= 0)
|
---|
| 139 | {
|
---|
| 140 | useCauInt = !useCauInt;
|
---|
[1849] | 141 |
|
---|
[2140] | 142 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/MultiBounce/CauCube_Trianglesobject_SE_0_clone");
|
---|
| 143 | if(!mat.isNull())
|
---|
| 144 | {
|
---|
| 145 | GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer();
|
---|
| 146 | Vparams->setNamedConstant("notUseIntensity", !useCauInt);
|
---|
| 147 | if(useCauInt)
|
---|
| 148 | {
|
---|
| 149 | mat->getTechnique(0)->getPass(0)->setPolygonMode(PM_SOLID);
|
---|
| 150 | OgreTechniqueGroup* tg = (OgreTechniqueGroup*) object->getSubEntity(0)->getRenderTechniqueGroup();
|
---|
| 151 | OgreCausticCubeMapRenderingRun* rr = (OgreCausticCubeMapRenderingRun*)
|
---|
| 152 | tg->getSharedRuns()->getRun(ILLUMRUN_CAUSTIC_CUBEMAP)
|
---|
| 153 | ->asOgreRenderingRun();
|
---|
| 154 | rr->setBlurMap(true);
|
---|
| 155 | }
|
---|
| 156 | else
|
---|
| 157 | {
|
---|
| 158 | mat->getTechnique(0)->getPass(0)->setPolygonMode(PM_POINTS);
|
---|
| 159 | OgreTechniqueGroup* tg = (OgreTechniqueGroup*) object->getSubEntity(0)->getRenderTechniqueGroup();
|
---|
| 160 | OgreCausticCubeMapRenderingRun* rr = (OgreCausticCubeMapRenderingRun*)
|
---|
| 161 | tg->getSharedRuns()->getRun(ILLUMRUN_CAUSTIC_CUBEMAP)
|
---|
| 162 | ->asOgreRenderingRun();
|
---|
| 163 | rr->setBlurMap(false);
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | mTimeUntilNextToggle = 1;
|
---|
| 167 | }
|
---|
[2057] | 168 | if (mInputDevice->isKeyDown(KC_J))
|
---|
[2095] | 169 | {
|
---|
[2057] | 170 | refIndex -= 0.001;
|
---|
| 171 |
|
---|
[2095] | 172 | MaterialPtr mat1 = MaterialManager::getSingleton().getByName(materialNames[currentMaterial]);
|
---|
| 173 | if(!mat1.isNull())
|
---|
| 174 | {
|
---|
| 175 | GpuProgramParameters* Fparams1 = mat1->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
| 176 | Fparams1->setNamedConstant("refIndex", refIndex);
|
---|
| 177 | }
|
---|
[2140] | 178 | //MaterialPtr mat2 = MaterialManager::getSingleton().getByName("GTP/MultiBounce/PhotonMap");
|
---|
| 179 | MaterialPtr mat2 = MaterialManager::getSingleton().getByName("GTP/Caustic/PhotonMap_HitEnv");
|
---|
[2095] | 180 | if(!mat2.isNull())
|
---|
| 181 | {
|
---|
| 182 | GpuProgramParameters* Fparams2 = mat2->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
| 183 | Fparams2->setNamedConstant("refIndex", refIndex);
|
---|
| 184 | }
|
---|
[2057] | 185 | }
|
---|
| 186 | if (mInputDevice->isKeyDown(KC_K))
|
---|
| 187 | {
|
---|
| 188 | refIndex += 0.001;
|
---|
[2095] | 189 |
|
---|
| 190 | MaterialPtr mat1 = MaterialManager::getSingleton().getByName(materialNames[currentMaterial]);
|
---|
| 191 | if(!mat1.isNull())
|
---|
| 192 | {
|
---|
| 193 | GpuProgramParameters* Fparams1 = mat1->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
| 194 | Fparams1->setNamedConstant("refIndex", refIndex);
|
---|
| 195 | }
|
---|
[2140] | 196 | //MaterialPtr mat2 = MaterialManager::getSingleton().getByName("GTP/MultiBounce/PhotonMap");
|
---|
| 197 | MaterialPtr mat2 = MaterialManager::getSingleton().getByName("GTP/Caustic/PhotonMap_HitEnv");
|
---|
[2095] | 198 | if(!mat2.isNull())
|
---|
| 199 | {
|
---|
| 200 | GpuProgramParameters* Fparams2 = mat2->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
| 201 | Fparams2->setNamedConstant("refIndex", refIndex);
|
---|
| 202 | }
|
---|
[2057] | 203 | }
|
---|
| 204 |
|
---|
[1724] | 205 | if (mInputDevice->isKeyDown(KC_UP))
|
---|
| 206 | {
|
---|
[1849] | 207 | objectNode->translate(0,0,move);
|
---|
[1724] | 208 | }
|
---|
| 209 | if (mInputDevice->isKeyDown(KC_MULTIPLY))
|
---|
| 210 | {
|
---|
| 211 | //objectNode->scale(1.1,1.1,1.1);
|
---|
[1849] | 212 | objectNode->rotate(Vector3(0,0,1), Degree(rotate));
|
---|
[1856] | 213 |
|
---|
[1724] | 214 | }
|
---|
| 215 | if (mInputDevice->isKeyDown(KC_DIVIDE))
|
---|
| 216 | {
|
---|
| 217 | //objectNode->scale(1.0/1.1,1.0/1.1,1.0/1.1);
|
---|
[1849] | 218 | objectNode->rotate(Vector3(1,0,0), Degree(rotate));
|
---|
[1856] | 219 |
|
---|
[1724] | 220 | }
|
---|
| 221 | if (mInputDevice->isKeyDown(KC_ADD))
|
---|
| 222 | {
|
---|
[1849] | 223 | objectNode->rotate(Vector3(0,1,0), Degree(rotate));
|
---|
[1724] | 224 | }
|
---|
| 225 | if (mInputDevice->isKeyDown(KC_HOME))
|
---|
| 226 | {
|
---|
[1849] | 227 | objectNode->translate(0,move,0);
|
---|
[1724] | 228 | }
|
---|
| 229 | if (mInputDevice->isKeyDown(KC_END))
|
---|
| 230 | {
|
---|
[1849] | 231 | objectNode->translate(0,-move,0);
|
---|
[1724] | 232 | }
|
---|
| 233 | if (mInputDevice->isKeyDown(KC_DOWN))
|
---|
| 234 | {
|
---|
[1849] | 235 | objectNode->translate(0,0,-move);
|
---|
[1724] | 236 | }
|
---|
| 237 | if (mInputDevice->isKeyDown(KC_RIGHT))
|
---|
| 238 | {
|
---|
[1849] | 239 | objectNode->translate(-move,0,0);
|
---|
[1724] | 240 | }
|
---|
| 241 | if (mInputDevice->isKeyDown(KC_LEFT))
|
---|
| 242 | {
|
---|
[1849] | 243 | objectNode->translate(move,0,0);
|
---|
[1724] | 244 | }
|
---|
| 245 |
|
---|
| 246 | if (mInputDevice->isKeyDown(KC_A))
|
---|
| 247 | {
|
---|
| 248 | // Move camera left
|
---|
| 249 | mTranslateVector.x = -mMoveScale;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | if (mInputDevice->isKeyDown(KC_D))
|
---|
| 253 | {
|
---|
| 254 | // Move camera RIGHT
|
---|
| 255 | mTranslateVector.x = mMoveScale;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | /* Move camera forward by keypress. */
|
---|
| 259 | if ( mInputDevice->isKeyDown(KC_W) )
|
---|
| 260 | {
|
---|
| 261 | mTranslateVector.z = -mMoveScale;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | /* Move camera backward by keypress. */
|
---|
| 265 | if (mInputDevice->isKeyDown(KC_S) )
|
---|
| 266 | {
|
---|
| 267 | mTranslateVector.z = mMoveScale;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | if (mInputDevice->isKeyDown(KC_PGUP))
|
---|
| 271 | {
|
---|
| 272 | // Move camera up
|
---|
| 273 | mTranslateVector.y = mMoveScale;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | if (mInputDevice->isKeyDown(KC_PGDOWN))
|
---|
| 277 | {
|
---|
| 278 | // Move camera down
|
---|
| 279 | mTranslateVector.y = -mMoveScale;
|
---|
[1847] | 280 | }
|
---|
| 281 | if (mInputDevice->isKeyDown(KC_N) && mTimeUntilNextToggle <= 0)
|
---|
| 282 | {
|
---|
| 283 | capture->playEvent();
|
---|
| 284 | mTimeUntilNextToggle = 1;
|
---|
| 285 | }
|
---|
| 286 | if (mInputDevice->isKeyDown(KC_B) && mTimeUntilNextToggle <= 0)
|
---|
| 287 | {
|
---|
| 288 | capture->recordEvent();
|
---|
| 289 | mTimeUntilNextToggle = 1;
|
---|
| 290 | }
|
---|
| 291 | if (mInputDevice->isKeyDown(KC_M) && mTimeUntilNextToggle <= 0)
|
---|
| 292 | {
|
---|
| 293 | capture->setSaving();
|
---|
| 294 | capture->playEvent();
|
---|
| 295 | mTimeUntilNextToggle = 1;
|
---|
[2095] | 296 | }
|
---|
[1724] | 297 |
|
---|
| 298 | if( mInputDevice->isKeyDown( KC_ESCAPE) )
|
---|
| 299 | {
|
---|
| 300 | return false;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | // see if switching is on, and you want to toggle
|
---|
| 304 | if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_M) && mTimeUntilNextToggle <= 0)
|
---|
| 305 | {
|
---|
| 306 | switchMouseMode();
|
---|
| 307 | mTimeUntilNextToggle = 1;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_K) && mTimeUntilNextToggle <= 0)
|
---|
| 311 | {
|
---|
| 312 | // must be going from immediate keyboard to buffered keyboard
|
---|
| 313 | switchKeyMode();
|
---|
| 314 | mTimeUntilNextToggle = 1;
|
---|
| 315 | }
|
---|
| 316 | if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
|
---|
| 317 | {
|
---|
| 318 | mStatsOn = !mStatsOn;
|
---|
| 319 | showDebugOverlay(mStatsOn);
|
---|
| 320 |
|
---|
| 321 | mTimeUntilNextToggle = 1;
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
|
---|
| 325 | {
|
---|
| 326 | char tmp[20];
|
---|
| 327 | sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
|
---|
| 328 | mWindow->writeContentsToFile(tmp);
|
---|
| 329 | mTimeUntilNextToggle = 0.5;
|
---|
| 330 | mWindow->setDebugText(String("Wrote ") + tmp);
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | static bool displayCameraDetails = false;
|
---|
| 334 | if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
|
---|
| 335 | {
|
---|
| 336 | displayCameraDetails = !displayCameraDetails;
|
---|
| 337 | mTimeUntilNextToggle = 0.5;
|
---|
| 338 | if (!displayCameraDetails)
|
---|
| 339 | mWindow->setDebugText("");
|
---|
| 340 | }
|
---|
| 341 | if (displayCameraDetails)
|
---|
| 342 | {
|
---|
| 343 | // Print camera details
|
---|
| 344 | mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " +
|
---|
| 345 | "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
|
---|
| 346 | }
|
---|
[1849] | 347 | lastTime = thisTime;
|
---|
[1724] | 348 | // Return true to continue rendering
|
---|
| 349 | return true;
|
---|
[1720] | 350 | }
|
---|
| 351 | bool frameStarted(const FrameEvent& evt)
|
---|
| 352 | {
|
---|
| 353 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
| 354 | framecount++;
|
---|
| 355 | return result;
|
---|
| 356 | }
|
---|
| 357 | };
|
---|
| 358 |
|
---|
| 359 | /** Application class */
|
---|
| 360 | class RaytraceDemoApplication : public ExampleApplication
|
---|
| 361 | {
|
---|
| 362 |
|
---|
| 363 | public:
|
---|
| 364 |
|
---|
| 365 |
|
---|
| 366 | protected:
|
---|
| 367 |
|
---|
| 368 | SceneNode* objectNode;
|
---|
| 369 |
|
---|
[1847] | 370 | void createCamera(void)
|
---|
| 371 | {
|
---|
| 372 | // Create the camera
|
---|
| 373 | mCamera = mSceneMgr->createCamera("PlayerCam");
|
---|
| 374 |
|
---|
| 375 | SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("mainCameraNode");
|
---|
| 376 | camNode->attachObject(mCamera);
|
---|
[1860] | 377 | //camNode->setPosition(Vector3(0,1,0));
|
---|
[1847] | 378 | // Position it at 500 in Z direction
|
---|
| 379 | //mCamera->setPosition(Vector3(0,0,500));
|
---|
| 380 | // Look back along -Z
|
---|
| 381 | //mCamera->lookAt(Vector3(0,0,-300));
|
---|
| 382 | mCamera->setNearClipDistance(5);
|
---|
| 383 |
|
---|
| 384 | }
|
---|
[2057] | 385 |
|
---|
| 386 | void loadResources(void)
|
---|
| 387 | {
|
---|
| 388 | // Initialise, parse scripts etc
|
---|
| 389 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
| 390 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
| 391 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
| 392 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
| 393 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap");
|
---|
| 394 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic");
|
---|
| 395 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_MultiBounce_Shared");
|
---|
| 396 | ResourceGroupManager::getSingleton().initialiseResourceGroup(resourceGroupName[currentMaterial]);
|
---|
| 397 | if(currentMaterial == 2)
|
---|
[2095] | 398 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_MultipleCausticRefraction");
|
---|
[2057] | 399 | if(currentMaterial == 5)
|
---|
[2095] | 400 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_MultipleCausticRefraction_MinMax");
|
---|
[2057] | 401 | }
|
---|
[2175] | 402 | Entity* object;
|
---|
[1847] | 403 |
|
---|
[2175] | 404 | void chooseSceneManager()
|
---|
| 405 | {
|
---|
| 406 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
| 407 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
| 408 | }
|
---|
| 409 |
|
---|
[2140] | 410 | void createPostproc()
|
---|
| 411 | {
|
---|
| 412 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 413 | "GTP/PostProc/Glow");
|
---|
| 414 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
| 415 | "GTP/PostProc/Glow", true);
|
---|
| 416 | /*
|
---|
| 417 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 418 | "GTP/PostProc/ToneMap");
|
---|
| 419 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
| 420 | "GTP/PostProc/ToneMap", true); */
|
---|
| 421 | }
|
---|
| 422 |
|
---|
[1720] | 423 | void createScene(void)
|
---|
| 424 | {
|
---|
[2140] | 425 | createPostproc();
|
---|
[1720] | 426 |
|
---|
| 427 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 428 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
| 429 |
|
---|
| 430 | OgreIlluminationManager::getSingleton().setMaxJoinRadius(420);
|
---|
| 431 |
|
---|
| 432 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
| 433 |
|
---|
[1862] | 434 | mCamera->setFOVy(Radian(Degree(80 * mWindow->getHeight() / mWindow->getWidth())));
|
---|
[1720] | 435 | mCamera->setFarClipDistance(200);
|
---|
| 436 | mCamera->setNearClipDistance(0.1);
|
---|
| 437 |
|
---|
[1847] | 438 | SceneNode* cn = mCamera->getParentSceneNode();
|
---|
| 439 |
|
---|
[1720] | 440 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
| 441 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
| 442 | OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
|
---|
| 443 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GameTools/ShadowMapDistance");
|
---|
| 444 | mSceneMgr->setAmbientLight(ColourValue(0.505 * 0.2, 0.897 * 0.2, 0.914 * 0.2));
|
---|
| 445 |
|
---|
[1847] | 446 | capture = new FrameCapture(mWindow);
|
---|
| 447 | if(scene == 1) createScene1();
|
---|
| 448 | if(scene == 2) createScene2();
|
---|
[1862] | 449 | if(scene == 3) createScene3();
|
---|
[1720] | 450 |
|
---|
[1847] | 451 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
| 452 | }
|
---|
[1856] | 453 | void createScene1(void)
|
---|
[1847] | 454 | {
|
---|
| 455 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 456 |
|
---|
[1879] | 457 | mCamera->getParentSceneNode()->translate(1.1,0.8,1.0);
|
---|
| 458 | //mCamera->lookAt(Vector3(0,1.2,0.0));
|
---|
[2140] | 459 |
|
---|
[2057] | 460 | object = mSceneMgr->createEntity("object", objectNames[currentObject]);
|
---|
| 461 |
|
---|
| 462 | object->setMaterialName(materialNames[currentMaterial]);
|
---|
[1850] | 463 | objectNode = rootNode->createChildSceneNode("objectNode");
|
---|
[1720] | 464 | objectNode->attachObject(object);
|
---|
[2057] | 465 |
|
---|
[2140] | 466 | float scale = objectscales[currentObject] * scenescales[scene-1];
|
---|
| 467 | objectNode->scale(scale, scale, scale);
|
---|
[2057] | 468 |
|
---|
[1720] | 469 | objectNode->setPosition(0,1.2,0);
|
---|
| 470 | objectNode->_updateBounds();
|
---|
| 471 |
|
---|
[1850] | 472 | capture->addAnimableNode(objectNode);
|
---|
[1847] | 473 | capture->addAnimableNode(mCamera->getParentSceneNode());
|
---|
[1850] | 474 |
|
---|
[1720] | 475 | Entity* room = mSceneMgr->createEntity("scene", "difflab.mesh");
|
---|
| 476 | //room->setMaterialName("GameTools/Phong");
|
---|
| 477 | SceneNode* roomNode = rootNode->createChildSceneNode();
|
---|
[2140] | 478 | roomNode->attachObject(room);
|
---|
[1720] | 479 | roomNode->_updateBounds();
|
---|
| 480 |
|
---|
| 481 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
[2140] | 482 |
|
---|
[1720] | 483 | Light* redLight1 = mSceneMgr->createLight("RedLight1");
|
---|
| 484 | redLight1->setType(Light::LT_POINT);
|
---|
| 485 | redLight1->setCastShadows(false);
|
---|
| 486 | redLight1->setDiffuseColour(ColourValue(1,0.055, 0.0));
|
---|
| 487 | redLight1->setPowerScale(1.6);
|
---|
| 488 | SceneNode* redLightNode1 = rootNode->createChildSceneNode();
|
---|
| 489 | redLightNode1->setPosition(0.05,2.361,-1.07);
|
---|
| 490 | redLightNode1->attachObject(redLight1);
|
---|
| 491 |
|
---|
| 492 | Light* greenLight1 = mSceneMgr->createLight("GreenLight1");
|
---|
| 493 | greenLight1->setType(Light::LT_POINT);
|
---|
| 494 | greenLight1->setCastShadows(false);
|
---|
| 495 | greenLight1->setDiffuseColour(ColourValue(0.362,0.783, 0.685));
|
---|
| 496 | greenLight1->setPowerScale(2.0);
|
---|
| 497 | SceneNode* greenLightNode1 = rootNode->createChildSceneNode();
|
---|
| 498 | greenLightNode1->setPosition(1.312,1.313,0);
|
---|
| 499 | greenLightNode1->attachObject(greenLight1);
|
---|
| 500 |
|
---|
| 501 | Light* mainBlueLight = mSceneMgr->createLight("MainBlueLight");
|
---|
| 502 | mainBlueLight->setType(Light::LT_SPOTLIGHT);
|
---|
| 503 | mainBlueLight->setCastShadows(true);
|
---|
| 504 | mainBlueLight->setDiffuseColour(ColourValue(0.395,0.766, 1.0));
|
---|
[2140] | 505 | mainBlueLight->setPowerScale(3.0);
|
---|
[1720] | 506 | mainBlueLight->setSpotlightRange(Degree(0),Degree(160));
|
---|
| 507 | mainBlueLight->setAttenuation(2.5, 0, 1, 0);
|
---|
| 508 | SceneNode* mainBlueLightNode = rootNode->createChildSceneNode();
|
---|
| 509 | mainBlueLightNode->setPosition(-0.546,2.095,1.035);
|
---|
| 510 | //mainBlueLightNode->rotate(Vector3::UNIT_X, Degree(161.396));
|
---|
| 511 | //mainBlueLightNode->rotate(Vector3::UNIT_Y, Degree(53.955));
|
---|
| 512 | //mainBlueLightNode->rotate(Vector3::UNIT_Z, Degree(-145.065));
|
---|
| 513 | mainBlueLight->setDirection(-1.5,-2.0,1.0);
|
---|
[1847] | 514 | mainBlueLightNode->attachObject(mainBlueLight);
|
---|
[2140] | 515 | /*
|
---|
| 516 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 517 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
| 518 | mainLight->setSpotlightRange(Degree(0),Degree(160));
|
---|
| 519 | mainLight->setCastShadows(false);
|
---|
| 520 | mainLight->setDiffuseColour(ColourValue(0.995,0.996, 0.80));
|
---|
| 521 | mainLight->setPowerScale(1.0);
|
---|
| 522 | mainLight->setAttenuation(3, 0, 1, 0);
|
---|
| 523 | SceneNode* mainLightNode = rootNode->createChildSceneNode();
|
---|
| 524 | mainLightNode->setPosition(0,2.5,0);
|
---|
| 525 | mainLight->setDirection(0,-1.0,0);
|
---|
| 526 | mainLightNode->attachObject(mainLight);*/
|
---|
| 527 | /*
|
---|
| 528 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
| 529 | bbs->setDefaultDimensions(0.2, 0.2);
|
---|
| 530 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
| 531 | bbs->setMaterialName("Flare");
|
---|
| 532 | mainLightNode->attachObject(bbs);*/
|
---|
[1847] | 533 | }
|
---|
[1720] | 534 |
|
---|
[1847] | 535 | void createScene2(void)
|
---|
| 536 | {
|
---|
| 537 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 538 |
|
---|
[1862] | 539 | mCamera->setPosition(2.3,7.0,2.3);
|
---|
[2057] | 540 | //mCamera->lookAt(Vector3(0,5.75,0.0));
|
---|
[1862] | 541 |
|
---|
[2140] | 542 | object = mSceneMgr->createEntity("object", "teapot.mesh");
|
---|
[1847] | 543 | object->setMaterialName("MetalTeapotMultipleBounce");
|
---|
| 544 | objectNode = rootNode->createChildSceneNode();
|
---|
| 545 | objectNode->attachObject(object);
|
---|
| 546 | //objectNode->scale(0.5,0.5,0.5);
|
---|
[1862] | 547 | //objectNode->scale(0.005,0.005,0.005);
|
---|
| 548 | objectNode->setPosition(0,5.75,0.0);
|
---|
[1847] | 549 | objectNode->_updateBounds();
|
---|
[1720] | 550 |
|
---|
[1862] | 551 | Entity* room = mSceneMgr->createEntity("scene", "terito.mesh");
|
---|
[1847] | 552 | //room->setMaterialName("GameTools/Phong");
|
---|
| 553 | SceneNode* roomNode = rootNode->createChildSceneNode();
|
---|
| 554 | roomNode->attachObject(room);
|
---|
| 555 | roomNode->_updateBounds();
|
---|
| 556 |
|
---|
| 557 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
[1862] | 558 | Light* Light1 = mSceneMgr->createLight("Light1");
|
---|
| 559 | Light1->setType(Light::LT_POINT);
|
---|
| 560 | Light1->setCastShadows(false);
|
---|
| 561 | Light1->setDiffuseColour(ColourValue(1,1, 1));
|
---|
| 562 | Light1->setPowerScale(1.0);
|
---|
| 563 | SceneNode* LightNode1 = rootNode->createChildSceneNode();
|
---|
| 564 | LightNode1->setPosition(1.5,10.3,0);
|
---|
| 565 | LightNode1->attachObject(Light1);
|
---|
| 566 | }
|
---|
[2140] | 567 |
|
---|
[1862] | 568 | void createScene3(void)
|
---|
[2057] | 569 | {
|
---|
[1862] | 570 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 571 |
|
---|
[1863] | 572 | //mCamera->getParentSceneNode()->translate(Vector3(6.564,4.328,0.059));
|
---|
| 573 | //mCamera->setPosition(4.0,4.2,-3.5);
|
---|
[2095] | 574 | //mCamera->getParentSceneNode()->translate(7.0,2.6,-0.5);
|
---|
| 575 | mCamera->setPosition(7.0,2.6,-0.5);
|
---|
| 576 | mCamera->lookAt(Vector3(1.0, 0.0,0.6));
|
---|
[2057] | 577 |
|
---|
| 578 | object = mSceneMgr->createEntity("object", objectNames[currentObject]);
|
---|
[1863] | 579 |
|
---|
[2057] | 580 | object->setMaterialName(materialNames[currentMaterial]);
|
---|
[1862] | 581 | objectNode = rootNode->createChildSceneNode();
|
---|
| 582 | objectNode->attachObject(object);
|
---|
[1863] | 583 |
|
---|
[2140] | 584 | float scale = objectscales[currentObject] * scenescales[scene-1];
|
---|
| 585 | objectNode->scale(scale, scale, scale);
|
---|
| 586 |
|
---|
[1862] | 587 | objectNode->_updateBounds();
|
---|
[1847] | 588 |
|
---|
[1862] | 589 | Entity* room = mSceneMgr->createEntity("scene", "colorcube.mesh");
|
---|
| 590 | //room->setMaterialName("GameTools/Phong");
|
---|
| 591 | SceneNode* roomNode = rootNode->createChildSceneNode();
|
---|
| 592 | roomNode->attachObject(room);
|
---|
[2057] | 593 | roomNode->setScale(2,2,2);
|
---|
| 594 | roomNode->_updateBounds();
|
---|
| 595 |
|
---|
| 596 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
| 597 | Light* Light1 = mSceneMgr->createLight("Light1");
|
---|
| 598 | Light1->setType(Light::LT_SPOTLIGHT);
|
---|
| 599 | Light1->setCastShadows(true);
|
---|
| 600 | Light1->setDiffuseColour(ColourValue(1,1, 1));
|
---|
| 601 | Light1->setPowerScale(1.0);
|
---|
| 602 | SceneNode* LightNode1 = rootNode->createChildSceneNode();
|
---|
| 603 | LightNode1->setPosition(3,3,3);
|
---|
| 604 | Light1->setDirection(-1,-1,-1);
|
---|
| 605 | Light1->setSpotlightRange(Degree(0),Degree(120));
|
---|
| 606 | LightNode1->attachObject(Light1);
|
---|
[2095] | 607 | /*
|
---|
[2057] | 608 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
| 609 | bbs->setDefaultDimensions(0.2, 0.2);
|
---|
| 610 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
| 611 | bbs->setMaterialName("Flare");
|
---|
[2095] | 612 | LightNode1->attachObject(bbs);*/
|
---|
[1720] | 613 | }
|
---|
| 614 |
|
---|
| 615 | void createFrameListener(void)
|
---|
| 616 | {
|
---|
| 617 | // This is where we instantiate our own frame listener
|
---|
[2140] | 618 | mFrameListener= new RaytraceDemoListener(mWindow, mCamera, objectNode, object);
|
---|
[1720] | 619 | mFrameListener->setPriority(1);
|
---|
[1847] | 620 | OgreIlluminationManager::getSingleton().setPriority(3);
|
---|
| 621 | capture->setPriority(2);
|
---|
| 622 | mRoot->addFrameListener(capture);
|
---|
[1720] | 623 | mRoot->addFrameListener(mFrameListener);
|
---|
| 624 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
| 625 |
|
---|
| 626 | }
|
---|
| 627 |
|
---|
| 628 | };
|
---|
| 629 |
|
---|