2018-09-08 04:06:10 +00:00
|
|
|
#include "Camera2D.h"
|
|
|
|
|
2018-09-10 01:20:56 +00:00
|
|
|
#include "Exception.h"
|
2018-09-08 04:06:10 +00:00
|
|
|
|
|
|
|
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)
|
2018-09-10 01:20:56 +00:00
|
|
|
: Camera(position)
|
2018-09-08 04:06:10 +00:00
|
|
|
{
|
|
|
|
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;
|
2018-09-10 01:20:56 +00:00
|
|
|
Poseable::update_position(-position);
|
2018-09-08 04:06:10 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 01:20:56 +00:00
|
|
|
// TODO: Inline?
|
2018-09-08 04:06:10 +00:00
|
|
|
void Camera2D::translate(const vec2& position)
|
|
|
|
{
|
|
|
|
translate(vec3(position.x, position.y, 0.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::translate(const vec3& position)
|
|
|
|
{
|
|
|
|
m_position += position;
|
2018-09-10 01:20:56 +00:00
|
|
|
Poseable::translate(-position);
|
2018-09-08 04:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::update_scale()
|
|
|
|
{
|
2018-09-10 01:20:56 +00:00
|
|
|
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;
|
2018-09-08 04:06:10 +00:00
|
|
|
}
|