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 MoriaDemoFrameListener : public ExampleFrameListener
|
---|
31 | {
|
---|
32 | protected:
|
---|
33 |
|
---|
34 | unsigned long framecount;
|
---|
35 | SceneNode* mainLightNode;
|
---|
36 | Light* light;
|
---|
37 |
|
---|
38 | public:
|
---|
39 | MoriaDemoFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode, Light* l)
|
---|
40 | :ExampleFrameListener(window, maincam)
|
---|
41 |
|
---|
42 | {
|
---|
43 | mainLightNode = lightNode;
|
---|
44 | light = l;
|
---|
45 | framecount = 0;
|
---|
46 | mMoveSpeed /= 50.0;
|
---|
47 | }
|
---|
48 |
|
---|
49 | bool frameStarted(const FrameEvent& evt)
|
---|
50 | {
|
---|
51 | /* light->setDirection(mCamera->getDirection());
|
---|
52 | light->setPosition(mCamera->getPosition());
|
---|
53 | mainLightNode->setPosition(mCamera->getPosition());*/
|
---|
54 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
55 | framecount++;
|
---|
56 |
|
---|
57 | return result;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | };
|
---|
63 |
|
---|
64 | /** Application class */
|
---|
65 | class MoriaDemoApplication : public ExampleApplication
|
---|
66 | {
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | protected:
|
---|
72 | SceneNode* kupolaNode;
|
---|
73 | SceneNode* mainLightNode;
|
---|
74 | Light* mainLight;
|
---|
75 |
|
---|
76 | void loadResources(void)
|
---|
77 | {
|
---|
78 | // Initialise, parse scripts etc
|
---|
79 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
80 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
81 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
82 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
83 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Particles");
|
---|
84 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Moria");
|
---|
85 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap");
|
---|
86 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic");
|
---|
87 | }
|
---|
88 |
|
---|
89 | void createPostproc()
|
---|
90 | {
|
---|
91 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
92 | "GTP/PostProc/Glow");
|
---|
93 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
94 | "GTP/PostProc/Glow", true);
|
---|
95 |
|
---|
96 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
97 | "GTP/PostProc/ToneMap");
|
---|
98 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
99 | "GTP/PostProc/ToneMap", true);
|
---|
100 | }
|
---|
101 |
|
---|
102 | void chooseSceneManager()
|
---|
103 | {
|
---|
104 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
105 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
106 | }
|
---|
107 |
|
---|
108 | void createScene(void) ///TOWERS
|
---|
109 | {
|
---|
110 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
111 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
112 |
|
---|
113 | createPostproc();
|
---|
114 |
|
---|
115 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
116 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
117 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
118 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
119 | OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
|
---|
120 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/Distance_Normalized");//GameTools/ShadowMapDistance
|
---|
121 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
122 |
|
---|
123 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
124 | mCamera->setPosition(-20,3,0);
|
---|
125 | //mCamera->setPosition(0,100,0);
|
---|
126 | //mCamera->lookAt(0,-1,0);
|
---|
127 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
128 | mCamera->setNearClipDistance(0.01);
|
---|
129 | mCamera->setFarClipDistance(1000);
|
---|
130 | // Set ambient light
|
---|
131 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
132 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
133 |
|
---|
134 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
135 |
|
---|
136 |
|
---|
137 | SceneSerializer s(mSceneMgr);
|
---|
138 | DataStreamPtr inputStream;
|
---|
139 | inputStream = ResourceGroupManager::getSingleton().openResource("moria.level"); //towers2.level
|
---|
140 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
141 |
|
---|
142 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/Moria/Smoke_Large");
|
---|
143 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
144 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
145 | pSysNode->attachObject(pSys1);
|
---|
146 | pSysNode->setPosition(-40,-1,-15);
|
---|
147 |
|
---|
148 | /*Entity* object = mSceneMgr->createEntity("object", "head.mesh");
|
---|
149 | object->setMaterialName("GTP/Caustic/Glass");
|
---|
150 | SceneNode* objectNode = rootNode->createChildSceneNode();
|
---|
151 | objectNode->attachObject(object);
|
---|
152 | objectNode->scale(0.1,0.1,0.1);
|
---|
153 | objectNode->rotate(Vector3(0,1,0),Radian(0.2));
|
---|
154 | objectNode->setPosition(-30,2.0,-5);
|
---|
155 | objectNode->_updateBounds();*/
|
---|
156 |
|
---|
157 | //createPlane("p","groundmaterial",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
158 |
|
---|
159 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
160 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
161 | mainLight->setCastShadows(true);
|
---|
162 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
163 | mainLight->setSpecularColour(ColourValue::White);
|
---|
164 | mainLightNode = rootNode->createChildSceneNode();
|
---|
165 |
|
---|
166 | mainLightNode->setPosition(-20,10,0);
|
---|
167 | mainLight->setPosition(-20,10,0);
|
---|
168 | mainLight->setPowerScale(5);
|
---|
169 | mainLight->setDirection(-1,-0.2, -1);
|
---|
170 | mainLightNode->attachObject(mainLight);
|
---|
171 | mainLight->setSpotlightRange(Degree(0),Degree(90));
|
---|
172 | mainLight->setAttenuation(40.0, 0, 1, 0);
|
---|
173 |
|
---|
174 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
175 | }
|
---|
176 |
|
---|
177 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1))
|
---|
178 | {
|
---|
179 | Plane _plane;
|
---|
180 | _plane.normal = Vector3::UNIT_Y;
|
---|
181 | _plane.d = 0;
|
---|
182 |
|
---|
183 |
|
---|
184 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
185 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
186 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
187 |
|
---|
188 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
189 | _entity->setMaterialName(_material);
|
---|
190 |
|
---|
191 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
192 | _node->attachObject(_entity);
|
---|
193 | _node->setPosition(_pos);
|
---|
194 |
|
---|
195 | }
|
---|
196 |
|
---|
197 | void createFrameListener(void)
|
---|
198 | {
|
---|
199 | // This is where we instantiate our own frame listener
|
---|
200 | mFrameListener= new MoriaDemoFrameListener(mWindow,
|
---|
201 | mCamera, mainLightNode, mainLight );
|
---|
202 | mFrameListener->setPriority(2);
|
---|
203 | mRoot->addFrameListener(mFrameListener);
|
---|
204 | OgreIlluminationManager::getSingleton().setPriority(3);
|
---|
205 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
206 | }
|
---|
207 |
|
---|
208 | };
|
---|
209 |
|
---|