Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Scenes/MainScene/MainScene.cpp

Diff revisions: vs.
  @@ -41,7 +41,7 @@
41 41 }
42 42
43 43 void MainScene::renderEnvironment(bool waterReflection){
44 - const vec3<F32>& eyePos = renderState()->getCamera()->getEye();
44 + const vec3<F32>& eyePos = renderState().getCamera().getEye();
45 45
46 46 bool underwater = _water->isPointUnderWater(eyePos);
47 47
  @@ -52,13 +52,9 @@
52 52 }
53 53
54 54 if(waterReflection){
55 - F32 waterLevel = 2.0f*state()->getWaterLevel();
56 - renderState()->getCamera()->RenderLookAt(false,true,waterLevel);
57 - getSkySGN(0)->getNode<Sky>()->setInvertPlane(waterLevel);
55 + renderState().getCamera().renderLookAtReflected(_water->getReflectionPlane());
58 56 }
59 57
60 - getSkySGN(0)->getNode<Sky>()->setInverted(waterReflection);
61 -
62 58 for_each(Terrain* ter, _visibleTerrains){
63 59 ter->toggleReflection(waterReflection);
64 60 }
  @@ -67,48 +63,48 @@
67 63
68 64 void MainScene::processInput(){
69 65 bool update = false;
70 - Camera* cam = renderState()->getCamera();
71 - if(state()->_angleLR){
72 - cam->RotateX((state()->_angleLR)/_LRSpeedFactor);
66 + Camera& cam = renderState().getCamera();
67 + if(state()._angleLR){
68 + cam.rotateYaw(state()._angleLR);
73 69 update = true;
74 70 }
75 - if(state()->_angleUD){
76 - cam->RotateY((state()->_angleUD)/_LRSpeedFactor);
71 + if(state()._angleUD){
72 + cam.rotatePitch(state()._angleUD);
77 73 update = true;
78 74 }
79 75
80 - if(state()->_moveFB || state()->_moveLR){
81 - if(state()->_moveFB) cam->MoveForward((state()->_moveFB) / _FBSpeedFactor);
82 - if(state()->_moveLR) cam->MoveStrafe((state()->_moveLR) / _FBSpeedFactor);
76 + if(state()._moveFB || state()._moveLR){
77 + if(state()._moveFB) cam.moveForward(state()._moveFB);
78 + if(state()._moveLR) cam.moveStrafe(state()._moveLR);
83 79 update = true;
84 80 }
85 81
86 82 if(update){
87 83 if(!_freeflyCamera){
88 84 F32 terrainHeight = 0.0f;
89 - vec3<F32> eyePosition = cam->getEye();
85 + vec3<F32> eyePosition = cam.getEye();
90 86 for_each(Terrain* ter, _visibleTerrains){
91 87 terrainHeight = ter->getPositionFromGlobal(eyePosition.x,eyePosition.z).y;
92 88 if(!IS_ZERO(terrainHeight)){
93 89 eyePosition.y = terrainHeight + 0.45f;
94 - cam->setEye(eyePosition);
90 + cam.setEye(eyePosition);
95 91 break;
96 92 }
97 93 }
98 94 GUI::getInstance().modifyText("camPosition","[ X: %5.2f | Y: %5.2f | Z: %5.2f ] [Pitch: %5.2f | Yaw: %5.2f] [TerHght: %5.2f ]",
99 - cam->getEye().x,
100 - cam->getEye().y,
101 - cam->getEye().z,
102 - DEGREES(cam->getAngleX()),
103 - DEGREES(cam->getAngleY()),
95 + cam.getEye().x,
96 + cam.getEye().y,
97 + cam.getEye().z,
98 + cam.getEuler().pitch,
99 + cam.getEuler().yaw,
104 100 terrainHeight);
105 101 }else{
106 102 GUI::getInstance().modifyText("camPosition","[ X: %5.2f | Y: %5.2f | Z: %5.2f ] [Pitch: %5.2f | Yaw: %5.2f]",
107 - cam->getEye().x,
108 - cam->getEye().y,
109 - cam->getEye().z,
110 - DEGREES(cam->getAngleX()),
111 - DEGREES(cam->getAngleY()));
103 + cam.getEye().x,
104 + cam.getEye().y,
105 + cam.getEye().z,
106 + cam.getEuler().pitch,
107 + cam.getEuler().yaw);
112 108 }
113 109 update = false;
114 110 }
  @@ -130,7 +126,7 @@
130 126
131 127 if (timeSec - _taskTimers[1] >= FpsDisplay){
132 128 GUI::getInstance().modifyText("fpsDisplay", "FPS: %3.0f. FrameTime: %3.1f", Framerate::getInstance().getFps(), Framerate::getInstance().getFrameTime());
133 - GUI::getInstance().modifyText("underwater","Underwater [ %s ] | WaterLevel [%f] ]", _paramHandler.getParam<bool>("scene.camera.underwater") ? "true" : "false", state()->getWaterLevel());
129 + GUI::getInstance().modifyText("underwater","Underwater [ %s ] | WaterLevel [%f] ]", _paramHandler.getParam<bool>("scene.camera.underwater") ? "true" : "false", state().getWaterLevel());
134 130 GUI::getInstance().modifyText("RenderBinCount", "Number of items in Render Bin: %d", GFX_RENDER_BIN_SIZE);
135 131 _taskTimers[1] += FpsDisplay;
136 132 }
  @@ -141,14 +137,13 @@
141 137 }
142 138 }
143 139
144 - bool MainScene::load(const std::string& name){
145 - _mousePressed = false;
140 + bool MainScene::load(const std::string& name, CameraManager* const cameraMgr){
146 141 bool computeWaterHeight = false;
147 142
148 - ///Load scene resources
149 - SCENE_LOAD(name,true,true);
143 + //Load scene resources
144 + bool loadState = SCENE_LOAD(name,cameraMgr,true,true);
150 145
151 - if(state()->getWaterLevel() == RAND_MAX) computeWaterHeight = true;
146 + if(state().getWaterLevel() == RAND_MAX) computeWaterHeight = true;
152 147 Light* light = addDefaultLight();
153 148 light->setLightProperties(LIGHT_PROPERTY_AMBIENT,WHITE());
154 149 light->setLightProperties(LIGHT_PROPERTY_DIFFUSE,WHITE());
  @@ -163,7 +158,7 @@
163 158 _visibleTerrains.push_back(tempTerrain);
164 159 if(computeWaterHeight){
165 160 F32 tempMin = terrainNode->getBoundingBox().getMin().y;
166 - if(state()->_waterHeight > tempMin) state()->_waterHeight = tempMin;
161 + if(state()._waterHeight > tempMin) state()._waterHeight = tempMin;
167 162 }
168 163 }
169 164 }else{
  @@ -172,7 +167,7 @@
172 167 }
173 168 ResourceDescriptor infiniteWater("waterEntity");
174 169 _water = CreateResource<WaterPlane>(infiniteWater);
175 - _water->setParams(40.0f,25,0.4f,0.45f);
170 + _water->setParams(200.0f,vec2<F32>(85.0f, 92.5f),vec2<F32>(0.4f,0.35f),0.34f);
176 171 _waterGraphNode = _sceneGraph->getRoot()->addNode(_water);
177 172 _waterGraphNode->useDefaultTransform(false);
178 173 _waterGraphNode->setTransform(NULL);
  @@ -192,15 +187,15 @@
192 187 return Scene::unload();
193 188 }
194 189
195 - bool _switchAB = false;
196 190 void MainScene::test(boost::any a, CallbackParam b){
191 + static bool switchAB = false;
197 192 vec3<F32> pos;
198 193 SceneGraphNode* boxNode = _sceneGraph->findNode("box");
199 194 Object3D* box = NULL;
200 195 if(boxNode) box = boxNode->getNode<Object3D>();
201 196 if(box) pos = boxNode->getTransform()->getPosition();
202 197
203 - if(!_switchAB){
198 + if(!switchAB){
204 199 if(pos.x < 300 && pos.z == 0) pos.x++;
205 200 if(pos.x == 300)
206 201 {
  @@ -208,7 +203,7 @@
208 203 if(pos.y == 800)
209 204 {
210 205 if(pos.z > -500) pos.z--;
211 - if(pos.z == -500) _switchAB = true;
206 + if(pos.z == -500) switchAB = true;
212 207 }
213 208 }
214 209 } else {
  @@ -218,7 +213,7 @@
218 213 if(pos.y > 100 && pos.z == -500) pos.y--;
219 214 if(pos.y == 100) {
220 215 if(pos.z < 0) pos.z++;
221 - if(pos.z == 0) _switchAB = false;
216 + if(pos.z == 0) switchAB = false;
222 217 }
223 218 }
224 219 }
  @@ -269,18 +264,18 @@
269 264 ResourceDescriptor beepSound("beep sound");
270 265 beepSound.setResourceLocation(_paramHandler.getParam<std::string>("assetsLocation")+"/sounds/beep.wav");
271 266 beepSound.setFlag(false);
272 - state()->_backgroundMusic["generalTheme"] = CreateResource<AudioDescriptor>(backgroundMusic);
267 + state()._backgroundMusic["generalTheme"] = CreateResource<AudioDescriptor>(backgroundMusic);
273 268 _beep = CreateResource<AudioDescriptor>(beepSound);
274 269
275 270 gui.addText("camPosition", vec2<I32>(60,100),
276 271 Font::DIVIDE_DEFAULT,
277 272 vec3<F32>(0.2f,0.8f,0.2f),
278 273 "Position [ X: %5.0f | Y: %5.0f | Z: %5.0f ] [Pitch: %5.2f | Yaw: %5.2f]",
279 - renderState()->getCamera()->getEye().x,
280 - renderState()->getCamera()->getEye().y,
281 - renderState()->getCamera()->getEye().z,
282 - DEGREES(renderState()->getCamera()->getAngleX()),
283 - DEGREES(renderState()->getCamera()->getAngleY()));
274 + renderState().getCamera().getEye().x,
275 + renderState().getCamera().getEye().y,
276 + renderState().getCamera().getEye().z,
277 + renderState().getCamera().getEuler().pitch,
278 + renderState().getCamera().getEuler().yaw);
284 279
285 280 return true;
286 281 }
  @@ -288,20 +283,11 @@
