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