Raycasting Loop Analysis
x = 0;
while (x < WIDTH)
{
cast_ray(cub, ray_angle, x);
ray_angle += ray_step;
x++;
}
Step Forward
Step Back
Auto Step
Reset
Complete Loop
↑ 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:
cast_ray()
: Shoots ray at current angle, finds wall hit, draws vertical line at screen position x
ray_angle += ray_step
: Move to next angle (rotate right)
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