diff options
author | Thales1330 <thaleslima.ufu@gmail.com> | 2017-01-24 18:25:17 -0200 |
---|---|---|
committer | Thales1330 <thaleslima.ufu@gmail.com> | 2017-01-24 18:25:17 -0200 |
commit | bdb0625280d827ba7333b6fc9d6c6534e0720100 (patch) | |
tree | 6511dd5568556115db2affce10696efb7ff62c8f /Project/Camera.cpp | |
parent | 56b93d40596cc6e39930faad0f6fdf347275ee49 (diff) | |
download | PSP.git-bdb0625280d827ba7333b6fc9d6c6534e0720100.tar.gz PSP.git-bdb0625280d827ba7333b6fc9d6c6534e0720100.tar.xz PSP.git-bdb0625280d827ba7333b6fc9d6c6534e0720100.zip |
Control editor implementation start
Diffstat (limited to 'Project/Camera.cpp')
-rw-r--r-- | Project/Camera.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Project/Camera.cpp b/Project/Camera.cpp new file mode 100644 index 0000000..248a835 --- /dev/null +++ b/Project/Camera.cpp @@ -0,0 +1,38 @@ +#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; +}
\ No newline at end of file |