From 400410fcd436d5e4310bfa779f0309c5fae5b2c2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 16 Jan 2021 18:09:15 +0000 Subject: Initial commit Stripped back and formatted from https://github.com/BennyQBD/ModernOpenGLTutorial/ --- camera.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 camera.h (limited to 'camera.h') diff --git a/camera.h b/camera.h new file mode 100644 index 0000000..86b59d1 --- /dev/null +++ b/camera.h @@ -0,0 +1,59 @@ +#ifndef CAMERA_INCLUDED_H +#define CAMERA_INCLUDED_H + +#include +#include + +struct Camera { +public: + Camera(const glm::vec3 & pos, float fov, float aspect, float zNear, float zFar) + { + this->pos = pos; + this->forward = glm::vec3(0.0f, 0.0f, 1.0f); + this->up = glm::vec3(0.0f, 1.0f, 0.0f); + this->projection = glm::perspective(fov, aspect, zNear, zFar); + } + + inline glm::mat4 + GetViewProjection() const + { + return projection * glm::lookAt(pos, pos + forward, up); + } + + // void MoveForward(float amt) + //{ + // pos += forward * amt; + //} + + // void MoveRight(float amt) + //{ + // pos += glm::cross(up, forward) * amt; + //} + + // void Pitch(float angle) + //{ + // glm::vec3 right = glm::normalize(glm::cross(up, forward)); + + // forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0))); + // up = glm::normalize(glm::cross(forward, right)); + //} + + // void RotateY(float angle) + //{ + // static const glm::vec3 UP(0.0f, 1.0f, 0.0f); + + // glm::mat4 rotation = glm::rotate(angle, UP); + + // forward = glm::vec3(glm::normalize(rotation * glm::vec4(forward, 0.0))); + // up = glm::vec3(glm::normalize(rotation * glm::vec4(up, 0.0))); + //} + +protected: +private: + glm::mat4 projection; + glm::vec3 pos; + glm::vec3 forward; + glm::vec3 up; +}; + +#endif -- cgit v1.2.3