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