Improve ship nickname rendering
This commit is contained in:
1 parent
e18484ea62
commit
e050d7d0ec
7 files changed
+45
-29
No files matched your search
+14
-12
@@ -756,26 +756,28 @@ namespace ZL
|
||||
// Позиция корабля в мире
|
||||
Vector3f shipWorld = st.position;
|
||||
|
||||
// Значение положения лейбла
|
||||
Vector3f labelWorld = shipWorld + Vector3f{ 0.0f, -5.0f, 0.0f };
|
||||
|
||||
float distSq = (Environment::shipState.position - shipWorld).squaredNorm();
|
||||
if (distSq > MAX_DIST_SQ)
|
||||
continue;
|
||||
float dist = sqrt(distSq);
|
||||
float alpha = std::clamp(1.f - (dist - FADE_START) / FADE_RANGE, 0.f, 1.f);
|
||||
if (alpha < 0.01f)
|
||||
continue;
|
||||
Vector3f labelWorld = shipWorld + Vector3f{ 0.f, -4.f, 0.f }; // регулировка высоты
|
||||
float sx, sy, depth;
|
||||
if (!worldToScreen(labelWorld, sx, sy, depth))
|
||||
continue;
|
||||
|
||||
float uiX = sx;
|
||||
float uiY = sy;
|
||||
|
||||
// Масштаб по расстоянию
|
||||
float dist = (Environment::shipState.position - shipWorld).norm();
|
||||
float scale = std::clamp(140.0f / (dist + 1.0f), 0.6f, 1.2f);
|
||||
|
||||
float uiX = sx, uiY = sy;
|
||||
float scale = std::clamp(BASE_SCALE / (dist * PERSPECTIVE_K + 1.f), MIN_SCALE, MAX_SCALE);
|
||||
|
||||
// Дефолтный лейбл
|
||||
std::string label = "Player (" + std::to_string(st.id) + ")";
|
||||
std::string label = "Player (" + std::to_string(st.id) + ") " + std::to_string((int)dist) + "m";
|
||||
|
||||
// TODO: nickname sync
|
||||
|
||||
textRenderer->drawText(label, uiX, uiY, scale, true);
|
||||
textRenderer->drawText(label, uiX + 1.f, uiY + 1.f, scale, true, {0.f, 0.f, 0.f, alpha}); // color param
|
||||
textRenderer->drawText(label, uiX, uiY, scale, true, { 1.f, 1.f, 1.f, alpha });
|
||||
}
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
Reference in new issue
Block a user