new background image

This commit is contained in:
2025-12-18 07:20:20 +01:00
parent 0ab7121c5b
commit 989b98002c
11 changed files with 233 additions and 27 deletions

View File

@ -68,9 +68,24 @@ void Starfield3D::setRandomDirection(Star3D& star) {
void Starfield3D::updateStar(int index) {
Star3D& star = stars[index];
star.x = randomFloat(-25.0f, 25.0f);
star.y = randomFloat(-25.0f, 25.0f);
// Avoid spawning stars on (or very near) the view axis. A star with x≈0 and y≈0
// projects to the exact center, and when it happens to be bright it looks like a
// static "big" star.
constexpr float SPAWN_RANGE = 25.0f;
constexpr float MIN_AXIS_RADIUS = 2.5f; // in star-space units
for (int attempt = 0; attempt < 8; ++attempt) {
star.x = randomFloat(-SPAWN_RANGE, SPAWN_RANGE);
star.y = randomFloat(-SPAWN_RANGE, SPAWN_RANGE);
if ((star.x * star.x + star.y * star.y) >= (MIN_AXIS_RADIUS * MIN_AXIS_RADIUS)) {
break;
}
}
// If we somehow still ended up too close, push it out deterministically.
if ((star.x * star.x + star.y * star.y) < (MIN_AXIS_RADIUS * MIN_AXIS_RADIUS)) {
star.x = (star.x < 0.0f ? -1.0f : 1.0f) * MIN_AXIS_RADIUS;
star.y = (star.y < 0.0f ? -1.0f : 1.0f) * MIN_AXIS_RADIUS;
}
star.z = randomFloat(1.0f, MAX_DEPTH);
// Give stars initial velocities in all possible directions
@ -91,6 +106,15 @@ void Starfield3D::updateStar(int index) {
star.vz = -STAR_SPEED * randomFloat(0.8f, 1.2f);
}
}
// Ensure newly spawned stars have some lateral drift so they don't appear to
// "stick" near the center line.
if (std::abs(star.vx) < 0.02f && std::abs(star.vy) < 0.02f) {
const float sx = (star.x < 0.0f ? -1.0f : 1.0f);
const float sy = (star.y < 0.0f ? -1.0f : 1.0f);
star.vx = sx * randomFloat(0.04f, 0.14f);
star.vy = sy * randomFloat(0.04f, 0.14f);
}
star.targetVx = star.vx;
star.targetVy = star.vy;