#include "gameplay/camera.h"

void Camera::update(float deltaTime)
{
	if (target == nullptr)
		return;
	float smoothingFactor = 0.01f;
	if (glm::distance(target->getCenter(), getCenterPos()) > 20.f)
		position += (target->getCenter() - getCenterPos()) * speed * smoothingFactor * deltaTime;
}

glm::mat4 Camera::getViewMatrix() 
{
	return glm::lookAt(position, position + front, up);
}

glm::mat4 Camera::getProjectionMatrix()
{
	return glm::ortho(0.f, viewPortW, viewPortH, 0.f);
}

const glm::vec3 Camera::worldToLocal(const glm::vec3& worldCoordinates) const
{
	return worldCoordinates - position;
}