288 283 void MainScene::onKeyDown(const OIS::KeyEvent& key){
289 284 Scene::onKeyDown(key);
290 285 switch(key.key) {
291 - case OIS::KC_W:
292 - state()->_moveFB = 0.75f;
293 - break;
294 - case OIS::KC_A:
295 - state()->_moveLR = 0.75f;
296 - break;
297 - case OIS::KC_S:
298 - state()->_moveFB = -0.75f;
299 - break;
300 - case OIS::KC_D:
301 - state()->_moveLR = -0.75f;
302 - break;
303 - default:
304 - break;
286 + default: break;
287 + case OIS::KC_W: state()._moveFB = 1; break;
288 + case OIS::KC_A: state()._moveLR = -1; break;
289 + case OIS::KC_S: state()._moveFB = -1; break;
290 + case OIS::KC_D: state()._moveLR = 1; break;
305 291 }
306 292 }
307 293
  @@ -309,21 +295,16 @@
309 295 void MainScene::onKeyUp(const OIS::KeyEvent& key){
310 296 Scene::onKeyUp(key);
311 297 switch(key.key) {
298 + default: break;
312 299 case OIS::KC_W:
313 - case OIS::KC_S:
314 - state()->_moveFB = 0;
315 - break;
300 + case OIS::KC_S: state()._moveFB = 0; break;
316 301 case OIS::KC_A:
317 - case OIS::KC_D:
318 - state()->_moveLR = 0;
319 - break;
320 - case OIS::KC_X:
321 - SFX_DEVICE.playSound(_beep);
322 - break;
302 + case OIS::KC_D: state()._moveLR = 0; break;
303 + case OIS::KC_X: SFX_DEVICE.playSound(_beep); break;
323 304 case OIS::KC_M:{
324 305 _playMusic = !_playMusic;
325 306 if(_playMusic){
326 - SFX_DEVICE.playMusic(state()->_backgroundMusic["generalTheme"]);
307 + SFX_DEVICE.playMusic(state()._backgroundMusic["generalTheme"]);
327 308 }else{
328 309 SFX_DEVICE.stopMusic();
329 310 }
  @@ -344,43 +325,28 @@
344 325 ter->toggleBoundingBoxes();
345 326 }
346 327 break;
347 - default:
348 - break;
349 328 }
350 329 }
351 330
352 331 void MainScene::onMouseMove(const OIS::MouseEvent& key){
353 - if(_mousePressed){
354 - if(_prevMouse.x - key.state.X.abs > 1 )
355 - state()->_angleLR = -0.15f;
356 - else if(_prevMouse.x - key.state.X.abs < -1 )
357 - state()->_angleLR = 0.15f;
358 - else
359 - state()->_angleLR = 0;
360 -
361 - if(_prevMouse.y - key.state.Y.abs > 1 )
362 - state()->_angleUD = -0.1f;
363 - else if(_prevMouse.y - key.state.Y.abs < -1 )
364 - state()->_angleUD = 0.1f;
365 - else
366 - state()->_angleUD = 0;
367 - }
368 -
369 - _prevMouse.x = key.state.X.abs;
370 - _prevMouse.y = key.state.Y.abs;
371 - }
372 -
373 - void MainScene::onMouseClickDown(const OIS::MouseEvent& key,OIS::MouseButtonID button){
374 - Scene::onMouseClickDown(key,button);
375 - if(button == 0)
376 - _mousePressed = true;
332 + if(_mousePressed[OIS::MB_Right]){
333 + if(_previousMousePos.x - key.state.X.abs > 1 ) state()._angleLR = -1;
334 + else if(_previousMousePos.x - key.state.X.abs < -1 ) state()._angleLR = 1;
335 + else state()._angleLR = 0;
336 +
337 + if(_previousMousePos.y - key.state.Y.abs > 1 ) state()._angleUD = -1;
338 + else if(_previousMousePos.y - key.state.Y.abs < -1 ) state()._angleUD = 1;
339 + else state()._angleUD = 0;
340 + }
341 +
342 + _previousMousePos.x = key.state.X.abs;
343 + _previousMousePos.y = key.state.Y.abs;
377 344 }
378 345
379 346 void MainScene::onMouseClickUp(const OIS::MouseEvent& key,OIS::MouseButtonID button){
380 347 Scene::onMouseClickUp(key,button);
381 - if(button == 0) {
382 - _mousePressed = false;
383 - state()->_angleUD = 0;
384 - state()->_angleLR = 0;
348 + if(!_mousePressed[OIS::MB_Right]){
349 + state()._angleUD = 0;
350 + state()._angleLR = 0;
385 351 }
386 352 }