diff --git a/src/game.cpp b/src/game.cpp index a6070fa..03feba9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -83,15 +83,14 @@ void Game::Setup(int w, int h) { *m_logger << LOGGER_ENDL; IsDisplayOpen = true; - m_player = std::make_shared(0, 70, 0); - - m_player->EntityCamera = std::make_shared(w, h); + std::shared_ptr playercamera = std::make_shared(w, h); + m_player = std::make_shared(glm::vec3(0), glm::vec3(0), playercamera); std::shared_ptr BlockDictionary = CBlockDictionary::GetInstance(); BlockDictionary->Build(); - m_world = std::make_unique(); + m_world = std::make_shared(); Texture texture; m_world->SetTextureMap(texture.LoadTextures(BlockDictionary->Textures)); @@ -132,7 +131,7 @@ void Game::Input(SDL_Event* e) { if (e->window.event == SDL_WINDOWEVENT_RESIZED) { - m_player->EntityCamera->UpdateProjection(e->window.data1, e->window.data2); + m_player->CameraUpdateProjection(e->window.data1, e->window.data2); glViewport(0, 0, e->window.data1, e->window.data2); } @@ -152,11 +151,11 @@ void Game::Input(SDL_Event* e) { } - if (IsMouseActive) m_player->EntityCamera->HandleMouse(*e); + if (IsMouseActive) m_player->HandleMouseSDL(*e); } - m_player->EntityCamera->MoveCamera(state); + m_player->MoveSDL(state); } diff --git a/src/game.hpp b/src/game.hpp index e57e0e2..daee357 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -22,7 +22,8 @@ class Logger; class Renderer; class Camera; -class Entity; + +class Player; class World; class Game { @@ -44,11 +45,10 @@ private: std::shared_ptr m_logger; - std::shared_ptr m_renderer; std::shared_ptr m_world; - std::shared_ptr m_player; + std::shared_ptr m_player; }; diff --git a/src/physics/collider.hpp b/src/physics/collider.hpp index 3fb3f2f..49e24f6 100644 --- a/src/physics/collider.hpp +++ b/src/physics/collider.hpp @@ -9,6 +9,11 @@ public: glm::vec3 Max; }; +class Collider : public ColliderBox { +public: + +}; + // TODO: Trees class EntityCollider { public: diff --git a/src/renderer/camera.cpp b/src/renderer/camera.cpp index e04a758..9c55d62 100644 --- a/src/renderer/camera.cpp +++ b/src/renderer/camera.cpp @@ -13,6 +13,8 @@ Camera::Camera() { viewMatrix = {}; + UpdateView(); + } Camera::Camera(int w, int h) { @@ -28,6 +30,8 @@ Camera::Camera(int w, int h) { viewMatrix = {}; + UpdateView(); + } void Camera::UpdateView() { @@ -161,6 +165,8 @@ void Camera::UpdatePosition(glm::vec3 position) { Position = position; + UpdateView(); + } void Camera::UpdateEulerLookDirection(float roll, float pitch, float yaw) { @@ -170,6 +176,8 @@ void Camera::UpdateEulerLookDirection(float roll, float pitch, float yaw) { LookDirection.y = sin(Yaw) * cos(Pitch); LookDirection.z = sin(Pitch); + UpdateView(); + } void Camera::UpdateLookDirection(glm::vec3 lookDirection) { @@ -178,4 +186,6 @@ void Camera::UpdateLookDirection(glm::vec3 lookDirection) { Pitch = asin(-lookDirection.y); Yaw = atan2(lookDirection.x, lookDirection.z); + UpdateView(); + } diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 09a0156..3517ce5 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -16,8 +16,10 @@ public: void UpdateProjection(int width, int height); - void HandleMouse(SDL_Event e); + // Keyboard void MoveCamera(Uint8* state); + // Mouse + void HandleMouse(SDL_Event e); void MouseMoved(glm::vec2 mouseDelta); float MouseSensitivity = 0.1f; diff --git a/src/world/entity.cpp b/src/world/entity.cpp index f3bc7fc..9e14d4f 100644 --- a/src/world/entity.cpp +++ b/src/world/entity.cpp @@ -13,38 +13,47 @@ Entity::Entity(glm::vec3 postion, glm::vec3 direction, std::shared_ptr c } } -<<<<<<< HEAD -Player::Player(glm::vec3 position, glm::vec3 direction) { +Player::Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr camera) + : Entity(position, direction, camera) { + + Position = { 0, 64, 0 }; + EntityCamera->Position = { Position.x, Position.y + EyePosition, Position.z }; + EntityCamera->UpdateView(); } -void Player::Move(Uint8* state) { - +void Player::MoveSDL(Uint8* state) { + + EntityCamera->MoveCamera(state); + Position = EntityCamera->Position; + Position.y -= EyePosition; + } void Player::HandleMouseSDL(SDL_Event e) { -} - - void UpdatePosition(glm::vec3 position); - void UpdateDirection(glm::vec3 direction); - - void CameaUpdateProjection(int xres, int yres); -======= -Player::Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr camera) - : Entity(position, direction, camera) { - - camera->Position = + EntityCamera->HandleMouse(e); + Direction = EntityCamera->LookDirection; } -Player(glm::vec3 position, glm::vec3 direction = {0.0f, 0.0f, 0.0f}); +void Player::UpdatePosition(glm::vec3 position) { -void Move(Uint8* state); -void HandleMouse(SDL_Event e); + Position = position; + EntityCamera->UpdatePosition({ Position.x, Position.y + EyePosition, Position.z }); -void UpdatePosition(glm::vec3 position); -void UpdateDirection(glm::vec3 direction); +} -void CameaUpdateProjection(int xres, int yres); ->>>>>>> 0b6a3b520cd2e51e4d8cf7716ec4ddcf51297e2e + +void Player::UpdateDirection(glm::vec3 direction) { + + Direction = direction; + EntityCamera->UpdateLookDirection(direction); + +} + +void Player::CameraUpdateProjection(int xres, int yres) { + + EntityCamera->UpdateProjection(xres, yres); + +} diff --git a/src/world/entity.hpp b/src/world/entity.hpp index 57a235c..ade36b9 100644 --- a/src/world/entity.hpp +++ b/src/world/entity.hpp @@ -5,6 +5,8 @@ class Camera; +class Collider; + class Entity { public: @@ -15,7 +17,6 @@ public: glm::vec3 Position; // Look direction of the camera glm::vec3 Direction; - // Velocity in direction // of movement glm::vec3 Velocity; @@ -24,25 +25,26 @@ public: std::shared_ptr EntityCamera; // Collider - + // std::unique_ptr EntityCollider; // Mesh (or reference to) }; - class Player : public Entity { public: Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr camera); - void Move(Uint8* state); + float EyePosition = 1.7f; + + void MoveSDL(Uint8* state); void HandleMouseSDL(SDL_Event e); void UpdatePosition(glm::vec3 position); void UpdateDirection(glm::vec3 direction); - void CameaUpdateProjection(int xres, int yres); + void CameraUpdateProjection(int xres, int yres); };