rotate_right - 1Fr3aK2/Cub3d GitHub Wiki
📝 rotate_right
Rotates the player's viewing direction to the right by updating the camera plane angle and recalculating the direction vector based on trigonometric functions.
⚙️ Parameters
| Parameter | Type | Description |
|---|---|---|
data |
t_data* |
Pointer to the main game data structure containing the player state. |
🔁 Returns
| Return value | Description |
|---|---|
void |
This function does not return a value; it directly updates the player's rotation inside the t_data structure. |
📖 Description
The rotate_right function updates the player's viewing angle by adding the constant rotation value ROT to the player's plane_x (the angle representing the camera plane orientation).
After updating the angle, the function recalculates the player's direction vector using:
cos(angle)→ updatesdir_xsin(angle)→ updatesdir_y
This ensures that the player's direction always follows the updated rotation, allowing smooth rightward turning during gameplay.
This function is typically called when the player presses the right arrow key or the D key, depending on the control scheme.
🔍 How it works
plane_xis treated as the player's current rotation angle.- Adding
ROTincrements the angle, rotating the viewpoint to the right. - The new direction vector becomes the normalized vector pointing toward this new angle.
💡 Example Usage
// Rotate the player to the right
rotate_right(data);
// Debug output
printf("New direction: (%.2f, %.2f)\n",
data->player.dir_x, data->player.dir_y);
printf("New plane angle: %.2f\n", data->player.plane_x);