1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include "Camera.h"
#include "../Application.h"
namespace nCine
{
Camera::Camera()
: viewValues_(0.0f, 0.0f, 0.0f, 1.0f), view_(Matrix4x4f::Identity), updateFrameProjectionMatrix_(0), updateFrameViewMatrix_(0)
{
auto res = theApplication().GetResolution();
projectionValues_.left = 0.0f;
projectionValues_.right = res.X;
projectionValues_.top = 0.0f;
projectionValues_.bottom = res.Y;
projection_ = Matrix4x4f::Ortho(projectionValues_.left, projectionValues_.right,
projectionValues_.bottom, projectionValues_.top,
projectionValues_.nearClip, projectionValues_.farClip);
}
void Camera::SetOrthoProjection(float left, float right, float top, float bottom)
{
projectionValues_.left = left;
projectionValues_.right = right;
projectionValues_.top = top;
projectionValues_.bottom = bottom;
projection_ = Matrix4x4f::Ortho(projectionValues_.left, projectionValues_.right,
projectionValues_.bottom, projectionValues_.top,
projectionValues_.nearClip, projectionValues_.farClip);
updateFrameProjectionMatrix_ = theApplication().GetFrameCount();
}
void Camera::SetOrthoProjection(const ProjectionValues& values)
{
SetOrthoProjection(values.left, values.right, values.top, values.bottom);
}
void Camera::SetView(Vector2f position, float rotation, float scale)
{
viewValues_.position = position;
viewValues_.rotation = rotation;
viewValues_.scale = scale;
view_ = Matrix4x4f::Translation(-position.X, -position.Y, 0.0f);
view_.RotateZ(-rotation);
view_.Scale(scale, scale, 1.0f);
updateFrameViewMatrix_ = theApplication().GetFrameCount();
}
void Camera::SetView(float x, float y, float rotation, float scale)
{
SetView(Vector2f(x, y), rotation, scale);
}
void Camera::SetView(const ViewValues& values)
{
SetView(values.position, values.rotation, values.scale);
}
}
|