xoreos  0.0.5
freeroamcamera.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/graphics/camera.h"
26 
28 
30 
31 namespace Engines {
32 
34  if (e.type == Events::kEventKeyDown)
35  return handleCameraKeyboardInput(e);
36  else if (e.type == Events::kEventMouseMove)
37  return handleCameraMouseInput(e);
38 
39  return false;
40 }
41 
43  float multiplier = 1.0f;
44  if (e.key.keysym.mod & KMOD_SHIFT)
45  multiplier = 5.0f;
46 
47  if (e.key.keysym.sym == SDLK_UP)
48  CameraMan.moveRelative(0.0f, 0.0f, multiplier * -0.5f);
49  else if (e.key.keysym.sym == SDLK_DOWN)
50  CameraMan.moveRelative(0.0f, 0.0f, multiplier * 0.5f);
51  else if (e.key.keysym.sym == SDLK_RIGHT)
52  CameraMan.turn( 0.0f, 0.0f, multiplier * -5.0f);
53  else if (e.key.keysym.sym == SDLK_LEFT)
54  CameraMan.turn( 0.0f, 0.0f, multiplier * 5.0f);
55  else if (e.key.keysym.scancode == SDL_SCANCODE_W)
56  CameraMan.moveRelative(0.0f, 0.0f, multiplier * -0.5f);
57  else if (e.key.keysym.scancode == SDL_SCANCODE_S)
58  CameraMan.moveRelative(0.0f, 0.0f, multiplier * 0.5f);
59  else if (e.key.keysym.scancode == SDL_SCANCODE_D)
60  CameraMan.turn( 0.0f, 0.0f, multiplier * -5.0f);
61  else if (e.key.keysym.scancode == SDL_SCANCODE_A)
62  CameraMan.turn( 0.0f, 0.0f, multiplier * 5.0f);
63  else if (e.key.keysym.scancode == SDL_SCANCODE_Q)
64  CameraMan.moveRelative(multiplier * -0.5f, 0.0f, 0.0f);
65  else if (e.key.keysym.scancode == SDL_SCANCODE_E)
66  CameraMan.moveRelative(multiplier * 0.5f, 0.0f, 0.0f);
67  else if (e.key.keysym.sym == SDLK_INSERT)
68  CameraMan.moveRelative(0.0f, multiplier * 0.5f, 0.0f);
69  else if (e.key.keysym.sym == SDLK_DELETE)
70  CameraMan.moveRelative(0.0f, multiplier * -0.5f, 0.0f);
71  else if (e.key.keysym.sym == SDLK_PAGEUP)
72  CameraMan.turn(multiplier * 5.0f, 0.0f, 0.0f);
73  else if (e.key.keysym.sym == SDLK_PAGEDOWN)
74  CameraMan.turn(multiplier * -5.0f, 0.0f, 0.0f);
75  else if (e.key.keysym.sym == SDLK_END) {
76  const float *orient = CameraMan.getOrientation();
77 
78  CameraMan.setOrientation(90.0f, orient[1], orient[2]);
79  } else
80  return false;
81 
82  return true;
83 }
84 
86  // Holding down the middle mouse button enables free look.
87  if (e.motion.state & SDL_BUTTON(2))
88  CameraMan.turn(-0.5f * e.motion.yrel, 0.0f, -0.5f * e.motion.xrel);
89  else
90  return false;
91 
92  return true;
93 }
94 
95 } // End of namespace Engines
bool handleCameraMouseInput(const Events::Event &e)
Camera management.
Mouse was moved.
Definition: types.h:48
SDL_Event Event
Definition: types.h:42
Keyboard key was pressed.
Definition: types.h:46
bool handleCameraKeyboardInput(const Events::Event &e)
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
Definition: singleton.h:122
bool handleCameraInput(const Events::Event &e)
#define CameraMan
Shortcut for accessing the camera manager.
Definition: camera.h:83
Engine utility class for free-roam camera handling.