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