From 0b6a3b520cd2e51e4d8cf7716ec4ddcf51297e2e Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 11 Nov 2019 01:24:09 +0000 Subject: [PATCH] im dissapointed w how little i got done this weekend --- src/renderer/camera.cpp | 12 +++++++++--- src/renderer/camera.hpp | 5 ++++- src/world/entity.cpp | 14 +++++++++++++- src/world/entity.hpp | 4 +--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/renderer/camera.cpp b/src/renderer/camera.cpp index ea36db2..40d27bf 100644 --- a/src/renderer/camera.cpp +++ b/src/renderer/camera.cpp @@ -33,9 +33,9 @@ Camera::Camera(int w, int h) { void Camera::UpdateView() { // roll can be removed - glm::mat4 matRoll = glm::mat4(1.0f); //identity matrix; - glm::mat4 matPitch = glm::mat4(1.0f);//identity matrix - glm::mat4 matYaw = glm::mat4(1.0f); //identity matrix + glm::mat4 matRoll = glm::mat4(1.0f); + glm::mat4 matPitch = glm::mat4(1.0f); + glm::mat4 matYaw = glm::mat4(1.0f); // roll, pitch and yaw matRoll = glm::rotate(matRoll, roll, glm::vec3(0.0f, 0.0f, 1.0f)); @@ -70,6 +70,12 @@ glm::mat4 Camera::GetProjectionMatrix() { } +glm::mat4 Camera::GetFrustrumMatrix() { + + return viewMatrix * projMatrix; + +} + void Camera::UpdateProjection(int width, int height) { projMatrix = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 0.1f, 1000.0f); diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 2fa5c35..d85fedb 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -12,6 +12,7 @@ public: glm::mat4 GetViewMatrix(); glm::mat4 GetProjectionMatrix(); + glm::mat4 GetFrustrumMatrix(); void UpdateProjection(int width, int height); @@ -22,7 +23,9 @@ public: float MouseSensitivity = 0.1f; float CameraSpeed = 2.0f; + // Influences the views update glm::vec3 Position = {}; + // Only updated after the view is updated glm::vec3 LookDirection = {}; private: @@ -30,7 +33,7 @@ private: glm::mat4 viewMatrix = {}; glm::mat4 projMatrix = {}; - + }; #endif diff --git a/src/world/entity.cpp b/src/world/entity.cpp index cc7332d..24474c9 100644 --- a/src/world/entity.cpp +++ b/src/world/entity.cpp @@ -13,7 +13,19 @@ Entity::Entity(glm::vec3 postion, glm::vec3 direction, std::shared_ptr c } } -Player::Player { +Player::Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr camera) + : Entity(position, direction, camera) { + camera->Position = + } +Player(glm::vec3 position, glm::vec3 direction = {0.0f, 0.0f, 0.0f}); + +void Move(Uint8* state); +void HandleMouse(SDL_Event e); + +void UpdatePosition(glm::vec3 position); +void UpdateDirection(glm::vec3 direction); + +void CameaUpdateProjection(int xres, int yres); diff --git a/src/world/entity.hpp b/src/world/entity.hpp index 2cfb2db..3fb918c 100644 --- a/src/world/entity.hpp +++ b/src/world/entity.hpp @@ -10,8 +10,6 @@ public: Entity(glm::vec3 position, glm::vec3 direction = { 0.0f, 0.0f, 0.0f }, std::shared_ptr camera = std::make_shared()); - bool Player = false; - // World position, 1.7 units below the // camera position. glm::vec3 Position; @@ -36,7 +34,7 @@ public: class Player : public Entity { public: - Player(glm::vec3 position, glm::vec3 direction = {0.0f, 0.0f, 0.0f}); + Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr camera); void Move(Uint8* state); void HandleMouse(SDL_Event e);