Camera.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Created by jovian on 18/08/17.
  3. //
  4. #include "Camera.h"
  5. Camera::Camera() : m_pos(0.0f, 0.0f), m_cursorPos(0.0f, 0.0f), m_zoom(100.0f), m_press(false), m_infoWanted(false) {}
  6. Camera::~Camera() {}
  7. void Camera::refresh(Input *input) {
  8. // Change position
  9. if (input->isMouseMoving() && input->getMouseKey(MOUSE_RIGHT)) {
  10. b2Vec2 move;
  11. move.x = (float) input->getXRel() / m_zoom;
  12. move.y = (float) input->getYRel() / m_zoom;
  13. m_pos -= move;
  14. }
  15. // Zoom
  16. if (input->getMouseKey(MOUSE_ANNEX_A))
  17. m_zoom += 1.0f;
  18. if (input->getMouseKey(MOUSE_ANNEX_B))
  19. m_zoom -= 1.0f;
  20. if (input->getMouseKey(MOUSE_MIDDLE))
  21. m_zoom = 100.0f;
  22. // Compute cursor position
  23. m_cursorPos.x = m_pos.x + (float) input->getXFromCenter() / m_zoom;
  24. m_cursorPos.y = m_pos.y + (float) input->getYFromCenter() / m_zoom;
  25. // Info wanted
  26. if (m_press != input->getMouseKey(MOUSE_LEFT)) {
  27. if (!m_press)
  28. m_infoWanted = !m_infoWanted;
  29. m_press = input->getMouseKey(MOUSE_LEFT);
  30. }
  31. }
  32. bool Camera::getInfoWanted() const {
  33. return m_infoWanted;
  34. }
  35. const b2Vec2 &Camera::getPos() const {
  36. return m_pos;
  37. }
  38. float Camera::getZoom() const {
  39. return m_zoom;
  40. }
  41. const b2Vec2 &Camera::getCursorPos() const {
  42. return m_cursorPos;
  43. }