Number5
Visualisierung 2 Project - Florian Schober (0828151, f.schober@live.com), Andreas Walch (0926780, walch.andreas89@gmail.com)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Camera.cpp
Go to the documentation of this file.
1 #include "Application.hpp"
2 
4  : m_app(app)
5  , m_cameraSideWayActive(false)
6 {
7  m_transformation.limitRotationX(glm::degrees(-85.0f), glm::degrees(+85.0f));
8  m_mouseBorder = 50;
9 }
10 
11 void Camera::update(double time, double timeDelta)
12 {
13  auto& wnd = m_app->getWindow();
14 
15  const float move_speed = 20.0f;
16  const float rot_speed = 0.5f;
17 
18  {
19  auto lookV = m_transformation.getLookVector();
20  auto sideV = m_transformation.getSideVector();
21 
22  auto move_delta = sideV * (float)(wnd.keyDown(GLFW_KEY_D) - wnd.keyDown(GLFW_KEY_A)) +
23  lookV * (float)(wnd.keyDown(GLFW_KEY_S) - wnd.keyDown(GLFW_KEY_W));
24 
25  // Auto-movment if cursor is in border-area
27  {
28  if (wnd.getCursor().x < m_mouseBorder) move_delta = move_delta - (sideV); // left
29  if (wnd.getCursor().x > wnd.getSize().x - m_mouseBorder) move_delta = move_delta + (sideV); // right
30  if (wnd.getCursor().y < m_mouseBorder) move_delta = move_delta - (lookV); // down
31  if (wnd.getCursor().y > wnd.getSize().y - m_mouseBorder) move_delta = move_delta + (lookV); // up
32  }
33 
34  if ( move_delta.x != 0 || move_delta.y != 0 || move_delta.z != 0 )
35  m_transformation.move( move_delta * move_speed * (float)timeDelta );
36  }
37 
38  if (wnd.mouseDown(GLFW_MOUSE_BUTTON_RIGHT))
39  {
40  auto rot_delta = vec3(glm::radians(-wnd.getCursorDelta().y),
41  -glm::radians(wnd.getCursorDelta().x),
42  0);
43  if ( rot_delta.x != 0 || rot_delta.y != 0 || rot_delta.z != 0 )
44  m_transformation.rotate( rot_delta * rot_speed );
45  }
46 
48 }
49 void Camera::onKeyStateChanged(int key, bool pressed)
50 {
51  if (!pressed)
52  {
53  if (key == GLFW_KEY_SCROLL_LOCK)
55  }
56 }
Application * m_app
Definition: Camera.hpp:13
bool m_cameraSideWayActive
Definition: Camera.hpp:16
bool const needsRecalc()
vec3 const & getSideVector()
bool m_hasViewChanged
Definition: Camera.hpp:14
Camera & getCamera()
Definition: Application.hpp:76
void move(vec3 const &delta)
Window & getWindow()
Definition: Application.hpp:41
void limitRotationX(float from, float to)
void update(double time, double timeDelta)
Definition: Camera.cpp:11
void rotate(vec3 const &delta)
bool const sideWayActive()
Definition: Camera.hpp:28
vec3 const & getLookVector()
Camera(Application *app)
Definition: Camera.cpp:3
Transformation m_transformation
Definition: Camera.hpp:12
void onKeyStateChanged(int key, bool pressed)
Definition: Camera.cpp:49
int m_mouseBorder
Definition: Camera.hpp:15