aboutsummaryrefslogtreecommitdiffstats
path: root/yage/core/camera.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-01-06 11:30:24 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-01-06 11:30:24 +0000
commitc7090180503f263c60ec34844992e0e8d4bea85a (patch)
tree6ecc5b2e16856db49de056738b36e1ba103d3049 /yage/core/camera.cpp
parentcf4c73f2a75b470a4d4c4167105f92bc46f1926c (diff)
parent07012cf0982d3f86aebe83b5bdc4a67332c635da (diff)
downloadYAGE-c7090180503f263c60ec34844992e0e8d4bea85a.tar.gz
YAGE-c7090180503f263c60ec34844992e0e8d4bea85a.zip
Merge branch 'develop'
Diffstat (limited to 'yage/core/camera.cpp')
-rw-r--r--yage/core/camera.cpp45
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