From 27fb7a448c77a2b5cd3c73b1aabc88382a54e155 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Sat, 13 Dec 2025 20:34:47 +0300 Subject: [PATCH] planet is closed --- Environment.cpp | 6 +++--- Game.cpp | 18 +++++++++++++++--- PlanetObject.cpp | 37 +++++++++++++++++++++++-------------- PlanetObject.h | 2 ++ 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/Environment.cpp b/Environment.cpp index d71c040..7e06bc4 100644 --- a/Environment.cpp +++ b/Environment.cpp @@ -8,7 +8,7 @@ namespace ZL { int Environment::windowHeaderHeight = 0; int Environment::width = 0; int Environment::height = 0; -float Environment::zoom = 14.f; +float Environment::zoom = 18.f; bool Environment::leftPressed = false; bool Environment::rightPressed = false; @@ -36,8 +36,8 @@ Vector3f Environment::shipPosition = {0,0,0}; float Environment::shipVelocity = 0.f; -const float Environment::CONST_Z_NEAR = 10.f; -const float Environment::CONST_Z_FAR = 10000.f; +const float Environment::CONST_Z_NEAR = 5.f; +const float Environment::CONST_Z_FAR = 5000.f; } // namespace ZL diff --git a/Game.cpp b/Game.cpp index fb94ba9..a9af59b 100755 --- a/Game.cpp +++ b/Game.cpp @@ -463,8 +463,12 @@ namespace ZL CheckGlError(); drawCubemap(); - drawShip(); planetObject.draw(renderer); + if (planetObject.planetIsFar(Environment::shipPosition)) + { + glClear(GL_DEPTH_BUFFER_BIT); + } + drawShip(); drawBoxes(); drawUI(); @@ -612,11 +616,19 @@ namespace ZL { if (event.key.keysym.sym == SDLK_i) { - Environment::shipVelocity += 5000.f; + Environment::shipVelocity += 500.f; } if (event.key.keysym.sym == SDLK_k) { - Environment::shipVelocity -= 5000.f; + Environment::shipVelocity -= 500.f; + } + if (event.key.keysym.sym == SDLK_o) + { + Environment::shipVelocity += 50.f; + } + if (event.key.keysym.sym == SDLK_l) + { + Environment::shipVelocity -= 50.f; } } } diff --git a/PlanetObject.cpp b/PlanetObject.cpp index 74861eb..a483d2c 100644 --- a/PlanetObject.cpp +++ b/PlanetObject.cpp @@ -6,30 +6,30 @@ namespace ZL { - static constexpr float PLANET_RADIUS = 100000.f; - static Vector3f PLANET_CENTER_OFFSET = Vector3f{ 0.f, 0.f, -225000.f }; + static constexpr float PLANET_RADIUS = 20000.f; + static Vector3f PLANET_CENTER_OFFSET = Vector3f{ 0.f, 0.f, -45000.f }; // --- 1. Дальний диапазон (FAR) --- - static constexpr float FAR_Z_NEAR = 5000.0f; - static constexpr float FAR_Z_FAR = 1000000.0f; + static constexpr float FAR_Z_NEAR = 2000.0f; + static constexpr float FAR_Z_FAR = 200000.0f; // Дистанция, где НАЧИНАЕТСЯ переход FAR -> MIDDLE - static constexpr float TRANSITION_FAR_START = 40000.0f; + static constexpr float TRANSITION_FAR_START = 3000.0f; // --- 2. Средний диапазон (MIDDLE) --- - static constexpr float MIDDLE_Z_NEAR = 1000.f; - static constexpr float MIDDLE_Z_FAR = 200000.f; + static constexpr float MIDDLE_Z_NEAR = 200.f; + static constexpr float MIDDLE_Z_FAR = 20000.f; // Дистанция, где ЗАВЕРШАЕТСЯ переход FAR -> MIDDLE и НАЧИНАЕТСЯ MIDDLE -> NEAR - static constexpr float TRANSITION_MIDDLE_START = 10000.f; + static constexpr float TRANSITION_MIDDLE_START = 500.f; // --- 3. Ближний диапазон (NEAR) --- // Новые константы для максимальной точности - static constexpr float NEAR_Z_NEAR = 200.0f; - static constexpr float NEAR_Z_FAR = 4000.0f; + static constexpr float NEAR_Z_NEAR = 5.0f; + static constexpr float NEAR_Z_FAR = 5000.0f; // Дистанция, где ЗАВЕРШАЕТСЯ переход MIDDLE -> NEAR - static constexpr float TRANSITION_NEAR_END = 10.f; + static constexpr float TRANSITION_NEAR_END = 40.f; std::pair calculateZRange(const Vector3f& shipPosition) { @@ -147,12 +147,21 @@ namespace ZL { // Масштабируем: хотим отклонение от 1.0 до 1.1 // Значит амплитуда = 0.1 - float height = 1.0f + (noiseValue * 0.002f); // * 0.2 даст вариацию высоты + float height = 1.0f + (noiseValue * 0.01f); // * 0.2 даст вариацию высоты return height; } + + bool PlanetObject::planetIsFar(const Vector3f& shipPosition) + { + const Vector3f planetWorldPosition = PLANET_CENTER_OFFSET; + const float distanceToPlanetCenter = (planetWorldPosition - shipPosition).length(); + const float distanceToPlanetSurface = distanceToPlanetCenter - PLANET_RADIUS; + + return distanceToPlanetSurface > 0.1*TRANSITION_MIDDLE_START; + } PlanetObject::PlanetObject() @@ -172,8 +181,8 @@ namespace ZL { planetRenderStruct.data = planetMesh; planetRenderStruct.RefreshVBO(); - //sandTexture = std::make_unique(CreateTextureDataFromPng("./resources/sand.png", "")); - sandTexture = std::make_unique(CreateTextureDataFromPng("./resources/rock.png", "")); + sandTexture = std::make_unique(CreateTextureDataFromPng("./resources/sand.png", "")); + //sandTexture = std::make_unique(CreateTextureDataFromPng("./resources/rock.png", "")); } diff --git a/PlanetObject.h b/PlanetObject.h index a3c0dc1..0d3140c 100644 --- a/PlanetObject.h +++ b/PlanetObject.h @@ -59,6 +59,8 @@ namespace ZL { void draw(Renderer& renderer); + bool planetIsFar(const Vector3f& shipPosition); + private: bool drawDataDirty = true;