diff --git a/src/game.cpp b/src/game.cpp index 16a2447..60922ff 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -89,14 +89,9 @@ void Game::Setup(int w, int h) { m_world = std::make_unique(); Texture texture; - m_world->TextureID = texture.LoadTextures(BlockDictionary->Textures); + m_world->SetTextureMap(texture.LoadTextures(BlockDictionary->Textures)); - for (int x = 0; x < 2; x++) - for (int y = 0; y < 2; y++) { - - m_world->Chunks.push_back(std::make_shared(x, y)); - - } + m_world->LoadWorld(); m_world->Shaders["Basic"] = std::make_shared(); m_world->Shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple"); diff --git a/src/renderer/camera.cpp b/src/renderer/camera.cpp index b26eb04..48dce0d 100644 --- a/src/renderer/camera.cpp +++ b/src/renderer/camera.cpp @@ -8,7 +8,9 @@ Camera::Camera(int w, int h) { pitch = 0.0f; yaw = 0.0f; - eyeVector = {}; + Position = {}; + LookDirection = {}; + viewMatrix = {}; } @@ -28,10 +30,17 @@ void Camera::UpdateView() { glm::mat4 rotate = matRoll * matPitch * matYaw; glm::mat4 translate = glm::mat4(1.0f); - translate = glm::translate(translate, -eyeVector); + translate = glm::translate(translate, -Position); viewMatrix = rotate * translate; + // Work out Look Vector + glm::mat4 inverseView = glm::inverse(viewMatrix); + + LookDirection.x = inverseView[2][0]; + LookDirection.y = inverseView[2][1]; + LookDirection.z = inverseView[2][2]; + } glm::mat4 Camera::GetViewMatrix() { @@ -52,12 +61,6 @@ void Camera::UpdateProjection(int width, int height) { } -glm::vec3 Camera::GetPos() { - - return eyeVector; - -} - void Camera::HandleMouse(SDL_Event e) { if (e.type != SDL_MOUSEMOTION) @@ -118,9 +121,10 @@ void Camera::MoveCamera(Uint8* state) { // forward vector must be negative to look forward. // read :http://in2gpu.com/2015/05/17/view-matrix/ - eyeVector.x += dx * CameraSpeed; - eyeVector.z += dz * CameraSpeed; - eyeVector.y += dy * CameraSpeed; + Position.x += dx * CameraSpeed; + Position.z += dz * CameraSpeed; + Position.y += dy * CameraSpeed; + // update the view matrix UpdateView(); diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 39f41d4..04f0403 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -11,9 +11,8 @@ public: glm::mat4 GetViewMatrix(); glm::mat4 GetProjectionMatrix(); - void UpdateProjection(int width, int height); - glm::vec3 GetPos(); + void UpdateProjection(int width, int height); void HandleMouse(SDL_Event e); void MoveCamera(Uint8* state); @@ -22,9 +21,11 @@ public: float MouseSensitivity = 0.1f; float CameraSpeed = 0.2f; + glm::vec3 Position = {}; + glm::vec3 LookDirection = {}; + private: float roll, pitch, yaw; - glm::vec3 eyeVector = {}; glm::mat4 viewMatrix = {}; glm::mat4 projMatrix = {}; diff --git a/src/world/world.cpp b/src/world/world.cpp index f1f5fb5..a28203b 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -1,3 +1,22 @@ #include "world.hpp" +World::World() { + +} + +void World::LoadWorld() { + +} + +void World::SetTextureMap(GLuint map) { + +} + +glm::vec2 World::GetChunkCoords(glm::vec3) { + +} + +std::vector> World::GetRenderableChunks() { + +} diff --git a/src/world/world.hpp b/src/world/world.hpp index 2c2e134..4a0d070 100644 --- a/src/world/world.hpp +++ b/src/world/world.hpp @@ -13,6 +13,16 @@ class Chunk; class World { public: + World(); + + void LoadWorld(); + + void SetTextureMap(GLuint map); + + // Takes world coordinates and gets a chunks coordinates + glm::vec2 GetChunkCoords(glm::vec3); + + std::vector> GetRenderableChunks(); private: @@ -24,6 +34,9 @@ private: std::vector m_generatorThreads; + // Chuks + + std::vector> m_renderableChunks; std::unordered_map> m_chunks; };