fix: fixed norme

This commit is contained in:
Theo Champion 2025-07-30 16:40:33 +02:00
parent e28cd1c85b
commit f21b8dc448
4 changed files with 22 additions and 21 deletions

View file

@ -6,7 +6,7 @@
/* 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/07/29 14:28:45 by tchampio ### ########.fr */ /* Updated: 2025/07/30 16:38:32 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,6 +32,7 @@ extern const float g_southeast;
# define MOVEMENT_SPEED 0.1 # define MOVEMENT_SPEED 0.1
# define ROTATION_SPEED 0.1 # define ROTATION_SPEED 0.1
# define PLANE_VALUE 0.66 # define PLANE_VALUE 0.66
# define TEXTURE_SIZE 64
# ifdef BONUS # ifdef BONUS
# define COMPILED_TEXT "Compiled with bonuses" # define COMPILED_TEXT "Compiled with bonuses"
# else # else

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/29 11:32:20 by tchampio #+# #+# */ /* Created: 2025/07/29 11:32:20 by tchampio #+# #+# */
/* Updated: 2025/07/29 11:35:17 by tchampio ### ########.fr */ /* Updated: 2025/07/30 16:39:24 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,19 +18,19 @@ typedef struct s_ray
double plane; double plane;
double dir_x; double dir_x;
double dir_y; double dir_y;
int map_x; int map_x;
int map_y; int map_y;
int step_x; int step_x;
int step_y; int step_y;
double side_dist_x; double side_dist_x;
double side_dist_y; double side_dist_y;
double delta_dist_x; double delta_dist_x;
double delta_dist_y; double delta_dist_y;
double wall_dist; double wall_dist;
int side; int side;
int wall_height; int wall_height;
int draw_start; int draw_start;
int draw_end; int draw_end;
double wall_x; double wall_x;
} t_ray; } t_ray;

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/30 12:50:10 by tchampio #+# #+# */ /* Created: 2025/07/30 12:50:10 by tchampio #+# #+# */
/* Updated: 2025/07/30 16:22:42 by tchampio ### ########.fr */ /* Updated: 2025/07/30 16:38:59 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,7 +30,6 @@ int get_cardinal(t_ray *ray)
else else
return (0); return (0);
} }
} }
/* /*
@ -47,20 +46,20 @@ void render_walls(t_cub3d_data *data, t_ray *ray, int x)
unsigned int color; unsigned int color;
double step; double step;
double pos; double pos;
static int texture_size = 64; // to be changed in favor of a const
dir = get_cardinal(ray); dir = get_cardinal(ray);
tex_x = (int)(ray->wall_x * texture_size); tex_x = (int)(ray->wall_x * TEXTURE_SIZE);
if ((ray->side == 0 && ray->dir_x < 0) || (ray->side == 1 && ray->dir_y > 0)) if ((ray->side == 0 && ray->dir_x < 0)
tex_x = texture_size - tex_x - 1; || (ray->side == 1 && ray->dir_y > 0))
step = 1.0 * texture_size / ray->wall_height; tex_x = TEXTURE_SIZE - tex_x - 1;
step = 1.0 * TEXTURE_SIZE / ray->wall_height;
pos = (ray->draw_start - HEIGHT / 2 + ray->wall_height / 2) * step; pos = (ray->draw_start - HEIGHT / 2 + ray->wall_height / 2) * step;
while (ray->draw_start < ray->draw_end) while (ray->draw_start < ray->draw_end)
{ {
pos += step; pos += step;
color = 0x0000ff; color = 0x0000ff;
(void)dir; // cc complains otherwise (void)dir;
(void)pos; // cc complains otherwise (void)pos;
data->screen_matrix[ray->draw_start][x] = color; data->screen_matrix[ray->draw_start][x] = color;
ray->draw_start++; ray->draw_start++;
} }

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/30 14:53:39 by tchampio #+# #+# */ /* Created: 2025/07/30 14:53:39 by tchampio #+# #+# */
/* Updated: 2025/07/30 16:21:18 by tchampio ### ########.fr */ /* Updated: 2025/07/30 16:39:51 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -46,7 +46,8 @@ void matrix_to_image(t_cub3d_data *data)
while (x < WIDTH) while (x < WIDTH)
{ {
if (data->screen_matrix[y][x] > 0) if (data->screen_matrix[y][x] > 0)
my_mlx_pixel_put(data->img_data, x, y, data->screen_matrix[y][x]); my_mlx_pixel_put(data->img_data,
x, y, data->screen_matrix[y][x]);
x++; x++;
} }
y++; y++;