51 lines
941 B
C++
51 lines
941 B
C++
#include "cameranode.h"
|
|
#include <glm/ext.hpp>
|
|
|
|
CameraNode::CameraNode(glm::vec3 position, float yFov, float near, float far) :
|
|
m_hasMoved(true),
|
|
m_hasResized(false),
|
|
m_eye(position),
|
|
m_target(0, 0, 1),
|
|
m_yFov(yFov),
|
|
m_near(near),
|
|
m_far(far)
|
|
{
|
|
|
|
}
|
|
|
|
void CameraNode::setPosition(glm::vec3 position)
|
|
{
|
|
m_hasMoved = true;
|
|
m_eye = position;
|
|
}
|
|
|
|
void CameraNode::setTarget(glm::vec3 target)
|
|
{
|
|
m_hasMoved = true;
|
|
m_target = target;
|
|
}
|
|
|
|
void CameraNode::update()
|
|
{
|
|
if(m_hasMoved)
|
|
m_view = glm::lookAt(m_eye, m_target, glm::vec3(0, 1, 0));
|
|
if(m_hasResized)
|
|
m_projection = glm::perspective(m_yFov, m_ratio, m_near, m_far);
|
|
}
|
|
|
|
glm::mat4 CameraNode::getProjectionMatrix()
|
|
{
|
|
return m_projection;
|
|
}
|
|
|
|
glm::mat4 CameraNode::getViewMatrix()
|
|
{
|
|
return m_view;
|
|
}
|
|
|
|
void CameraNode::resize(int width, int height)
|
|
{
|
|
m_hasResized = false;
|
|
m_ratio = ((float)width)/((float)height);
|
|
}
|