diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 12:19:41 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 12:19:41 +0100 |
commit | 55a1e0ad7c9d2661c266b2e767bfcb2f944e859f (patch) | |
tree | fe3ac90ab853e2f87bd33294976a3fc56e144988 /src/camera2d.cpp | |
parent | aa67c8bb56cb750ac83ecbd361439f5ecb5e12d9 (diff) | |
download | YAGE-55a1e0ad7c9d2661c266b2e767bfcb2f944e859f.tar.gz YAGE-55a1e0ad7c9d2661c266b2e767bfcb2f944e859f.zip |
Adding spritebatch class
Diffstat (limited to 'src/camera2d.cpp')
-rw-r--r-- | src/camera2d.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/camera2d.cpp b/src/camera2d.cpp new file mode 100644 index 00000000..5dd25bb3 --- /dev/null +++ b/src/camera2d.cpp @@ -0,0 +1,29 @@ +#include "camera2d.hpp" + +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)) +{} + +Camera2D::~Camera2D() +{} + +void Camera2D::update() +{ + if(matrix_needs_update_) + { + 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_; + + matrix_needs_update_=false; + } +} + +} // yage |