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