[1080] | 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 "SceneSerializer.h"
|
---|
| 27 |
|
---|
[2405] | 28 | Light* blueLight;
|
---|
[1080] | 29 |
|
---|
| 30 | // Listener class for frame updates
|
---|
| 31 | class PRMDemoFrameListener : public ExampleFrameListener
|
---|
| 32 | {
|
---|
| 33 | protected:
|
---|
| 34 |
|
---|
| 35 | unsigned long framecount;
|
---|
[2201] | 36 | SceneNode* mainLightNode;
|
---|
| 37 | Light* light;
|
---|
[1080] | 38 |
|
---|
| 39 | public:
|
---|
[2201] | 40 | PRMDemoFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode, Light* l)
|
---|
[1080] | 41 | :ExampleFrameListener(window, maincam)
|
---|
| 42 |
|
---|
| 43 | {
|
---|
[2201] | 44 | mainLightNode = lightNode;
|
---|
| 45 | light = l;
|
---|
[2151] | 46 | framecount = 0;
|
---|
[2163] | 47 | mMoveSpeed /= 50.0;
|
---|
[1080] | 48 | }
|
---|
| 49 |
|
---|
| 50 | bool frameStarted(const FrameEvent& evt)
|
---|
[2201] | 51 | {
|
---|
[2216] | 52 | /* light->setDirection(mCamera->getDirection());
|
---|
[2201] | 53 | light->setPosition(mCamera->getPosition());
|
---|
| 54 | mainLightNode->setPosition(mCamera->getPosition());*/
|
---|
[1080] | 55 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
| 56 | framecount++;
|
---|
[2405] | 57 |
|
---|
| 58 | static float t = 0;
|
---|
| 59 | float dt = evt.timeSinceLastFrame / 4.0;
|
---|
| 60 | t += dt;
|
---|
[2423] | 61 | /*
|
---|
[2411] | 62 | Vector3 pos(30 * sin(t), 1, 30 * cos(t));
|
---|
[2423] | 63 | light->getParentSceneNode()->setPosition(pos);
|
---|
| 64 | Vector3 dir = -pos;
|
---|
[2411] | 65 | dir.normalise();
|
---|
[2423] | 66 | light->setDirection(dir);*/
|
---|
[2201] | 67 |
|
---|
[2411] | 68 |
|
---|
[1080] | 69 | return result;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | /** Application class */
|
---|
| 77 | class PRMDemoApplication : public ExampleApplication
|
---|
| 78 | {
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
[2025] | 82 |
|
---|
[1080] | 83 | protected:
|
---|
| 84 | SceneNode* kupolaNode;
|
---|
| 85 | SceneNode* mainLightNode;
|
---|
[2201] | 86 | Light* mainLight;
|
---|
[2025] | 87 |
|
---|
| 88 | void loadResources(void)
|
---|
| 89 | {
|
---|
| 90 | // Initialise, parse scripts etc
|
---|
| 91 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
| 92 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
[2151] | 93 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
[2025] | 94 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
[2405] | 95 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_PathMap");
|
---|
[2186] | 96 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_PathMapDemo");
|
---|
[2439] | 97 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Demo_Towers");
|
---|
[1080] | 98 | }
|
---|
| 99 |
|
---|
| 100 | void createPostproc()
|
---|
[2025] | 101 | {
|
---|
[1080] | 102 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
[2025] | 103 | "GTP/PostProc/Glow");
|
---|
[1080] | 104 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[2025] | 105 | "GTP/PostProc/Glow", true);
|
---|
[2186] | 106 | /*
|
---|
[2025] | 107 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 108 | "GTP/PostProc/ToneMap");
|
---|
| 109 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[2186] | 110 | "GTP/PostProc/ToneMap", true); */
|
---|
[1080] | 111 | }
|
---|
| 112 |
|
---|
[2151] | 113 | void chooseSceneManager()
|
---|
| 114 | {
|
---|
[2267] | 115 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
| 116 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
[2151] | 117 | }
|
---|
[2188] | 118 |
|
---|
| 119 | /*
|
---|
| 120 | void createScene(void) /// SHADOWACCUM
|
---|
| 121 | {
|
---|
| 122 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
| 123 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
| 124 | //createPostproc();
|
---|
| 125 |
|
---|
| 126 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 127 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
| 128 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/CameraDepth");
|
---|
| 129 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
[2201] | 130 | OgreIlluminationManager::getSingleton().setShadowMapSize(1024);
|
---|
[2188] | 131 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
| 132 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
[2191] | 133 | OgreIlluminationManager::getSingleton().setAreaLigtRadius(2);
|
---|
[2188] | 134 |
|
---|
| 135 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
| 136 | mCamera->setPosition(0,0,0);
|
---|
| 137 | //mCamera->setPosition(0,100,0);
|
---|
| 138 | //mCamera->lookAt(0,-1,0);
|
---|
| 139 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
| 140 | mCamera->setNearClipDistance(0.01);
|
---|
| 141 | mCamera->setFarClipDistance(1000);
|
---|
| 142 | // Set ambient light
|
---|
| 143 | mSceneMgr->setAmbientLight(ColourValue(0,0, 0));
|
---|
| 144 | //mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
| 145 |
|
---|
| 146 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 147 |
|
---|
| 148 | Entity* pillar = mSceneMgr->createEntity("pillar", "pillarShape.mesh");
|
---|
| 149 | SceneNode* pillarNode = rootNode->createChildSceneNode("pillarnode");
|
---|
| 150 | pillarNode->attachObject(pillar);
|
---|
| 151 |
|
---|
| 152 |
|
---|
[2296] | 153 | createPlane("p","GTP/Basic/ShadowReceiver/ShadowAccum",Vector3(0,-1.3,0),Vector2(20,20),Vector2(1,1));
|
---|
[2188] | 154 |
|
---|
| 155 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 156 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
| 157 | mainLight->setCastShadows(true);
|
---|
| 158 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 159 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 160 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 161 |
|
---|
[2201] | 162 | mainLightNode->setPosition(10,10,10);
|
---|
| 163 | mainLight->setPosition(10,10,10);
|
---|
| 164 | mainLight->setPowerScale(10);
|
---|
[2188] | 165 | mainLight->setDirection(-1,-1, -1);
|
---|
| 166 | mainLight->setSpotlightOuterAngle(Radian(Degree(90)));
|
---|
[2201] | 167 | mainLight->setAttenuation(20, 0, 0, 0);
|
---|
[2188] | 168 | mainLightNode->attachObject(mainLight);
|
---|
| 169 |
|
---|
| 170 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
[2201] | 171 | bbs->setDefaultDimensions(6,6);
|
---|
[2188] | 172 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
| 173 | bbs->setMaterialName("Flare");
|
---|
| 174 | mainLightNode->attachObject(bbs);
|
---|
| 175 |
|
---|
| 176 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
| 177 | }*/
|
---|
[2439] | 178 |
|
---|
[2188] | 179 | void createScene(void) ///TOWERS
|
---|
[2186] | 180 | {
|
---|
| 181 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
| 182 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
| 183 |
|
---|
[2439] | 184 | //createPostproc();
|
---|
[1080] | 185 |
|
---|
[2186] | 186 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 187 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
[2296] | 188 | OgreIlluminationManager::getSingleton().setShadowMapSize(700);
|
---|
| 189 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/Depth");
|
---|
[2186] | 190 | OgreIlluminationManager::getSingleton().setFocusingSM(true);
|
---|
[2439] | 191 | OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
|
---|
| 192 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
[2186] | 193 |
|
---|
| 194 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
| 195 | mCamera->setPosition(0,0,0);
|
---|
| 196 | //mCamera->setPosition(0,100,0);
|
---|
| 197 | //mCamera->lookAt(0,-1,0);
|
---|
| 198 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
| 199 | mCamera->setNearClipDistance(0.01);
|
---|
| 200 | mCamera->setFarClipDistance(1000);
|
---|
| 201 | // Set ambient light
|
---|
| 202 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
| 203 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
| 204 |
|
---|
| 205 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | SceneSerializer s(mSceneMgr);
|
---|
| 209 | DataStreamPtr inputStream;
|
---|
| 210 | inputStream = ResourceGroupManager::getSingleton().openResource("towers.level"); //towers2.level
|
---|
| 211 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 212 |
|
---|
| 213 | //createPlane("p","groundmaterial",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
| 214 |
|
---|
| 215 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 216 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
| 217 | mainLight->setCastShadows(true);
|
---|
| 218 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 219 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 220 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 221 |
|
---|
| 222 | mainLightNode->setPosition(1000,1000,1000);
|
---|
| 223 | mainLight->setPosition(1000,1000,1000);
|
---|
| 224 | mainLight->setPowerScale(5);
|
---|
| 225 | mainLight->setDirection(-1,-1, -1);
|
---|
| 226 | mainLightNode->attachObject(mainLight);
|
---|
| 227 |
|
---|
| 228 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[2439] | 229 | }
|
---|
| 230 | /*
|
---|
[2188] | 231 | void createScene(void) ///PATHMAP Hangar
|
---|
[2439] | 232 | {
|
---|
[2260] | 233 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
[2267] | 234 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
[2179] | 235 |
|
---|
[2201] | 236 | //createPostproc();
|
---|
[1080] | 237 |
|
---|
[2436] | 238 | OgreIlluminationManager::getSingleton().joinSharedRuns(false);
|
---|
[1080] | 239 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 240 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
[2405] | 241 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_SPOTLIGHT, "GTP/Basic/Distance_Normalized");
|
---|
| 242 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_POINT, "GTP/Basic/Distance_Normalized");
|
---|
[2216] | 243 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
| 244 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
| 245 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
| 246 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
[1080] | 247 |
|
---|
| 248 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
[2430] | 249 |
|
---|
[2436] | 250 | mCamera->setPosition(32,0.68,11);
|
---|
| 251 | //mCamera->setPosition(50,35,-2);
|
---|
| 252 | //mCamera->lookAt(0,0,0);
|
---|
[2430] | 253 |
|
---|
[1080] | 254 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
[2163] | 255 | mCamera->setNearClipDistance(0.01);
|
---|
| 256 | mCamera->setFarClipDistance(1000);
|
---|
[1080] | 257 | // Set ambient light
|
---|
[2151] | 258 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
[2163] | 259 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
| 260 |
|
---|
[2179] | 261 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
[1132] | 262 |
|
---|
[2163] | 263 |
|
---|
[1080] | 264 | SceneSerializer s(mSceneMgr);
|
---|
| 265 | DataStreamPtr inputStream;
|
---|
[2186] | 266 | inputStream = ResourceGroupManager::getSingleton().openResource("processed.level"); //towers2.level
|
---|
[1080] | 267 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
[2423] | 268 | s.parseEntryPoints("SpacePrmEntryPoints.text");
|
---|
[2179] | 269 |
|
---|
[2296] | 270 | //createPlane("p","GTP/Basic/ShadowReceiver/Depth",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
[2423] | 271 |
|
---|
[2201] | 272 | mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 273 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
[2405] | 274 | mainLight->setCastShadows(true);
|
---|
| 275 | mainLight->setDiffuseColour(ColourValue(1.0,0.5,0.3,1));
|
---|
[1080] | 276 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 277 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 278 |
|
---|
[2334] | 279 | mainLightNode->setPosition(30,1,0.0);
|
---|
[2405] | 280 | //mainLight->setPosition(30,1,0);
|
---|
| 281 | mainLight->setPowerScale(200);
|
---|
[2216] | 282 | mainLight->setDirection(-1, 0, 0);
|
---|
[2201] | 283 | mainLight->setSpotlightOuterAngle(Radian(Degree(90)));
|
---|
[2423] | 284 | mainLight->setSpotlightFalloff(1);
|
---|
[2405] | 285 | mainLight->setAttenuation(200, 0, 0, 1);
|
---|
[1080] | 286 | mainLightNode->attachObject(mainLight);
|
---|
[2439] | 287 |
|
---|
[2405] | 288 | blueLight = mSceneMgr->createLight("BlueLight");
|
---|
[2411] | 289 | blueLight->setType(Light::LT_SPOTLIGHT);
|
---|
[2405] | 290 | blueLight->setCastShadows(true);
|
---|
[2423] | 291 | blueLight->setDiffuseColour(ColourValue(0.3,0.5,1.0,1));
|
---|
[2334] | 292 | blueLight->setSpecularColour(ColourValue::White);
|
---|
| 293 | SceneNode* blueLightNode = rootNode->createChildSceneNode();
|
---|
[1086] | 294 |
|
---|
[2334] | 295 | blueLightNode->setPosition(-30,1,0.0);
|
---|
[2405] | 296 | //blueLight->setPosition(-30,1,0);
|
---|
| 297 | blueLight->setPowerScale(200);
|
---|
[2423] | 298 | blueLight->setDirection(1, 0, 0);
|
---|
| 299 | blueLight->setSpotlightOuterAngle(Radian(Degree(160)));
|
---|
[2411] | 300 | blueLight->setSpotlightFalloff(1);
|
---|
| 301 | blueLight->setAttenuation(2000, 0, 0, 1);
|
---|
[2439] | 302 | blueLightNode->attachObject(blueLight);
|
---|
[2334] | 303 |
|
---|
| 304 |
|
---|
[1086] | 305 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[2334] | 306 | }
|
---|
[2439] | 307 | */
|
---|
[2201] | 308 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1))
|
---|
| 309 | {
|
---|
[1117] | 310 | Plane _plane;
|
---|
| 311 | _plane.normal = Vector3::UNIT_Y;
|
---|
| 312 | _plane.d = 0;
|
---|
[1080] | 313 |
|
---|
[1117] | 314 |
|
---|
| 315 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
| 316 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
| 317 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
| 318 |
|
---|
| 319 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
| 320 | _entity->setMaterialName(_material);
|
---|
| 321 |
|
---|
| 322 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
| 323 | _node->attachObject(_entity);
|
---|
| 324 | _node->setPosition(_pos);
|
---|
| 325 |
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[1080] | 328 | void createFrameListener(void)
|
---|
| 329 | {
|
---|
| 330 | // This is where we instantiate our own frame listener
|
---|
| 331 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
[2201] | 332 | mCamera, mainLightNode, mainLight );
|
---|
[2025] | 333 | mFrameListener->setPriority(1);
|
---|
| 334 | mRoot->addFrameListener(mFrameListener);
|
---|
| 335 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
| 336 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
[1080] | 337 | }
|
---|
| 338 |
|
---|
| 339 | };
|
---|
| 340 |
|
---|