fix: various rendering issues

- Correct rendering on whole window if window is not square
- Multiple crashes eliminated
- Sprites no longer lag behind player movement/rotation
This commit is contained in:
Khaïs COLIN 2025-08-12 12:21:56 +02:00
parent 98e0119c91
commit fcb08f6447
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 9 additions and 11 deletions

View file

@ -6,15 +6,15 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */ /* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
/* Updated: 2025/08/07 13:45:34 by kcolin ### ########.fr */ /* Updated: 2025/08/12 14:32:47 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef CONSTS_H #ifndef CONSTS_H
# define CONSTS_H # define CONSTS_H
# define HEIGHT 800
# define WIDTH 800 # define WIDTH 800
# define HEIGHT 600
# define SIZE 64 # define SIZE 64
# define MAP_SIZE 10 # define MAP_SIZE 10

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:28:56 by kcolin #+# #+# */ /* Created: 2025/07/17 14:28:56 by kcolin #+# #+# */
/* Updated: 2025/08/06 14:02:08 by tchampio ### ########.fr */ /* Updated: 2025/08/12 14:30:49 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,7 @@ void my_mlx_pixel_put(t_img_data *data, int x, int y, int color)
{ {
char *dst; char *dst;
if (x < 0 || y < 0 || x >= HEIGHT || y >= WIDTH) if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT)
return ; return ;
dst = data->addr + (y * data->line_length + x * (data->bits_per_pixel / 8)); dst = data->addr + (y * data->line_length + x * (data->bits_per_pixel / 8));
*(unsigned int *)dst = color; *(unsigned int *)dst = color;

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/08/11 11:03:22 by tchampio ### ########.fr */ /* Updated: 2025/08/12 14:23:27 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -39,11 +39,9 @@ int game_loop(t_cub3d_data *data)
char *fps_string; char *fps_string;
data->last_tick = get_milliseconds(); 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); reset_matrix(data);
raycaster(data, &ray);
move_player(data); move_player(data);
raycaster(data, &ray);
sprite_caster(data); sprite_caster(data);
matrix_to_image(data); matrix_to_image(data);
draw_map(data->map, &data->player, data->img_data); draw_map(data->map, &data->player, data->img_data);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:18:17 by kcolin #+# #+# */ /* Created: 2025/07/31 13:18:17 by kcolin #+# #+# */
/* Updated: 2025/07/31 13:38:49 by kcolin ### ########.fr */ /* Updated: 2025/08/12 14:31:04 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,12 +23,12 @@ void reset_matrix(t_cub3d_data *data)
int matrix_get(t_cub3d_data *data, int x, int y) int matrix_get(t_cub3d_data *data, int x, int y)
{ {
return (data->screen_matrix[y + x * WIDTH]); return (data->screen_matrix[y + x * HEIGHT]);
} }
void matrix_set(t_cub3d_data *data, int x, int y, int color) void matrix_set(t_cub3d_data *data, int x, int y, int color)
{ {
data->screen_matrix[y + x * WIDTH] = color; data->screen_matrix[y + x * HEIGHT] = color;
} }
void matrix_to_image(t_cub3d_data *data) void matrix_to_image(t_cub3d_data *data)