mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 13:39:19 +01:00
34 lines
949 B
C++
34 lines
949 B
C++
#include "pch.h"
|
|
#include "Camera.h"
|
|
|
|
Camera::Camera() : m_Position { 0, 0 }, m_Scale { 1.0f } {
|
|
}
|
|
|
|
Camera::Camera(const Point2f& position, float scale) : m_Position { position }, m_Scale { scale } {
|
|
}
|
|
|
|
|
|
void Camera::BeginRendering() const {
|
|
glPushMatrix();
|
|
glTranslatef(-m_Position.x, -m_Position.y, 0);
|
|
glScalef(m_Scale, m_Scale, 1);
|
|
}
|
|
|
|
void Camera::EndRendering() const {
|
|
glPopMatrix();
|
|
}
|
|
|
|
Point2f Camera::TransformMouse(const Point2f& mousePos) const {
|
|
//Mousepos is in screen coords, we need to transform it to world coords
|
|
Point2f worldPos = mousePos;
|
|
worldPos.x = (worldPos.x + m_Position.x) / m_Scale;
|
|
worldPos.y = Viewport.height - worldPos.y + m_Position.y / m_Scale;
|
|
return worldPos;
|
|
}
|
|
Point2f Camera::TransformWorld(const Point2f& worldPos) const {
|
|
Point2f screenPos = worldPos;
|
|
screenPos.x = screenPos.x * m_Scale - m_Position.x;
|
|
screenPos.y = Viewport.height - screenPos.y * m_Scale - m_Position.y;
|
|
return screenPos;
|
|
}
|