#include "Camera.h"
#include <glm/vec2.hpp>
#include <algorithm>

Camera::Camera()
    : m_pos(new Vector2f(0.0f, 0.0f))
{

}

Camera::Camera(float x, float y)
    : m_pos(new Vector2f(x, y))
{

}

Camera::Camera(const Camera& other)
    : m_pos(new Vector2f(other.m_pos->x, other.m_pos->y))
    , m_zoom(other.m_zoom)
    , m_zPos(other.m_zPos)
    , m_enabled(other.m_enabled)
{

}

Camera::~Camera()
{

}

void Camera::setPosition(float x, float y)
{
    *m_pos = Vector2f(x, y);
}

void Camera::setPosition(Vector2f pos)
{
    *m_pos = pos;
}

Camera::Vector2f Camera::getPosition() const
{
    return *m_pos;
}

void Camera::setZoom(float zoom)
{
    this->m_zoom = std::max(0.1f, std::min(10.0f, zoom));
}

float Camera::getZoom() const
{
    return m_zoom;
}

void Camera::setZPosition(float z)
{
    this->m_zPos = z;
}

float Camera::getZPosition() const
{
    return m_zPos;
}

void Camera::setEnabled(bool enabled)
{
    this->m_enabled = enabled;
}

/**
 * 获取摄像机是否启用
 */
bool Camera::isEnabled() const
{
    return m_enabled;
}

void Camera::move(float dx, float dy)
{
    *m_pos += Vector2f(dx, dy);
}

void Camera::zoom(float factor)
{
    m_zoom *= factor;
    m_zoom = std::max(0.1f, std::min(10.0f, m_zoom));
}

void Camera::reset() {
    *m_pos = Vector2f(0.0f, 0.0f);
    m_zoom = 1.0f;
    m_zPos = 0.0f;
}
