mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
feat(player): reimplemented angles
This commit is contained in:
parent
e46f199606
commit
b6eeea5e9f
3 changed files with 42 additions and 5 deletions
|
|
@ -6,11 +6,43 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/24 14:41:35 by tchampio #+# #+# */
|
||||
/* Updated: 2025/07/29 12:21:27 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/07/29 19:47:18 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_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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/24 14:46:11 by tchampio #+# #+# */
|
||||
/* Updated: 2025/07/24 14:48:52 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/07/29 19:34:34 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
# include "../cub3d_data.h"
|
||||
# include "../consts.h"
|
||||
|
||||
void apply_angle(int key, t_cub3d_data *data);
|
||||
void turn_left_angle(t_cub3d_data *data);
|
||||
void turn_right_angle(t_cub3d_data *data);
|
||||
|
||||
#endif // ANGLE_H
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/29 13:58:00 by tchampio #+# #+# */
|
||||
/* Updated: 2025/07/29 14:52:54 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/07/29 19:47:38 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d_data.h"
|
||||
#include "angle.h"
|
||||
#include "../consts.h"
|
||||
#include <stdio.h> // bad
|
||||
|
||||
void move_player_forward(t_cub3d_data *data)
|
||||
{
|
||||
|
|
@ -84,4 +84,8 @@ void move_player(t_cub3d_data *data)
|
|||
move_player_strafe_left(data);
|
||||
if (data->keypresses.is_d_pressed)
|
||||
move_player_strafe_right(data);
|
||||
if (data->keypresses.is_left_pressed)
|
||||
turn_left_angle(data);
|
||||
if (data->keypresses.is_right_pressed)
|
||||
turn_right_angle(data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue