Raycasting Loop Analysis

x = 0;
while (x < WIDTH)
{
    cast_ray(cub, ray_angle, x);
    ray_angle += ray_step;
    x++;
}

↑ Simulated Screen Output (each column from one ray)

Ray: 0 / 120

Current Step:

Ready to start

Variables:

x = 0
ray_angle = -30°
ray_step = 0.5°

What happens each iteration:

  1. cast_ray(): Shoots ray at current angle, finds wall hit, draws vertical line at screen position x
  2. ray_angle += ray_step: Move to next angle (rotate right)
  3. x++: Move to next screen column

Why this works:

  • Each ray corresponds to one screen column
  • Angles sweep smoothly across FOV
  • Left-to-right casting builds complete image
  • Distance determines wall height