🔍 YOUR CODE TRACE

fix_dist = use_distance(delta_x, delta_y) * cos(angle)
Your function:
float use_fixed_dist(float x2, float y2, t_cub *game)
{
    float delta_x, delta_y, angle, fix_dist;
    delta_x = x2 - game->player.x;
    delta_y = y2 - game->player.y;
    angle = atan2(delta_y, delta_x) - game->player.angle;
    fix_dist = use_distance(delta_x, delta_y) * cos(angle);
    return (fix_dist);
}

delta_x

100
x2 - player.x

delta_y

50
y2 - player.y

use_distance

111.8
√(delta_x² + delta_y²)

angle

26.57°
atan2(delta_y, delta_x) - player.angle

fix_dist

100.0
use_distance * cos(angle)
STEP 1: Calculate delta_x and delta_y
delta_x = x2 - game->player.x
delta_y = y2 - game->player.y

These are the horizontal and vertical distances from player to target point.

STEP 2: Calculate angle
angle = atan2(delta_y, delta_x) - game->player.angle

atan2(delta_y, delta_x) = angle from player to target
- game->player.angle = subtract player's current facing direction
Result: angle difference between where player is looking and where target is

STEP 3: Calculate use_distance
use_distance(delta_x, delta_y) = sqrt(delta_x * delta_x + delta_y * delta_y)

This is the straight-line distance from player to target (Pythagorean theorem).

STEP 4: Apply cosine correction
fix_dist = use_distance(delta_x, delta_y) * cos(angle)

cos(angle) corrects for the viewing angle.
If target is directly in front (angle=0°), cos(0°)=1, so full distance counts.
If target is to the side (angle=90°), cos(90°)=0, so no distance counts.

🎯 WHY THIS IS USED

This is for raycasting in 3D games! It prevents the "fisheye effect":

This makes the 3D world look realistic instead of curved like a fisheye lens!