diff options
Diffstat (limited to 'src/RendererWorld.cpp')
-rw-r--r-- | src/RendererWorld.cpp | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index aa64dc0..5d0d6a8 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -148,7 +148,6 @@ void RendererWorld::UpdateAllSections(VectorF playerPos) { RendererWorld::RendererWorld(GameState* ptr) { gs = ptr; - frustum = std::make_unique<Frustum>(); MaxRenderingDistance = 2; numOfWorkers = _max(1, (signed int) std::thread::hardware_concurrency() - 2); @@ -396,38 +395,19 @@ void RendererWorld::Render(RenderState & renderState) { glUniform2f(windowSizeLoc, renderState.WindowWidth, renderState.WindowHeight); glCheckError(); - frustum->UpdateFrustum(projView); + Frustum frustum(projView); size_t culledSections = sections.size(); - for (auto& section : sections) { - const static Vector sectionCorners[] = { - Vector(0, 0, 0), - Vector(0, 0, 16), - Vector(0, 16, 0), - Vector(0, 16, 16), - Vector(16, 0, 0), - Vector(16, 0, 16), - Vector(16, 16, 0), - Vector(16, 16, 16), - }; - bool isVisible = false; - for (const auto &it : sectionCorners) { - VectorF point(section.second.GetPosition().x * 16 + it.x, - section.second.GetPosition().y * 16 + it.y, - section.second.GetPosition().z * 16 + it.z); - if (frustum->TestPoint(point)) { - isVisible = true; - break; - } - } - - double lengthToSection = (gs->player->pos - - VectorF(section.first.x*16, - section.first.y*16, - section.first.z*16) - ).GetLength(); + for (auto& section : sections) { + glm::vec3 point{ + section.second.GetPosition().x * 16 + 8, + section.second.GetPosition().y * 16 + 8, + section.second.GetPosition().z * 16 + 8 + }; + + bool isVisible = frustum.TestSphere(point, 16.0f); - if (!isVisible && lengthToSection > 30.0f) { + if (!isVisible) { culledSections--; continue; } |