set_player_direction - 1Fr3aK2/Cub3d GitHub Wiki

๐Ÿ“ set_player_direction

Initializes the playerโ€™s facing direction using trigonometric values computed from a predefined angle based on the starting direction ('N', 'S', 'E', or 'W').
This function configures the player orientation by calling set_directions() with the calculated cosine, sine, and angle values.


โš™๏ธ Parameters

Parameter Type Description
player t_player* Pointer to the player structure whose direction vectors will be initialized.
dir char Character representing the starting direction ('N', 'S', 'E', or 'W').

๐Ÿ” Returns

Return value Description
void This function does not return a value; it updates the player's direction internally.

๐Ÿ“– Description

The set_player_direction function determines the playerโ€™s initial orientation angle based on the direction character and uses trigonometric functions (cos() and sin()) to calculate the appropriate direction vector.

It then passes these computed values to the helper function set_directions() alongside the angle used for calculation.

Direction Angles Used

Direction Angle Used Explanation
'N' 3 * PI / 2 Facing upward (north) in radian-based orientation system.
'S' PI / 2 Facing downward (south).
'E' 2 * PI Facing east (full rotation โ†’ angle = 0 rad).
'W' PI Facing west.

The cosine and sine of each angle compute the direction vector:

cos(angle) โ†’ dir_x
sin(angle) โ†’ dir_y