From a65fc4406962666c9f8d2dfbeec28632d8181463 Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Thu, 21 Sep 2023 17:13:21 +0200 Subject: [PATCH] renderer: correct distance check --- src/renderer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/renderer.cpp b/src/renderer.cpp index 98d82f3..0c5796c 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -150,9 +150,12 @@ namespace renderer{ for(auto& c : chunks_torender){ //float dist = glm::distance(c->getPosition(), cameraChunkPos); //if(static_cast(dist) <= RENDER_DISTANCE + 1){ - if(abs(c->getPosition().x - cameraChunkPos.x) <= RENDER_DISTANCE && - abs(c->getPosition().y - cameraChunkPos.y) <= RENDER_DISTANCE && - abs(c->getPosition().z - cameraChunkPos.z) <= RENDER_DISTANCE){ + int distx = c->getPosition().x - cameraChunkPos.x; + int disty = c->getPosition().y - cameraChunkPos.y; + int distz = c->getPosition().z - cameraChunkPos.z; + if(distx >= -RENDER_DISTANCE && distx < RENDER_DISTANCE && + disty >= -RENDER_DISTANCE && disty < RENDER_DISTANCE && + distz >= -RENDER_DISTANCE && distz < RENDER_DISTANCE){ if(!c->getState(Chunk::CHUNK_STATE_MESH_LOADED)) continue; // Increase total vertex count @@ -210,7 +213,6 @@ namespace renderer{ render_todelete.push_back(c); } } else{ - std::cout << "chunk at " << glm::to_string(c->getPosition()) << std::endl; // Mark has out of vision and annotate when it started c->setState(Chunk::CHUNK_STATE_OUTOFVISION, true); c->setState(Chunk::CHUNK_STATE_UNLOADED, false);