space warp fixes

This commit is contained in:
2025-12-10 17:57:32 +01:00
parent 57eac01bcb
commit e8a7b19213
3 changed files with 41 additions and 7 deletions

View File

@ -163,14 +163,22 @@ void Starfield3D::drawStar(SDL_Renderer* renderer, float x, float y, SDL_Color c
}
void Starfield3D::draw(SDL_Renderer* renderer, float offsetX, float offsetY, float alphaScale, bool grayscale) {
// Small visual jitter applied to the visual center so a single bright star
// doesn't remain perfectly fixed at the exact pixel center of the viewport.
const float jitterAmp = 1.6f; // max pixel offset
const uint32_t now = SDL_GetTicks();
const float tms = static_cast<float>(now) * 0.001f;
const float centerJitterX = std::sin(tms * 1.7f) * jitterAmp + std::cos(tms * 0.9f) * 0.4f;
const float centerJitterY = std::sin(tms * 1.1f + 3.7f) * (jitterAmp * 0.6f);
const bool useMagnet = magnetActive && magnetStrength > 0.0f;
for (const Star3D& star : stars) {
// Calculate perspective projection factor
const float k = DEPTH_FACTOR / star.z;
// Calculate screen position with perspective
float px = star.x * k + centerX;
float py = star.y * k + centerY;
float px = star.x * k + centerX + centerJitterX;
float py = star.y * k + centerY + centerJitterY;
if (useMagnet) {
float dx = magnetX - px;