26 lines
684 B
C++
26 lines
684 B
C++
#include "gameplay/camera.h"
|
|
|
|
void Camera::update(double deltaTime)
|
|
{
|
|
if (target == nullptr)
|
|
return;
|
|
float smoothingFactor = 5.0f;
|
|
//if (glm::distance(target->getCenter(), getCenterPos()) > 20.f)
|
|
position += (target->getCenter() - getCenterPos()) * smoothingFactor * static_cast<float>(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)
|
|
{
|
|
//return worldCoordinates - position;
|
|
return glm::vec3(getViewMatrix() * glm::vec4(worldCoordinates, 1.0f));
|
|
}
|