From 859aef604c810826dfbb3a5afb2836645b198d9c Mon Sep 17 00:00:00 2001 From: Ben Kyd Date: Tue, 12 Nov 2019 14:56:46 +0000 Subject: [PATCH] is anyone here? --- resources/shaders/simple.frag | 2 +- src/physics/collider.hpp | 2 +- src/renderer/camera.cpp | 50 +++++++++++++++++++++++++---------- src/renderer/camera.hpp | 6 ++++- src/world/chunk/chunk.cpp | 2 +- src/world/entity.cpp | 16 +++++++++-- src/world/entity.hpp | 2 +- src/world/world.cpp | 4 +-- 8 files changed, 61 insertions(+), 23 deletions(-) diff --git a/resources/shaders/simple.frag b/resources/shaders/simple.frag index 2010616..0127390 100644 --- a/resources/shaders/simple.frag +++ b/resources/shaders/simple.frag @@ -12,7 +12,7 @@ uniform sampler2DArray tex; void main() { outColour = texture(tex, TexCoord); - //outColour = vec4(.9, .9, .9, 1); + // outColour = vec4(.9, .9, .9, 1); if (outColour.w == .0) discard; diff --git a/src/physics/collider.hpp b/src/physics/collider.hpp index 62c3c97..3fb3f2f 100644 --- a/src/physics/collider.hpp +++ b/src/physics/collider.hpp @@ -9,6 +9,7 @@ public: glm::vec3 Max; }; +// TODO: Trees class EntityCollider { public: @@ -30,5 +31,4 @@ private: }; - #endif diff --git a/src/renderer/camera.cpp b/src/renderer/camera.cpp index ea36db2..192d5df 100644 --- a/src/renderer/camera.cpp +++ b/src/renderer/camera.cpp @@ -4,9 +4,9 @@ Camera::Camera() { projMatrix = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 1000.0f); - roll = 0.0f; - pitch = 0.0f; - yaw = 0.0f; + Roll = 0.0f; + Pitch = 0.0f; + Yaw = 0.0f; Position = {}; LookDirection = {}; @@ -19,9 +19,9 @@ Camera::Camera(int w, int h) { projMatrix = glm::perspective(glm::radians(45.0f), (float)w / float(h), 0.1f, 1000.0f); - roll = 0.0f; - pitch = 0.0f; - yaw = 0.0f; + Roll = 0.0f; + Pitch = 0.0f; + Yaw = 0.0f; Position = {}; LookDirection = {}; @@ -38,9 +38,9 @@ void Camera::UpdateView() { glm::mat4 matYaw = glm::mat4(1.0f); //identity matrix // roll, pitch and yaw - matRoll = glm::rotate(matRoll, roll, glm::vec3(0.0f, 0.0f, 1.0f)); - matPitch = glm::rotate(matPitch, pitch, glm::vec3(1.0f, 0.0f, 0.0f)); - matYaw = glm::rotate(matYaw, yaw, glm::vec3(0.0f, 1.0f, 0.0f)); + matRoll = glm::rotate(matRoll, Roll, glm::vec3(0.0f, 0.0f, 1.0f)); + matPitch = glm::rotate(matPitch, Pitch, glm::vec3(1.0f, 0.0f, 0.0f)); + matYaw = glm::rotate(matYaw, Yaw, glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 rotate = matRoll * matPitch * matYaw; @@ -99,8 +99,8 @@ void Camera::MoveCamera(Uint8* state) { // Rotate by camera direction glm::mat2 rotate { - cos(yaw), -sin(yaw), - sin(yaw), cos(yaw) + cos(Yaw), -sin(Yaw), + sin(Yaw), cos(Yaw) }; glm::vec2 f(0.0, 1.0); @@ -149,11 +149,33 @@ void Camera::MouseMoved(glm::vec2 mouseDelta) { // note that yaw and pitch must be converted to radians. // this is done in UpdateView() by glm::rotate - yaw += MouseSensitivity * (mouseDelta.x/100); - pitch += MouseSensitivity * (mouseDelta.y/100); - pitch = glm::clamp(pitch, -M_PI/2, M_PI/2); + Yaw += MouseSensitivity * (mouseDelta.x/100); + Pitch += MouseSensitivity * (mouseDelta.y/100); + Pitch = glm::clamp(Pitch, -M_PI/2, M_PI/2); UpdateView(); } +void Camera::UpdatePosition(glm::vec3 position) { + + Position = position; + +} + +void Camera::UpdateEulerLookDirection(float roll, float pitch, float yaw) { + + Roll = roll; Pitch = pitch; Yaw = yaw; + LookDirection.x = cos(Yaw) * cos(Pitch); + LookDirection.y = sin(Yaw) * cos(Pitch); + LookDirection.z = sin(Pitch); + +} + +void Camera::UpdateLookDirection(glm::vec3 lookDirection) { + + LookDirection = lookDirection; + // TODO: calculate euler values from + // look unit vector + +} diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 2fa5c35..5783e57 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -22,11 +22,15 @@ public: float MouseSensitivity = 0.1f; float CameraSpeed = 2.0f; + void UpdatePosition(glm::vec3 position); + void UpdateEulerLookDirection(float roll, float pitch, float yaw); + void UpdateLookDirection(glm::vec3 lookDirection); + glm::vec3 Position = {}; + float Roll, Pitch, Yaw; glm::vec3 LookDirection = {}; private: - float roll, pitch, yaw; glm::mat4 viewMatrix = {}; glm::mat4 projMatrix = {}; diff --git a/src/world/chunk/chunk.cpp b/src/world/chunk/chunk.cpp index 8284e0d..1c06640 100644 --- a/src/world/chunk/chunk.cpp +++ b/src/world/chunk/chunk.cpp @@ -53,7 +53,7 @@ Chunk::Chunk(int x, int z, std::shared_ptr terrainGenerator) { continue; } - if (pow(y / (float)CHUNK_HEIGHT, 1.1024f) + terrainGenerator->GetValueFractal(x + (Z * CHUNK_WIDTH), y, z + (X * CHUNK_DEPTH)) * 0.60f < 0.5f) { + if (pow(y / (float)CHUNK_HEIGHT, 1.1024f) + terrainGenerator->GetNoise(x + (Z * CHUNK_WIDTH), y, z + (X * CHUNK_DEPTH)) * 0.60f < 0.5f) { Voxels.push_back((uint8_t)EBlockType::Grass); continue; diff --git a/src/world/entity.cpp b/src/world/entity.cpp index cc7332d..d41965c 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) { + } +void Player::Move(Uint8* state) { + +} + +void Player::HandleMouseSDL(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..e994d67 100644 --- a/src/world/entity.hpp +++ b/src/world/entity.hpp @@ -39,7 +39,7 @@ public: Player(glm::vec3 position, glm::vec3 direction = {0.0f, 0.0f, 0.0f}); void Move(Uint8* state); - void HandleMouse(SDL_Event e); + void HandleMouseSDL(SDL_Event e); void UpdatePosition(glm::vec3 position); void UpdateDirection(glm::vec3 direction); diff --git a/src/world/world.cpp b/src/world/world.cpp index ff7b317..ef02b4a 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -24,9 +24,9 @@ void World::LoadWorld() { m_noiseGenerator = std::make_shared(); m_noiseGenerator->SetSeed(rand()); - m_noiseGenerator->SetNoiseType(FastNoise::SimplexFractal); + m_noiseGenerator->SetNoiseType(FastNoise::Perlin); - m_noiseGenerator->SetFractalOctaves(5); + m_noiseGenerator->SetFractalOctaves(8); for (int x = -4; x < 50; x++) for (int y = -50; y < 4; y++) {