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