charcoal/OpenGLEngine/Camera2D.cpp
elipzer 75357b330c Added Dependency: GLM
Now using GLM instead of the custom math libraries.
Sadly, this did not 100% fix the problem at hand but it does give
some closure that the math is not the problem.

Also it will be nice to have a general math library to not have to
deal with creating every math function every time.
2018-09-09 21:20:56 -04:00

44 lines
921 B
C++

#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;
}