charcoal/OpenGLEngine/Camera2D.cpp

44 lines
921 B
C++
Raw Normal View History

#include "Camera2D.h"
#include "Exception.h"
Camera2D::Camera2D(const vec2& size, const vec2& position)
: Camera2D(vec3(size.x, size.y, 2.0f), vec3(position.x, position.y, 0.0f)) {}
Camera2D::Camera2D(const vec3& size, const vec3& position)
: Camera(position)
{
update_size(size);
update_position(position);
}
void Camera2D::update_size(const vec3& size)
{
m_size = size;
update_scale();
}
void Camera2D::update_position(const vec3& position)
{
m_position = position;
Poseable::update_position(-position);
}
// TODO: Inline?
void Camera2D::translate(const vec2& position)
{
translate(vec3(position.x, position.y, 0.0f));
}
void Camera2D::translate(const vec3& position)
{
m_position += position;
Poseable::translate(-position);
}
void Camera2D::update_scale()
{
m_projection_matrix[0][0] = 2.0f / m_size.x;
m_projection_matrix[1][1] = 2.0f / m_size.y;
m_projection_matrix[2][2] = -2.0f / m_size.z;
}