From ddd26ed83d3ac0335562f762ced273a1d62bd959 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 23 Dec 2017 01:37:09 +0000 Subject: [Style] Updated style in files. --- yage/core/camera.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 yage/core/camera.cpp (limited to 'yage/core/camera.cpp') diff --git a/yage/core/camera.cpp b/yage/core/camera.cpp new file mode 100644 index 00000000..71938cbb --- /dev/null +++ b/yage/core/camera.cpp @@ -0,0 +1,47 @@ +/** --------------------------------------------------------------------------- + * @file: camera.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "camera.h" +#include "glslprogram.h" + +#include +#include + +namespace yage +{ + +Camera::Camera(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 Camera::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 Camera::move(const glm::vec2 &direction) +{ + position_ += direction; + update_matrix_ = true; +} + +} // namespace yage -- cgit