From f2c571b10ba6f15361a74fbbfe17f0f5de08231c Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 5 Nov 2019 23:46:02 +0000 Subject: [PATCH 1/2] collision --- CMakeLists.txt | 2 +- resources/shaders/simple.frag | 2 +- src/physics/collider.cpp | 35 +++++++++++++++++++++++++++++++++++ src/physics/collider.hpp | 34 ++++++++++++++++++++++++++++++++++ src/renderer/camera.hpp | 2 +- src/world/entity.hpp | 24 ++++++++++++++++++++++++ src/world/world.cpp | 6 +++--- 7 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src/physics/collider.cpp create mode 100644 src/physics/collider.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a85e8d..77888f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CMakeModules/) cmake_policy(SET CMP0037 OLD) set(CMAKE_BUILD_TYPE Debug) -# set(CMAKE_CXX_FLAGS "-Ofast") +set(CMAKE_CXX_FLAGS "-Ofast") set(executable output) set(SrcDIR ./src) diff --git a/resources/shaders/simple.frag b/resources/shaders/simple.frag index 949c2ec..2010616 100644 --- a/resources/shaders/simple.frag +++ b/resources/shaders/simple.frag @@ -17,7 +17,7 @@ void main() { if (outColour.w == .0) discard; - float fogMax = 60000; + float fogMax = 200000; vec3 colour = mix(outColour.xyz, SkyColour, min(1.0f, Distance / fogMax)); diff --git a/src/physics/collider.cpp b/src/physics/collider.cpp new file mode 100644 index 0000000..9ec5801 --- /dev/null +++ b/src/physics/collider.cpp @@ -0,0 +1,35 @@ +#include "collider.hpp" + +EntityCollider::EntityCollider() { + +} + +glm::vec3 EntityCollider::TerrainCollide(std::vector terrain) { + + + +} + +bool EntityCollider::m_aabb(ColliderBox a, ColliderBox b) { + + return { + (a.Min.x <= b.Min.x + b.Max.x && a.Min.x + a.Max.x >= b.Min.x) && + (a.Min.y <= b.Min.y + b.Max.y && a.Min.y + a.Max.y >= b.Min.y) && + (a.Min.z <= b.Min.z + b.Max.z && a.Min.z + a.Max.z >= b.Min.z) + }; + +} + +float EntityCollider::m_xDepth(ColliderBox a, ColliderBox b) { + +} + + +float EntityCollider::m_yDepth(ColliderBox a, ColliderBox b) { + +} + + +float EntityCollider::m_zDepth(ColliderBox a, ColliderBox b) { + +} diff --git a/src/physics/collider.hpp b/src/physics/collider.hpp new file mode 100644 index 0000000..62c3c97 --- /dev/null +++ b/src/physics/collider.hpp @@ -0,0 +1,34 @@ +#ifndef MINECRAFT_PHYSICS_COLLIDER_H_ +#define MINECRAFT_PHYSICS_COLLIDER_H_ + +#include "../common.hpp" + +class ColliderBox { +public: + glm::vec3 Min; + glm::vec3 Max; +}; + +class EntityCollider { +public: + + EntityCollider(); + + // Surrounding blocks indexed XYZ + // Returns point of collision + glm::vec3 TerrainCollide(std::vector surroundingBlocks); + + ColliderBox Bounds; + +private: + + bool m_aabb(ColliderBox a, ColliderBox b); + + float m_xDepth(ColliderBox a, ColliderBox b); + float m_yDepth(ColliderBox a, ColliderBox b); + float m_zDepth(ColliderBox a, ColliderBox b); + +}; + + +#endif diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 04f0403..06e0bde 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -19,7 +19,7 @@ public: void MouseMoved(glm::vec2 mouseDelta); float MouseSensitivity = 0.1f; - float CameraSpeed = 0.2f; + float CameraSpeed = 2.0f; glm::vec3 Position = {}; glm::vec3 LookDirection = {}; diff --git a/src/world/entity.hpp b/src/world/entity.hpp index 7848976..cc03f15 100644 --- a/src/world/entity.hpp +++ b/src/world/entity.hpp @@ -1,5 +1,29 @@ #ifndef MINECRAFT_WORLD_ENTITY_H_ #define MINECRAFT_WORLD_ENTITY_H_ +#include "../common.hpp" + +class Entity { +public: + + Entity(); + + // World position + glm::vec3 Position; + // Look direction + glm::vec3 Direction; + + // Velocity in direction + // of movement + glm::vec3 Velocity; + + // Collider + + + // Mesh (or reference to) + + + +}; #endif diff --git a/src/world/world.cpp b/src/world/world.cpp index cf5a755..92c2a53 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -26,15 +26,15 @@ void World::LoadWorld() { m_noiseGenerator->SetFractalOctaves(5); - for (int x = -4; x < 10; x++) - for (int y = -4; y < 4; y++) { + for (int x = -4; x < 50; x++) + for (int y = -50; y < 4; y++) { m_chunkLoaderQueue.push({ x, y }); } // Spawn generator threads - for (int i = 0; i < 7; i++) { + for (int i = 0; i < 6; i++) { m_generatorThreads.push_back(std::thread([&]() { From 044a61e069fa734c8cb1ea64ca9a078df5623c4a Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 6 Nov 2019 00:10:43 +0000 Subject: [PATCH 2/2] added trello to readme --- README.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7f2a6cd..03efeae 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,11 @@ A Minecraft clone written in C++ with OpenGL ### Development Checklist -### Trello coming soon +#### Trello: -- [X] Block atlas -- [X] Texturing faces -- [X] Mesh chunks -- [X] Fog -- [ ] Fustrum culling -- [ ] Chunk generation around the player -- [X] Threaded chunk generation -- [ ] Player collision -- [ ] Player cursor -- [ ] Procedural world generation -- [ ] . . . +All of the projects progress will be tracked here + +https://trello.com/b/jpGIDFKm/minecraft Even after this initial short checklist there will be a lot to implement to have a playable minecraft clone, its really there so you can see the development stage of the renderer.