rotate_left - 1Fr3aK2/Cub3d GitHub Wiki

📝 rotate_left

Applies a left rotation to the player by updating the camera plane angle and recomputing the direction vector based on the new orientation.

⚙️ Parameters

Parameter Type Description
data t_data* Pointer to the main game state structure containing the player information.

🔁 Returns

Return value Description
void This function does not return a value; it directly updates the player's rotation and direction vectors.

📖 Description

The rotate_left function rotates the player to the left by subtracting a constant rotation value (ROT) from the player's camera plane angle (plane_x).
After adjusting the angle, it recalculates the player's direction vector:

  • dir_x becomes cos(plane_x)
  • dir_y becomes sin(plane_x)

This ensures the player's orientation is correctly updated for movement and raycasting calculations.

The function operates directly on the player stored inside the t_data structure, making it part of the real-time input and movement system.
It is typically called when the player presses the rotate-left key, causing the player's view to smoothly turn counterclockwise.

💡 Example Usage

// Rotate the player left based on the predefined ROT constant
rotate_left(data);

// Debug: print updated direction
printf("New direction: (%.2f, %.2f)\n", data->player.dir_x, data->player.dir_y);