diff options
author | rtk0c <[email protected]> | 2022-06-03 23:30:01 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-03 23:30:01 -0700 |
commit | 791b3f354b378769bffe623b05f1305c91b77101 (patch) | |
tree | 5409b311e6232eb4a6d3f8259b780d76b8ee1c59 /ProjectBrussel/Game/Camera.cpp | |
parent | 60ccc62f4934e44ad5b905fdbcf458302b8d8a09 (diff) |
Changeset: 64 [WIP] Rename directoriesmaster-switch-to-build2
Diffstat (limited to 'ProjectBrussel/Game/Camera.cpp')
-rw-r--r-- | ProjectBrussel/Game/Camera.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ProjectBrussel/Game/Camera.cpp b/ProjectBrussel/Game/Camera.cpp new file mode 100644 index 0000000..39f0369 --- /dev/null +++ b/ProjectBrussel/Game/Camera.cpp @@ -0,0 +1,46 @@ +#include "Camera.hpp" + +#include "AppConfig.hpp" + +#include <glm/gtc/matrix_transform.hpp> + +Camera::Camera() + : eye(0.0f, 0.0f, 0.0f) + , target(0.0, 0.0f, -2.0f) + , pixelsPerMeter{ 50.0f } // Basic default + , fov{ M_PI / 4 } // 45deg is the convention + , perspective{ false } // +{ +} + +void Camera::SetEyePos(glm::vec3 pos) { + auto lookVector = this->target - /*Old pos*/ this->eye; + this->eye = pos; + this->target = pos + lookVector; +} + +void Camera::SetTargetPos(glm::vec3 pos) { + this->target = pos; +} + +void Camera::SetTargetDirection(glm::vec3 lookVector) { + this->target = this->eye + lookVector; +} + +void Camera::SetHasPerspective(bool perspective) { + this->perspective = perspective; +} + +glm::mat4 Camera::CalcViewMatrix() const { + return glm::lookAt(eye, target, glm::vec3(0, 1, 0)); +} + +glm::mat4 Camera::CalcProjectionMatrix() const { + if (perspective) { + return glm::perspective(fov, AppConfig::mainWindowAspectRatio, 0.1f, 1000.0f); + } else { + float widthMeters = AppConfig::mainWindowWidth / pixelsPerMeter; + float heightMeters = AppConfig::mainWindowHeight / pixelsPerMeter; + return glm::ortho(-widthMeters / 2, +widthMeters / 2, -heightMeters / 2, +heightMeters / 2); + } +} |