mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
55 lines
2 KiB
C
55 lines
2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* angle.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/07/24 14:41:35 by tchampio #+# #+# */
|
|
/* Updated: 2025/07/29 20:09:55 by tchampio ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <X11/keysym.h>
|
|
#include <X11/X.h>
|
|
#include "../cub3d_data.h"
|
|
#include "../consts.h"
|
|
#include <math.h>
|
|
#include "player.h"
|
|
|
|
void turn_right_angle(t_cub3d_data *data)
|
|
{
|
|
t_player *p;
|
|
double prev_dir_x;
|
|
double prev_plane_x;
|
|
|
|
p = &data->player;
|
|
prev_dir_x = p->dir_x;
|
|
prev_plane_x = p->plane_x;
|
|
p->dir_x = p->dir_x * cos(ROTATION_SPEED) - p->dir_y * sin(ROTATION_SPEED);
|
|
p->dir_y = prev_dir_x * sin(ROTATION_SPEED)
|
|
+ p->dir_y * cos(ROTATION_SPEED);
|
|
p->plane_x = p->plane_x * cos(ROTATION_SPEED)
|
|
- p->plane_y * sin(ROTATION_SPEED);
|
|
p->plane_y = prev_plane_x * sin(ROTATION_SPEED)
|
|
+ p->plane_y * cos(ROTATION_SPEED);
|
|
}
|
|
|
|
void turn_left_angle(t_cub3d_data *data)
|
|
{
|
|
t_player *p;
|
|
double prev_dir_x;
|
|
double prev_plane_x;
|
|
|
|
p = &data->player;
|
|
prev_dir_x = p->dir_x;
|
|
prev_plane_x = p->plane_x;
|
|
p->dir_x = p->dir_x * cos(-ROTATION_SPEED)
|
|
- p->dir_y * sin(-ROTATION_SPEED);
|
|
p->dir_y = prev_dir_x * sin(-ROTATION_SPEED)
|
|
+ p->dir_y * cos(-ROTATION_SPEED);
|
|
p->plane_x = p->plane_x * cos(-ROTATION_SPEED)
|
|
- p->plane_y * sin(-ROTATION_SPEED);
|
|
p->plane_y = prev_plane_x * sin(-ROTATION_SPEED)
|
|
+ p->plane_y * cos(-ROTATION_SPEED);
|
|
}
|