Screen Coordinates
Origin: Top-Left
X: Left → Right
Y: Top → Bottom
Math Coordinates
Origin: Center
X: Left → Right
Y: Bottom → Top
⚠️ Coordinate System Difference:
In computer graphics, Y increases downward. In math, Y increases upward.
This affects how angles are interpreted but sin/cos still work correctly!
🎯 Interactive Ray Parameter Calculator
Click anywhere to set ray direction. Grid shows map blocks.
ray_dir_x/y: Direction vector components (unit vector)
map_x/y: Current map grid cell coordinates
delta_dist_x/y: Distance ray travels to cross one grid line
pos_x/y: Exact player position in world coordinates
🧮 The Deep Math: Why Delta Distance = 1/ray_dir?
Delta Distance X
delta_dist_x = |1 / ray_dir_x|
This is the distance the ray travels to move exactly 1 unit in the X direction.
If ray_dir_x = 1 (horizontal ray): delta = 1
If ray_dir_x = 0.5 (shallow angle): delta = 2
If ray_dir_x = 0.1 (steep angle): delta = 10
Delta Distance Y
delta_dist_y = |1 / ray_dir_y|
This is the distance the ray travels to move exactly 1 unit in the Y direction.
If ray_dir_y = 1 (vertical ray): delta = 1
If ray_dir_y = 0.5 (shallow angle): delta = 2
If ray_dir_y = 0.1 (steep angle): delta = 10
Visualization of delta distances: How far ray travels to cross grid lines
💡 Why This Matters for DDA:
The DDA algorithm steps through grid cells efficiently. Delta distances tell us exactly
how far to step when crossing each grid line, making collision detection fast and accurate.
🚨 Division by Zero Protection:
If ray_dir_x or ray_dir_y is 0 (perfectly horizontal/vertical ray), 1/0 = infinity.
The fabs() handles this, and the DDA algorithm is designed to handle infinite delta distances.