[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");
|
---|
[1080] | 97 | }
|
---|
| 98 |
|
---|
| 99 | void createPostproc()
|
---|
[2025] | 100 | {
|
---|
[1080] | 101 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
[2025] | 102 | "GTP/PostProc/Glow");
|
---|
[1080] | 103 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[2025] | 104 | "GTP/PostProc/Glow", true);
|
---|
[2186] | 105 | /*
|
---|
[2025] | 106 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
| 107 | "GTP/PostProc/ToneMap");
|
---|
| 108 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
[2186] | 109 | "GTP/PostProc/ToneMap", true); */
|
---|
[1080] | 110 | }
|
---|
| 111 |
|
---|
[2151] | 112 | void chooseSceneManager()
|
---|
| 113 | {
|
---|
[2267] | 114 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
| 115 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
[2151] | 116 | }
|
---|
[2188] | 117 |
|
---|
| 118 | /*
|
---|
| 119 | void createScene(void) /// SHADOWACCUM
|
---|
| 120 | {
|
---|
| 121 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
| 122 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
| 123 | //createPostproc();
|
---|
| 124 |
|
---|
| 125 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 126 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
| 127 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/CameraDepth");
|
---|
| 128 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
[2201] | 129 | OgreIlluminationManager::getSingleton().setShadowMapSize(1024);
|
---|
[2188] | 130 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
| 131 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
[2191] | 132 | OgreIlluminationManager::getSingleton().setAreaLigtRadius(2);
|
---|
[2188] | 133 |
|
---|
| 134 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
| 135 | mCamera->setPosition(0,0,0);
|
---|
| 136 | //mCamera->setPosition(0,100,0);
|
---|
| 137 | //mCamera->lookAt(0,-1,0);
|
---|
| 138 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
| 139 | mCamera->setNearClipDistance(0.01);
|
---|
| 140 | mCamera->setFarClipDistance(1000);
|
---|
| 141 | // Set ambient light
|
---|
| 142 | mSceneMgr->setAmbientLight(ColourValue(0,0, 0));
|
---|
| 143 | //mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
| 144 |
|
---|
| 145 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 146 |
|
---|
| 147 | Entity* pillar = mSceneMgr->createEntity("pillar", "pillarShape.mesh");
|
---|
| 148 | SceneNode* pillarNode = rootNode->createChildSceneNode("pillarnode");
|
---|
| 149 | pillarNode->attachObject(pillar);
|
---|
| 150 |
|
---|
| 151 |
|
---|
[2296] | 152 | createPlane("p","GTP/Basic/ShadowReceiver/ShadowAccum",Vector3(0,-1.3,0),Vector2(20,20),Vector2(1,1));
|
---|
[2188] | 153 |
|
---|
| 154 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 155 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
| 156 | mainLight->setCastShadows(true);
|
---|
| 157 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 158 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 159 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 160 |
|
---|
[2201] | 161 | mainLightNode->setPosition(10,10,10);
|
---|
| 162 | mainLight->setPosition(10,10,10);
|
---|
| 163 | mainLight->setPowerScale(10);
|
---|
[2188] | 164 | mainLight->setDirection(-1,-1, -1);
|
---|
| 165 | mainLight->setSpotlightOuterAngle(Radian(Degree(90)));
|
---|
[2201] | 166 | mainLight->setAttenuation(20, 0, 0, 0);
|
---|
[2188] | 167 | mainLightNode->attachObject(mainLight);
|
---|
| 168 |
|
---|
| 169 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
[2201] | 170 | bbs->setDefaultDimensions(6,6);
|
---|
[2188] | 171 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
| 172 | bbs->setMaterialName("Flare");
|
---|
| 173 | mainLightNode->attachObject(bbs);
|
---|
| 174 |
|
---|
| 175 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
| 176 | }*/
|
---|
[2334] | 177 | /*
|
---|
[2188] | 178 | void createScene(void) ///TOWERS
|
---|
[2186] | 179 | {
|
---|
| 180 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
| 181 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
| 182 |
|
---|
| 183 | createPostproc();
|
---|
[1080] | 184 |
|
---|
[2186] | 185 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 186 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
[2296] | 187 | OgreIlluminationManager::getSingleton().setShadowMapSize(700);
|
---|
| 188 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/Depth");
|
---|
[2186] | 189 | OgreIlluminationManager::getSingleton().setFocusingSM(true);
|
---|
[2296] | 190 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
[2186] | 191 | OgreIlluminationManager::getSingleton().setUseLISPSM(true);
|
---|
| 192 |
|
---|
| 193 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
| 194 | mCamera->setPosition(0,0,0);
|
---|
| 195 | //mCamera->setPosition(0,100,0);
|
---|
| 196 | //mCamera->lookAt(0,-1,0);
|
---|
| 197 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
| 198 | mCamera->setNearClipDistance(0.01);
|
---|
| 199 | mCamera->setFarClipDistance(1000);
|
---|
| 200 | // Set ambient light
|
---|
| 201 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
| 202 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
| 203 |
|
---|
| 204 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
| 205 |
|
---|
| 206 |
|
---|
| 207 | SceneSerializer s(mSceneMgr);
|
---|
| 208 | DataStreamPtr inputStream;
|
---|
| 209 | inputStream = ResourceGroupManager::getSingleton().openResource("towers.level"); //towers2.level
|
---|
| 210 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 211 |
|
---|
| 212 | //createPlane("p","groundmaterial",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
| 213 |
|
---|
| 214 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 215 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
| 216 | mainLight->setCastShadows(true);
|
---|
| 217 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
| 218 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 219 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 220 |
|
---|
| 221 | mainLightNode->setPosition(1000,1000,1000);
|
---|
| 222 | mainLight->setPosition(1000,1000,1000);
|
---|
| 223 | mainLight->setPowerScale(5);
|
---|
| 224 | mainLight->setDirection(-1,-1, -1);
|
---|
| 225 | mainLightNode->attachObject(mainLight);
|
---|
| 226 |
|
---|
| 227 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[2334] | 228 | }*/
|
---|
[2201] | 229 |
|
---|
[2188] | 230 | void createScene(void) ///PATHMAP Hangar
|
---|
[1080] | 231 | {
|
---|
[2260] | 232 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
[2267] | 233 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
[2179] | 234 |
|
---|
[2201] | 235 | //createPostproc();
|
---|
[1080] | 236 |
|
---|
| 237 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
| 238 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
[2405] | 239 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_SPOTLIGHT, "GTP/Basic/Distance_Normalized");
|
---|
| 240 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_POINT, "GTP/Basic/Distance_Normalized");
|
---|
[2216] | 241 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
| 242 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
| 243 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
| 244 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
[1080] | 245 |
|
---|
| 246 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
[2423] | 247 | mCamera->setPosition(32,0.68,11);
|
---|
| 248 | //mCamera->setPosition(50,35,-2);
|
---|
| 249 | //mCamera->lookAt(0,0,0);
|
---|
[1132] | 250 | //mCamera->setPosition(0,100,0);
|
---|
[1127] | 251 | //mCamera->lookAt(0,-1,0);
|
---|
[1080] | 252 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
[2163] | 253 | mCamera->setNearClipDistance(0.01);
|
---|
| 254 | mCamera->setFarClipDistance(1000);
|
---|
[1080] | 255 | // Set ambient light
|
---|
[2151] | 256 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
[2163] | 257 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
| 258 |
|
---|
[2179] | 259 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
[1132] | 260 |
|
---|
[2163] | 261 |
|
---|
[1080] | 262 | SceneSerializer s(mSceneMgr);
|
---|
| 263 | DataStreamPtr inputStream;
|
---|
[2186] | 264 | inputStream = ResourceGroupManager::getSingleton().openResource("processed.level"); //towers2.level
|
---|
[1080] | 265 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
[2423] | 266 | s.parseEntryPoints("SpacePrmEntryPoints.text");
|
---|
[2179] | 267 |
|
---|
[2296] | 268 | //createPlane("p","GTP/Basic/ShadowReceiver/Depth",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
[2423] | 269 |
|
---|
[2201] | 270 | mainLight = mSceneMgr->createLight("MainLight");
|
---|
| 271 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
[2405] | 272 | mainLight->setCastShadows(true);
|
---|
| 273 | mainLight->setDiffuseColour(ColourValue(1.0,0.5,0.3,1));
|
---|
[1080] | 274 | mainLight->setSpecularColour(ColourValue::White);
|
---|
| 275 | mainLightNode = rootNode->createChildSceneNode();
|
---|
| 276 |
|
---|
[2334] | 277 | mainLightNode->setPosition(30,1,0.0);
|
---|
[2405] | 278 | //mainLight->setPosition(30,1,0);
|
---|
| 279 | mainLight->setPowerScale(200);
|
---|
[2216] | 280 | mainLight->setDirection(-1, 0, 0);
|
---|
[2201] | 281 | mainLight->setSpotlightOuterAngle(Radian(Degree(90)));
|
---|
[2423] | 282 | mainLight->setSpotlightFalloff(1);
|
---|
[2405] | 283 | mainLight->setAttenuation(200, 0, 0, 1);
|
---|
[1080] | 284 | mainLightNode->attachObject(mainLight);
|
---|
[2423] | 285 | /*
|
---|
[2405] | 286 | blueLight = mSceneMgr->createLight("BlueLight");
|
---|
[2411] | 287 | blueLight->setType(Light::LT_SPOTLIGHT);
|
---|
[2405] | 288 | blueLight->setCastShadows(true);
|
---|
[2423] | 289 | blueLight->setDiffuseColour(ColourValue(0.3,0.5,1.0,1));
|
---|
[2334] | 290 | blueLight->setSpecularColour(ColourValue::White);
|
---|
| 291 | SceneNode* blueLightNode = rootNode->createChildSceneNode();
|
---|
[1086] | 292 |
|
---|
[2334] | 293 | blueLightNode->setPosition(-30,1,0.0);
|
---|
[2405] | 294 | //blueLight->setPosition(-30,1,0);
|
---|
| 295 | blueLight->setPowerScale(200);
|
---|
[2423] | 296 | blueLight->setDirection(1, 0, 0);
|
---|
| 297 | blueLight->setSpotlightOuterAngle(Radian(Degree(160)));
|
---|
[2411] | 298 | blueLight->setSpotlightFalloff(1);
|
---|
| 299 | blueLight->setAttenuation(2000, 0, 0, 1);
|
---|
[2423] | 300 | blueLightNode->attachObject(blueLight); */
|
---|
[2334] | 301 |
|
---|
| 302 |
|
---|
[1086] | 303 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
[2334] | 304 | }
|
---|
[2201] | 305 |
|
---|
| 306 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1))
|
---|
| 307 | {
|
---|
[1117] | 308 | Plane _plane;
|
---|
| 309 | _plane.normal = Vector3::UNIT_Y;
|
---|
| 310 | _plane.d = 0;
|
---|
[1080] | 311 |
|
---|
[1117] | 312 |
|
---|
| 313 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
| 314 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
| 315 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
| 316 |
|
---|
| 317 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
| 318 | _entity->setMaterialName(_material);
|
---|
| 319 |
|
---|
| 320 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
| 321 | _node->attachObject(_entity);
|
---|
| 322 | _node->setPosition(_pos);
|
---|
| 323 |
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[1080] | 326 | void createFrameListener(void)
|
---|
| 327 | {
|
---|
| 328 | // This is where we instantiate our own frame listener
|
---|
| 329 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
[2201] | 330 | mCamera, mainLightNode, mainLight );
|
---|
[2025] | 331 | mFrameListener->setPriority(1);
|
---|
| 332 | mRoot->addFrameListener(mFrameListener);
|
---|
| 333 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
| 334 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
[1080] | 335 | }
|
---|
| 336 |
|
---|
| 337 | };
|
---|
| 338 |
|
---|