feat: rotation via deltatime + fix deltatime calculation

This commit is contained in:
Khaïs COLIN 2025-07-31 14:53:18 +02:00
parent 11ea82f935
commit 770f3d5ec0
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
3 changed files with 29 additions and 24 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
/* Updated: 2025/07/31 14:42:33 by tchampio ### ########.fr */
/* Updated: 2025/07/31 15:02:18 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,8 +19,8 @@
# define SIZE 64
# define MAP_SIZE 20
# define RESSOURCE_DIR "ressources"
# define MOVEMENT_SPEED 0.0001
# define ROTATION_SPEED 0.01
# define MOVEMENT_SPEED 0.000005
# define ROTATION_SPEED 0.000002
# define PLANE_VALUE 0.66
# define TEXTURE_SIZE 64
# ifdef BONUS

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/07/31 13:57:08 by tchampio ### ########.fr */
/* Updated: 2025/07/31 15:01:00 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,7 +33,7 @@ int game_loop(t_cub3d_data *data)
{
t_ray ray;
data->delta = (get_milliseconds() - data->last_tick);
data->last_tick = get_milliseconds();
mlx_destroy_image(data->mlx, data->img_data->img);
data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT);
reset_matrix(data);
@ -44,7 +44,8 @@ int game_loop(t_cub3d_data *data)
mlx_put_image_to_window(data->mlx, data->mlx_win,
data->img_data->img, 0, 0);
mlx_string_put(data->mlx, data->mlx_win, 10, 10, 0x00FFFFFF, COMPILED_TEXT);
data->last_tick = get_milliseconds();
data->delta = (get_milliseconds() - data->last_tick);
ft_printf("%d,%d\n", data->last_tick, data->delta);
return (0);
}

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* angle.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/24 14:41:35 by tchampio #+# #+# */
/* Updated: 2025/07/29 20:09:55 by tchampio ### ########.fr */
/* Created: 2025/07/31 14:53:18 by kcolin #+# #+# */
/* Updated: 2025/07/31 14:53:59 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,17 +22,19 @@ void turn_right_angle(t_cub3d_data *data)
t_player *p;
double prev_dir_x;
double prev_plane_x;
double rotspeed;
rotspeed = ROTATION_SPEED * data->delta;
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);
p->dir_x = p->dir_x * cos(rotspeed) - p->dir_y * sin(rotspeed);
p->dir_y = prev_dir_x * sin(rotspeed)
+ p->dir_y * cos(rotspeed);
p->plane_x = p->plane_x * cos(rotspeed)
- p->plane_y * sin(rotspeed);
p->plane_y = prev_plane_x * sin(rotspeed)
+ p->plane_y * cos(rotspeed);
}
void turn_left_angle(t_cub3d_data *data)
@ -40,16 +42,18 @@ void turn_left_angle(t_cub3d_data *data)
t_player *p;
double prev_dir_x;
double prev_plane_x;
double rotspeed;
rotspeed = ROTATION_SPEED * data->delta;
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);
p->dir_x = p->dir_x * cos(-rotspeed)
- p->dir_y * sin(-rotspeed);
p->dir_y = prev_dir_x * sin(-rotspeed)
+ p->dir_y * cos(-rotspeed);
p->plane_x = p->plane_x * cos(-rotspeed)
- p->plane_y * sin(-rotspeed);
p->plane_y = prev_plane_x * sin(-rotspeed)
+ p->plane_y * cos(-rotspeed);
}