diff options
Diffstat (limited to 'yage/core/camera.cpp')
-rw-r--r-- | yage/core/camera.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/yage/core/camera.cpp b/yage/core/camera.cpp index 71938cbb..843224dd 100644 --- a/yage/core/camera.cpp +++ b/yage/core/camera.cpp @@ -7,7 +7,8 @@ */ #include "camera.h" -#include "glslprogram.h" +#include "../render/shader.h" +#include "logger.h" #include <glad/glad.h> #include <glm/gtc/matrix_transform.hpp> @@ -15,6 +16,14 @@ namespace yage { +/** + * Creates a camera that looks onto the scene. The screen width and screen + * height should be the current size of the window that the camera is being used + * on so that is functions correctly. + * + * @param screen_width Current screen width of the Window. + * @param screen_height Current screen height of the Window. + */ Camera::Camera(int screen_width, int screen_height) : position_(0.f, 0.f), camera_matrix_(1.f), ortho_matrix_( @@ -22,7 +31,17 @@ Camera::Camera(int screen_width, int screen_height) { } -void Camera::update(GlslProgram &program) +/** + * Updates the camera matrix value in the shader program that is passed to it. + * This must be a parameter `P` in the shader for this function to work. + * + * @param program Shader program to make changes to. + * + * @todo Make this function more general to be able to be able to use any + * parametre in then shader as the camera matrix and not make it dependent on it + * being `P`. + */ +void Camera::update(Shader &program) { if (update_matrix_) { glm::vec3 translate(-position_.x, -position_.y, 0.f); @@ -34,14 +53,32 @@ void Camera::update(GlslProgram &program) update_matrix_ = false; } - GLint matrix_location = program.getUniformLocation("P"); - glUniformMatrix4fv(matrix_location, 1, GL_FALSE, &(camera_matrix_[0][0])); + program.setUniform("P", camera_matrix_); } +/** + * Moves the camera using a two-dimensional displacement vector to describe the + * movement. + * + * @param direction Two-dimensional vector to describe the displacement of the + * camera. + */ void Camera::move(const glm::vec2 &direction) { position_ += direction; update_matrix_ = true; } +/** + * Zooms the camera by an incremental amount. + * + * @param factor Factor by which the camera should zoom. This can also be a + * negative number for the camera to zoom out. + */ +void Camera::zoom(float factor) +{ + scale_ += factor; + update_matrix_ = true; +} + } // namespace yage |