blob: 58c916c492f0a218924b3f55c90760dc4a131ed7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/*
* Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Camera.h"
Camera::Camera()
{
m_translation = wxPoint2DDouble(0, 0);
m_scale = 1.0;
}
Camera::~Camera() {}
wxPoint2DDouble Camera::ScreenToWorld(wxPoint2DDouble screenCoords) const
{
return wxPoint2DDouble(screenCoords.m_x / m_scale - m_translation.m_x,
screenCoords.m_y / m_scale - m_translation.m_y);
}
void Camera::SetTranslation(wxPoint2DDouble screenPoint)
{
m_translation = screenPoint / m_scale - m_translationStartPt;
}
void Camera::SetScale(wxPoint2DDouble screenPoint, double delta)
{
m_translation -= screenPoint * (1.0 - m_scale) / m_scale;
m_scale += delta;
// Limits: 5% - 300%
if(m_scale < m_zoomMin) m_scale = m_zoomMin;
if(m_scale > m_zoomMax) m_scale = m_zoomMax;
m_translation += screenPoint * (1.0 - m_scale) / m_scale;
}
wxPoint2DDouble Camera::GetMousePosition(bool worldCoords) const
{
if(worldCoords) return ScreenToWorld(m_mousePosition);
return m_mousePosition;
}
|