#include "pch.h"
#include "Camera.h"

Camera::Camera() : m_Position { 0, 0 }, m_Scale { 1.0f } {
}

Camera::Camera(const Vector2f& 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);
}

// ReSharper disable once CppMemberFunctionMayBeStatic
void Camera::EndRendering() const {
	glPopMatrix();
}

Vector2f Camera::TransformMouse(const Vector2f& mousePos) const {
	Vector2f worldPos = mousePos;
	worldPos.x = ( worldPos.x + m_Position.x ) / m_Scale;
	worldPos.y = Viewport.height - worldPos.y + m_Position.y / m_Scale;
	return worldPos;
}
Vector2f Camera::TransformWorld(const Vector2f& worldPos) const {
	Vector2f screenPos = worldPos;
	screenPos.x = screenPos.x * m_Scale - m_Position.x;
	screenPos.y = Viewport.height - screenPos.y * m_Scale - m_Position.y;
	return screenPos;
}
