12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // Created by jovian on 18/08/17.
- //
- #include "Camera.h"
- Camera::Camera() : m_pos(0.0f, 0.0f), m_cursorPos(0.0f, 0.0f), m_zoom(100.0f), m_press(false), m_infoWanted(false) {}
- Camera::~Camera() {}
- void Camera::refresh(Input *input) {
- // Change position
- if (input->isMouseMoving() && input->getMouseKey(MOUSE_RIGHT)) {
- b2Vec2 move;
- move.x = (float) input->getXRel() / m_zoom;
- move.y = (float) input->getYRel() / m_zoom;
- m_pos -= move;
- }
- // Zoom
- if (input->getMouseKey(MOUSE_ANNEX_A))
- m_zoom += 1.0f;
- if (input->getMouseKey(MOUSE_ANNEX_B))
- m_zoom -= 1.0f;
- if (input->getMouseKey(MOUSE_MIDDLE))
- m_zoom = 100.0f;
- // Compute cursor position
- m_cursorPos.x = m_pos.x + (float) input->getXFromCenter() / m_zoom;
- m_cursorPos.y = m_pos.y + (float) input->getYFromCenter() / m_zoom;
- // Info wanted
- if (m_press != input->getMouseKey(MOUSE_LEFT)) {
- if (!m_press)
- m_infoWanted = !m_infoWanted;
- m_press = input->getMouseKey(MOUSE_LEFT);
- }
- }
- bool Camera::getInfoWanted() const {
- return m_infoWanted;
- }
- const b2Vec2 &Camera::getPos() const {
- return m_pos;
- }
- float Camera::getZoom() const {
- return m_zoom;
- }
- const b2Vec2 &Camera::getCursorPos() const {
- return m_cursorPos;
- }
|