[1054] | 1 |
|
---|
| 2 |
|
---|
| 3 |
|
---|
[777] | 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"
|
---|
| 30 |
|
---|
[1096] | 31 | float causize = 10;
|
---|
[875] | 32 | float cauintens = 40;
|
---|
[777] | 33 |
|
---|
| 34 | // Listener class for frame updates
|
---|
| 35 | class RaytraceDemoListener : public ExampleFrameListener
|
---|
| 36 | {
|
---|
| 37 | protected:
|
---|
| 38 | SceneNode* goldSphereNode;
|
---|
| 39 | SceneNode* silverSphereNode;
|
---|
| 40 | SceneNode* copperSphereNode;
|
---|
| 41 | SceneNode* aluSphereNode;
|
---|
| 42 | SceneNode* lightNode;
|
---|
| 43 | unsigned long framecount;
|
---|
| 44 |
|
---|
| 45 | public:
|
---|
| 46 | RaytraceDemoListener(RenderWindow* window, Camera* maincam,SceneNode* lightNode,
|
---|
| 47 | SceneNode* goldSphereNode,
|
---|
| 48 | SceneNode* silverSphereNode,
|
---|
| 49 | SceneNode* copperSphereNode,
|
---|
| 50 | SceneNode* aluSphereNode)
|
---|
| 51 | :ExampleFrameListener(window, maincam)
|
---|
| 52 |
|
---|
| 53 | {
|
---|
| 54 | framecount = 0;
|
---|
| 55 | this->goldSphereNode = goldSphereNode;
|
---|
| 56 | this->silverSphereNode = silverSphereNode;
|
---|
| 57 | this->copperSphereNode = copperSphereNode;
|
---|
| 58 | this->aluSphereNode = aluSphereNode;
|
---|
| 59 | this->lightNode = lightNode;
|
---|
| 60 | }
|
---|
| 61 | bool processUnbufferedKeyInput(const FrameEvent& evt)
|
---|
| 62 | {
|
---|
[1096] | 63 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GameTools/Cauathene_SE_0_clone");
|
---|
[777] | 64 | GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer();
|
---|
| 65 | GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
| 66 |
|
---|
| 67 | if (mInputDevice->isKeyDown(KC_SUBTRACT))
|
---|
| 68 | {
|
---|
[807] | 69 | cauintens -= 0.5;
|
---|
[777] | 70 | cauintens = std::max(cauintens, 1.0f);
|
---|
| 71 | float intensity = pow( cauintens / 100.0f, 2 );
|
---|
| 72 | Fparams->setNamedConstant("CauSpriteIntens", intensity);
|
---|
| 73 | }
|
---|
| 74 | if (mInputDevice->isKeyDown(KC_ADD))
|
---|
| 75 | {
|
---|
[807] | 76 | cauintens += 0.5;
|
---|
[777] | 77 | cauintens = std::min(cauintens, 100.0f);
|
---|
| 78 | float intensity = pow( cauintens / 100.0f, 2 );
|
---|
| 79 | Fparams->setNamedConstant("CauSpriteIntens", intensity);
|
---|
| 80 | }
|
---|
| 81 | if (mInputDevice->isKeyDown(KC_MULTIPLY))
|
---|
| 82 | {
|
---|
[807] | 83 | causize = std::max(causize - 0.1, 0.0);
|
---|
[777] | 84 | Vparams->setNamedConstant("CauSpriteSize", causize);
|
---|
| 85 | }
|
---|
| 86 | if (mInputDevice->isKeyDown(KC_DIVIDE))
|
---|
| 87 | {
|
---|
[807] | 88 | causize = causize + 0.1;
|
---|
[777] | 89 | Vparams->setNamedConstant("CauSpriteSize", causize);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | return ExampleFrameListener::processUnbufferedKeyInput(evt);
|
---|
| 93 | }
|
---|
| 94 | bool frameStarted(const FrameEvent& evt)
|
---|
| 95 | {
|
---|
| 96 | static bool first = true;
|
---|
| 97 | if(first)
|
---|
| 98 | {
|
---|
[1096] | 99 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GameTools/Cauathene_SE_0_clone");
|
---|
[777] | 100 | GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer();
|
---|
| 101 | GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
| 102 | float intensity = pow( cauintens / 100.0f, 2 );
|
---|
| 103 | Fparams->setNamedConstant("CauSpriteIntens", intensity);
|
---|
| 104 | Vparams->setNamedConstant("CauSpriteSize", causize);
|
---|
| 105 | first = false;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | lightNode->setPosition( 100.0 * Vector3(cos(-(float)framecount/500.0),2.0,sin(-(float)framecount/500.0)));
|
---|
| 109 | //lightNode->setDirection(-lightNode->getPosition());
|
---|
| 110 |
|
---|
| 111 | goldSphereNode->setPosition( 100.0 *
|
---|
| 112 | Vector3(
|
---|
| 113 | cos((float)framecount/700.0),
|
---|
| 114 | 1.0,
|
---|
| 115 | sin((float)framecount/700.0)));
|
---|
| 116 | silverSphereNode->setPosition( 100.0 *
|
---|
| 117 | Vector3(
|
---|
| 118 | cos((float)framecount/700.0 + Math::PI / 2.0),
|
---|
| 119 | 1.0,
|
---|
| 120 | sin((float)framecount/700.0 + Math::PI / 2.0)));
|
---|
| 121 | copperSphereNode->setPosition( 100.0 *
|
---|
| 122 | Vector3(
|
---|
| 123 | cos((float)framecount/700.0 + Math::PI ),
|
---|
| 124 | 1.0,
|
---|
| 125 | sin((float)framecount/700.0 + Math::PI)));
|
---|
| 126 | aluSphereNode->setPosition( 100.0 *
|
---|
| 127 | Vector3(
|
---|
| 128 | cos((float)framecount/700.0 + 3 * Math::PI / 2.0),
|
---|
| 129 | 1.0,
|
---|
| 130 | sin((float)framecount/700.0+ 3 * Math::PI / 2.0)));
|
---|
| 131 |
|
---|
| 132 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
| 133 | framecount++;
|
---|
[1054] | 134 | return result;
|
---|
[777] | 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | };
|
---|
| 140 |
|
---|
| 141 | /** Application class */
|
---|
| 142 | class RaytraceDemoApplication : public ExampleApplication
|
---|
| 143 | {
|
---|
| 144 |
|
---|
| 145 | public:
|
---|
| 146 | virtual void go(void)
|
---|
| 147 | {
|
---|
| 148 | if (!setup())
|
---|
| 149 | return;
|
---|
| 150 |
|
---|
| 151 | renderScene();
|
---|
| 152 |
|
---|
| 153 | // clean up
|
---|
| 154 | destroyScene();
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[875] | 157 |
|
---|
[777] | 158 | protected:
|
---|
| 159 | SceneNode* kupolaNode;
|
---|
| 160 | SceneNode* mainLightNode;
|
---|
| 161 | SceneNode* goldSphereNode;
|
---|
| 162 | SceneNode* silverSphereNode;
|
---|
| 163 | SceneNode* copperSphereNode;
|
---|
| 164 | SceneNode* aluSphereNode;
|
---|
| 165 |
|
---|
[875] | 166 | void renderScene(){
|
---|
[777] | 167 |
|
---|
| 168 | mWindow->resetStatistics();
|
---|
| 169 | while(true){
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 173 | // Pump events on Win32
|
---|
| 174 | MSG msg;
|
---|
| 175 | while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
|
---|
| 176 | {
|
---|
| 177 | TranslateMessage( &msg );
|
---|
| 178 | DispatchMessage( &msg );
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | #endif
|
---|
| 182 |
|
---|
| 183 | if(!mRoot->_fireFrameStarted()){
|
---|
| 184 | break;
|
---|
| 185 | }
|
---|
| 186 | unsigned long framenum = mRoot->getCurrentFrameNumber();
|
---|
| 187 |
|
---|
| 188 | OgreIlluminationManager::getSingleton().update(framenum, mWindow);
|
---|
| 189 |
|
---|
[875] | 190 | //mRoot->renderOneFrame();
|
---|
| 191 | mRoot->_updateAllRenderTargets();
|
---|
| 192 |
|
---|
[777] | 193 | mRoot->_fireFrameEnded();
|
---|
| 194 |
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | void createPostproc()
|
---|
| 199 | {
|
---|
[788] | 200 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
[777] | 201 | "GameTools/Glow");
|
---|
| 202 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[788] | 203 | "GameTools/Glow", true);
|
---|
[777] | 204 | /*
|
---|
| 205 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 206 | "GameTools/ToneMap");
|
---|
| 207 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
| 208 | "GameTools/ToneMap", true);*/
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | void createScene(void)
|
---|
| 213 | {
|
---|
| 214 |
|
---|
| 215 | createPostproc();
|
---|
| 216 |
|
---|
| 217 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 218 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
| 219 |
|
---|
[1096] | 220 | OgreIlluminationManager::getSingleton().setMaxJoinRadius(420);
|
---|
[777] | 221 |
|
---|
| 222 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
[1334] | 223 |
|
---|
[777] | 224 | mCamera->setPosition(0,100,240);
|
---|
| 225 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
| 226 | //mCamera->setFarClipDistance(1000);
|
---|
| 227 | // Set ambient light
|
---|
| 228 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
| 229 |
|
---|
| 230 | // Skybox
|
---|
| 231 | mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
| 232 |
|
---|
| 233 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 234 |
|
---|
| 235 |
|
---|
| 236 | //init objects
|
---|
| 237 | Entity* kupola = mSceneMgr->createEntity("kupola", "kupola.mesh");
|
---|
| 238 | Entity* athene = mSceneMgr->createEntity("athene", "head.mesh");
|
---|
| 239 | Entity* goldSphere = mSceneMgr->createEntity("goldSphere", "head.mesh");
|
---|
| 240 | Entity* silverSphere = mSceneMgr->createEntity("silverSphere", "head.mesh");
|
---|
| 241 | Entity* copperSphere = mSceneMgr->createEntity("copperSphere", "head.mesh");
|
---|
| 242 | Entity* aluSphere = mSceneMgr->createEntity("aluSphere", "head.mesh");
|
---|
| 243 |
|
---|
[807] | 244 | kupola->setCastShadows(false);
|
---|
[777] | 245 | //lod
|
---|
| 246 | //MeshPtr amesh = athene->getMesh();
|
---|
| 247 | //Mesh::LodDistanceList distances;
|
---|
| 248 | //distances.push_back(1);
|
---|
| 249 | //distances.push_back(2);
|
---|
[807] | 250 | //distances.push_back(3);
|
---|
| 251 | //distances.push_back(4);
|
---|
[777] | 252 | ////distances.push_back(5);
|
---|
| 253 | //amesh->generateLodLevels(distances,ProgressiveMesh::VertexReductionQuota::VRQ_PROPORTIONAL,0.6);
|
---|
| 254 | //athene->setMeshLodBias(50000.0,0);
|
---|
| 255 | //tangents
|
---|
| 256 | //amesh->buildTangentVectors(0,1);
|
---|
| 257 | MeshPtr kmesh = kupola->getMesh();
|
---|
| 258 | kmesh->buildTangentVectors(0,1);
|
---|
| 259 |
|
---|
| 260 | //init nodes
|
---|
| 261 | kupolaNode = rootNode->createChildSceneNode( "kupola" );
|
---|
| 262 | kupolaNode->rotate(Vector3(0,1,0),Radian(Degree(90)));
|
---|
| 263 | kupolaNode->attachObject( kupola );
|
---|
| 264 | kupolaNode->scale(25,21,25);
|
---|
[807] | 265 | //kupolaNode->scale(2,2,2);
|
---|
| 266 | //kupolaNode->setPosition(0,100,0);
|
---|
[777] | 267 | SceneNode* atheneNode = rootNode->createChildSceneNode("athene");
|
---|
| 268 | atheneNode->attachObject(athene);
|
---|
| 269 | //atheneNode->setScale(3.5,5.5,5.5);
|
---|
| 270 | atheneNode->setScale(4,4,4);
|
---|
| 271 | //atheneNode->setScale(0.5,0.5,0.5);
|
---|
| 272 | AxisAlignedBox bbox = athene->getBoundingBox();
|
---|
| 273 | atheneNode->setPosition(0, 100,0);
|
---|
| 274 |
|
---|
| 275 |
|
---|
| 276 | goldSphereNode = rootNode->createChildSceneNode( "goldSphere" );
|
---|
| 277 | //goldSphereNode->scale(0.3,0.3,0.3);
|
---|
| 278 | goldSphereNode->scale(2,2,2);
|
---|
| 279 | silverSphereNode = rootNode->createChildSceneNode( "silverSphere" );
|
---|
| 280 | //silverSphereNode->scale(0.3,0.3,0.3);
|
---|
| 281 | silverSphereNode->scale(2,2,2);
|
---|
| 282 | copperSphereNode = rootNode->createChildSceneNode( "copperSphere" );
|
---|
| 283 | //copperSphereNode->scale(0.3,0.3,0.3);
|
---|
| 284 | copperSphereNode->scale(2,2,2);
|
---|
| 285 | aluSphereNode = rootNode->createChildSceneNode( "aluSphere" );
|
---|
| 286 | //aluSphereNode->scale(0.3,0.3,0.3);
|
---|
| 287 | aluSphereNode->scale(2,2,2);
|
---|
| 288 |
|
---|
| 289 | goldSphereNode->attachObject(goldSphere);
|
---|
| 290 | silverSphereNode->attachObject(silverSphere);
|
---|
| 291 | aluSphereNode->attachObject(aluSphere);
|
---|
| 292 | copperSphereNode->attachObject(copperSphere);
|
---|
| 293 |
|
---|
| 294 | goldSphereNode->_updateBounds();
|
---|
| 295 | silverSphereNode->_updateBounds();
|
---|
| 296 | aluSphereNode->_updateBounds();
|
---|
| 297 | copperSphereNode->_updateBounds();
|
---|
| 298 |
|
---|
| 299 | kupolaNode->_updateBounds();
|
---|
[1054] | 300 | atheneNode->_updateBounds();
|
---|
[777] | 301 |
|
---|
| 302 | //Init lights
|
---|
| 303 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 304 | mainLight->setType(Light::LT_POINT);
|
---|
| 305 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 306 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 307 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 308 | mainLightNode->setPosition(0,0,0);
|
---|
| 309 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
[835] | 310 | mainLightNode->attachObject(mainLight);
|
---|
[777] | 311 |
|
---|
[835] | 312 | aluSphere->setMaterialName("EnvMetals/Alu");
|
---|
| 313 | copperSphere->setMaterialName("EnvMetals/Copper");
|
---|
[1054] | 314 |
|
---|
| 315 | {
|
---|
| 316 | Material* oldmat = (Material*) MaterialManager::getSingleton().getByName("EnvMetals/Gold").getPointer();
|
---|
| 317 | Material* newmat = oldmat->clone("gold1").getPointer();
|
---|
| 318 | Material* newmat2 = oldmat->clone("gold2").getPointer();
|
---|
[777] | 319 |
|
---|
[1054] | 320 | goldSphere->setMaterialName(newmat->getName());
|
---|
| 321 | silverSphere->setMaterialName(newmat2->getName());
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[1096] | 324 | athene->setMaterialName("GameTools/CausticGlass");
|
---|
[1054] | 325 | //athene->setMaterialName("GameTools/CubeMap/Diffuse");
|
---|
| 326 |
|
---|
[835] | 327 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[777] | 328 |
|
---|
| 329 |
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | void createFrameListener(void)
|
---|
| 333 | {
|
---|
| 334 | // This is where we instantiate our own frame listener
|
---|
| 335 | mFrameListener= new RaytraceDemoListener(mWindow,
|
---|
| 336 | mCamera,
|
---|
| 337 | mainLightNode,
|
---|
| 338 | goldSphereNode,
|
---|
| 339 | silverSphereNode,
|
---|
| 340 | copperSphereNode,
|
---|
| 341 | aluSphereNode);
|
---|
| 342 | mRoot->addFrameListener(mFrameListener);
|
---|
[875] | 343 | //mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
[777] | 344 |
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | };
|
---|
| 348 |
|
---|