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 | }
|
---|
76 |
|
---|
77 | void createPostproc()
|
---|
78 | {
|
---|
79 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
80 | "GTP/PostProc/Glow");
|
---|
81 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
82 | "GTP/PostProc/Glow", true);
|
---|
83 |
|
---|
84 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
85 | "GTP/PostProc/ToneMap");
|
---|
86 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
87 | "GTP/PostProc/ToneMap", true);
|
---|
88 | }
|
---|
89 |
|
---|
90 | void chooseSceneManager()
|
---|
91 | {
|
---|
92 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
93 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
94 | }
|
---|
95 |
|
---|
96 | void createScene(void)
|
---|
97 | {
|
---|
98 | createPostproc();
|
---|
99 |
|
---|
100 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
101 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
102 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
103 |
|
---|
104 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
105 | mCamera->setPosition(0,0,0);
|
---|
106 | //mCamera->setPosition(0,100,0);
|
---|
107 | //mCamera->lookAt(0,-1,0);
|
---|
108 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
109 | mCamera->setNearClipDistance(0.01);
|
---|
110 | mCamera->setFarClipDistance(1000);
|
---|
111 | // Set ambient light
|
---|
112 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
113 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
114 |
|
---|
115 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
116 |
|
---|
117 |
|
---|
118 | SceneSerializer s(mSceneMgr);
|
---|
119 | DataStreamPtr inputStream;
|
---|
120 | inputStream = ResourceGroupManager::getSingleton().openResource("towers2.level");
|
---|
121 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
122 |
|
---|
123 | /* Entity* tower = mSceneMgr->createEntity("tower","tower.mesh");
|
---|
124 | SceneNode* tNode = rootNode->createChildSceneNode("tower");
|
---|
125 | tNode->setScale(10,10,10);
|
---|
126 | tNode->attachObject(tower);
|
---|
127 |
|
---|
128 | Entity* tower2 = mSceneMgr->createEntity("tower2","tower.mesh");
|
---|
129 | tower2->setMaterialName("towermaterialBump");
|
---|
130 | SceneNode* tNode2 = rootNode->createChildSceneNode("tower2");
|
---|
131 | tNode2->setScale(10,10,10);
|
---|
132 | tNode2->setPosition(0,0,100);
|
---|
133 | tNode2->attachObject(tower2);*/
|
---|
134 |
|
---|
135 | /* Entity* tower3 = mSceneMgr->createEntity("tower3","tower.mesh");
|
---|
136 | tower3->setMaterialName("towermaterialNoBump");
|
---|
137 | SceneNode* tNode3 = rootNode->createChildSceneNode("tower3");
|
---|
138 | tNode3->setPosition(0,0,-50);
|
---|
139 | tNode3->setScale(10,10,10);
|
---|
140 | tNode3->attachObject(tower3);*/
|
---|
141 |
|
---|
142 | /* Entity* lepcso = mSceneMgr->createEntity("lepcso","stairs.mesh");
|
---|
143 | SceneNode* lNode = rootNode->createChildSceneNode("l");
|
---|
144 | lNode->attachObject(lepcso);*/
|
---|
145 |
|
---|
146 | //createPlane("p","lambert1",Vector3(0,-20,0),Vector2(100,100));
|
---|
147 |
|
---|
148 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
149 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
150 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
151 | mainLight->setSpecularColour(ColourValue::White);
|
---|
152 | mainLightNode = rootNode->createChildSceneNode();
|
---|
153 |
|
---|
154 | mainLightNode->setPosition(10,10,0);
|
---|
155 | mainLight->setPosition(10,10,0);
|
---|
156 | mainLight->setPowerScale(5);
|
---|
157 | mainLight->setDirection(-1,-1, -1);
|
---|
158 | mainLightNode->attachObject(mainLight);
|
---|
159 |
|
---|
160 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
161 | }
|
---|
162 |
|
---|
163 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
|
---|
164 | Plane _plane;
|
---|
165 | _plane.normal = Vector3::UNIT_Y;
|
---|
166 | _plane.d = 0;
|
---|
167 |
|
---|
168 |
|
---|
169 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
170 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
171 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
172 |
|
---|
173 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
174 | _entity->setMaterialName(_material);
|
---|
175 |
|
---|
176 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
177 | _node->attachObject(_entity);
|
---|
178 | _node->setPosition(_pos);
|
---|
179 |
|
---|
180 | }
|
---|
181 |
|
---|
182 | void createFrameListener(void)
|
---|
183 | {
|
---|
184 | // This is where we instantiate our own frame listener
|
---|
185 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
186 | mCamera );
|
---|
187 | mFrameListener->setPriority(1);
|
---|
188 | mRoot->addFrameListener(mFrameListener);
|
---|
189 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
190 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
191 | }
|
---|
192 |
|
---|
193 | };
|
---|
194 |
|
---|