diff --git a/include/render/frustum.h b/include/render/frustum.h index 8cf8682..8ac3883 100644 --- a/include/render/frustum.h +++ b/include/render/frustum.h @@ -34,7 +34,8 @@ class frustum { } [[nodiscard]] inline float distance(const blt::vec3& point) const { - return m_A * point.x() + m_B * point.y() + m_C * point.z() + m_D; + auto dist = m_A * point.x() + m_B * point.y() + m_C * point.z() + m_D; + return dist; } [[nodiscard]] inline float A() const { return m_A; } @@ -111,8 +112,9 @@ class frustum { // std::all_of ?? for (auto plane : planes){ // point is outside plane - if (plane.distance(point) < 0) + if (plane.distance(point) < 0) { return false; + } } return true; } diff --git a/src/render/gl.cpp b/src/render/gl.cpp index 4adca75..4ed22d9 100644 --- a/src/render/gl.cpp +++ b/src/render/gl.cpp @@ -62,15 +62,15 @@ namespace fp::_static { } const blt::mat4x4& fp::getViewMatrix() { - return _static::projectionMatrix; + return _static::viewMatrix; } const blt::mat4x4& fp::getProjectionMatrix() { - return _static::orthographicMatrix; + return _static::projectionMatrix; } const blt::mat4x4& fp::getOrthographicMatrix() { - return _static::viewMatrix; + return _static::orthographicMatrix; } namespace fp { diff --git a/src/world/world.cpp b/src/world/world.cpp index 5d4aa7b..7391cd2 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -174,12 +174,16 @@ void fp::world::render(fp::shader& shader) { } auto cp = blt::vec3{(float)adjusted_chunk_pos.x, (float)adjusted_chunk_pos.y, (float)adjusted_chunk_pos.z}; - auto cp2 = cp + blt::vec3{CHUNK_SIZE, CHUNK_SIZE, CHUNK_SIZE}; - if (view_frustum.cubeInside(cp, cp2)) + auto cp2 = cp + blt::vec3{CHUNK_SIZE, 0, 0}; + auto cp3 = cp + blt::vec3{0, CHUNK_SIZE, 0}; + auto cp4 = cp + blt::vec3{0, 0, CHUNK_SIZE}; + auto cp5 = cp + blt::vec3{CHUNK_SIZE, CHUNK_SIZE, CHUNK_SIZE}; + if (view_frustum.pointInside(cp) || view_frustum.pointInside(cp2) || view_frustum.pointInside(cp3) || view_frustum.pointInside(cp4) || view_frustum.pointInside(cp5)) chunk->render(shader); } } } + //std::cout << "0,0,0 in frustum? " << view_frustum.pointInside(blt::vec3{0,0,0}) << "\n"; } fp::chunk* fp::world::generateChunk(const fp::chunk_pos& pos) {