🐠 Fishbowl Effect Correction

🎯 Top-Down View

👁️ 3D View

🔬 The Problem & Solution

🐠 The Fishbowl Effect

When casting rays at different angles, walls appear curved instead of straight because we measure the actual distance to each point, not the perpendicular distance to the screen plane.

// Simple Euclidean distance float use_distance(float x, float y) { return sqrt(x * x + y * y); } // Corrected distance float use_fixed_dist(float x2, float y2, t_cub *game) { float delta_x = x2 - game->player.x; float delta_y = y2 - game->player.y; float angle = atan2(delta_y, delta_x) - game->player.angle; float fix_dist = use_distance(delta_x, delta_y) * cos(angle); return fix_dist; }
corrected_distance = actual_distance × cos(angle_difference)

📐 Step-by-Step Breakdown:

  1. Calculate delta vectors: Find the difference between hit point and player position
  2. Find ray angle: Use atan2() to get the angle from player to hit point
  3. Calculate angle difference: Subtract player's facing angle from ray angle
  4. Apply cosine correction: Multiply distance by cos(angle_difference)

❌ Without Correction

Walls appear curved and distorted
Distance varies with viewing angle
Creates unrealistic "fishbowl" effect

✅ With Correction

Walls appear straight and natural
Consistent perpendicular distances
Realistic 3D perspective

🧮 Mathematical Insight

The cosine correction works because we're projecting the actual ray distance onto the viewing plane. This is essentially converting from radial distance (distance along the ray) to perpendicular distance (distance to the projection screen).

Think of it like shining a flashlight at an angle on a wall - the light travels further along the beam than the perpendicular distance to the wall.