planet is closed

This commit is contained in:
Vladislav Khorev 2025-12-13 20:34:47 +03:00
parent 2b6af91992
commit 27fb7a448c
4 changed files with 43 additions and 20 deletions

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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<float, float> 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<Texture>(CreateTextureDataFromPng("./resources/sand.png", ""));
sandTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/rock.png", ""));
sandTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/sand.png", ""));
//sandTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/rock.png", ""));
}

View File

@ -59,6 +59,8 @@ namespace ZL {
void draw(Renderer& renderer);
bool planetIsFar(const Vector3f& shipPosition);
private:
bool drawDataDirty = true;