From 1a8ec165031af3b860028ef1b360acc8e7baf9e6 Mon Sep 17 00:00:00 2001 From: TravisBot <> Date: Thu, 21 Sep 2017 23:32:46 +0000 Subject: Rebuilding documentation --- yage/base/camera2d.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 yage/base/camera2d.cpp (limited to 'yage/base/camera2d.cpp') diff --git a/yage/base/camera2d.cpp b/yage/base/camera2d.cpp new file mode 100644 index 00000000..9eda38ee --- /dev/null +++ b/yage/base/camera2d.cpp @@ -0,0 +1,45 @@ +/* ---------------------------------------------------------------------------- + * camera2d.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#include "camera2d.h" + +#include + +namespace yage +{ + +Camera2D::Camera2D(int screen_width, int screen_height) + : position_(0.f, 0.f), camera_matrix_(1.f), + ortho_matrix_( + glm::ortho(0.f, (float)screen_width, 0.f, (float)screen_height)) +{ +} + +void Camera2D::update(GlslProgram &program) +{ + if (update_matrix_) { + glm::vec3 translate(-position_.x, -position_.y, 0.f); + glm::vec3 scale(scale_, scale_, 0.f); + + camera_matrix_ = glm::translate(ortho_matrix_, translate); + camera_matrix_ = glm::scale(glm::mat4(1.f), scale) * camera_matrix_; + + update_matrix_ = false; + } + + GLint matrix_location = program.getUniformLocation("P"); + glUniformMatrix4fv(matrix_location, 1, GL_FALSE, &(camera_matrix_[0][0])); +} + +void Camera2D::move(const glm::vec2 &direction) +{ + position_ += direction; + update_matrix_ = true; +} + +} // namespace yage -- cgit