mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
fix: use t_cardinal_dir instead of an int to represent direction
This commit is contained in:
parent
c4a867b054
commit
f21e1e56fb
4 changed files with 43 additions and 47 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ cub3d
|
|||
*.d
|
||||
libft.a
|
||||
vgcore.*
|
||||
cscope.*
|
||||
|
|
|
|||
|
|
@ -61,18 +61,18 @@ void calculate_wall_dist(t_ray *ray, char **map)
|
|||
{
|
||||
ray->side_dist_x += ray->delta_dist_x;
|
||||
ray->map_x += ray->step_x;
|
||||
ray->side = 0;
|
||||
ray->side = NORTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
ray->side_dist_y += ray->delta_dist_y;
|
||||
ray->map_y += ray->step_y;
|
||||
ray->side = 1;
|
||||
ray->side = SOUTH;
|
||||
}
|
||||
if (map[ray->map_y][ray->map_x] != '0')
|
||||
break ;
|
||||
}
|
||||
if (ray->side == 0)
|
||||
if (ray->side == NORTH)
|
||||
ray->wall_dist = ray->side_dist_x - ray->delta_dist_x;
|
||||
else
|
||||
ray->wall_dist = ray->side_dist_y - ray->delta_dist_y;
|
||||
|
|
@ -89,7 +89,7 @@ void calculate_wall_height(t_ray *ray, t_player *player)
|
|||
ray->draw_end = ray->wall_height / 2 + HEIGHT / 2;
|
||||
if (ray->draw_end >= HEIGHT)
|
||||
ray->draw_end = HEIGHT - 1;
|
||||
if (ray->side == 0)
|
||||
if (ray->side == NORTH)
|
||||
ray->wall_x = player->y + ray->wall_dist * ray->dir_y;
|
||||
else
|
||||
ray->wall_x = player->x + ray->wall_dist * ray->dir_x;
|
||||
|
|
|
|||
|
|
@ -3,16 +3,18 @@
|
|||
/* ::: :::::::: */
|
||||
/* ray.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/29 11:32:20 by tchampio #+# #+# */
|
||||
/* Updated: 2025/07/30 16:46:05 by tchampio ### ########.fr */
|
||||
/* Created: 2025/08/05 12:49:49 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/05 12:49:49 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RAY_H
|
||||
# define RAY_H
|
||||
|
||||
# include "../map/mapdata.h"
|
||||
|
||||
/*
|
||||
* plane - plan de camera (vectoriel)
|
||||
* dir_x - Direction (pour X)
|
||||
|
|
@ -31,23 +33,23 @@
|
|||
*/
|
||||
typedef struct s_ray
|
||||
{
|
||||
double plane;
|
||||
double dir_x;
|
||||
double dir_y;
|
||||
int map_x;
|
||||
int map_y;
|
||||
int step_x;
|
||||
int step_y;
|
||||
double side_dist_x;
|
||||
double side_dist_y;
|
||||
double delta_dist_x;
|
||||
double delta_dist_y;
|
||||
double wall_dist;
|
||||
int side;
|
||||
int wall_height;
|
||||
int draw_start;
|
||||
int draw_end;
|
||||
double wall_x;
|
||||
double plane;
|
||||
double dir_x;
|
||||
double dir_y;
|
||||
int map_x;
|
||||
int map_y;
|
||||
int step_x;
|
||||
int step_y;
|
||||
double side_dist_x;
|
||||
double side_dist_y;
|
||||
double delta_dist_x;
|
||||
double delta_dist_y;
|
||||
double wall_dist;
|
||||
t_cardinal_dir side;
|
||||
int wall_height;
|
||||
int draw_start;
|
||||
int draw_end;
|
||||
double wall_x;
|
||||
} t_ray;
|
||||
|
||||
#endif // RAY_H
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* render.c :+: :+: :+: */
|
||||
/* walls.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
|
||||
/* Updated: 2025/07/31 13:38:07 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/08/05 12:49:26 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,51 +15,44 @@
|
|||
#include "ray.h"
|
||||
#include "../renderer/render.h"
|
||||
|
||||
int get_cardinal(t_ray *ray)
|
||||
t_cardinal_dir get_cardinal(t_ray *ray)
|
||||
{
|
||||
if (ray->side == 0)
|
||||
if (ray->side == NORTH)
|
||||
{
|
||||
if (ray->dir_x < 0)
|
||||
return (2);
|
||||
return (WEST);
|
||||
else
|
||||
return (3);
|
||||
return (EAST);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ray->dir_y > 0)
|
||||
return (1);
|
||||
return (SOUTH);
|
||||
else
|
||||
return (0);
|
||||
return (NORTH);
|
||||
}
|
||||
}
|
||||
|
||||
static int get_color(int dir)
|
||||
static int get_color(t_cardinal_dir dir)
|
||||
{
|
||||
int color;
|
||||
|
||||
if (dir == 0)
|
||||
if (dir == NORTH)
|
||||
color = 0x0000ff;
|
||||
else if (dir == 1)
|
||||
else if (dir == SOUTH)
|
||||
color = 0x00ff00;
|
||||
else if (dir == 2)
|
||||
else if (dir == WEST)
|
||||
color = 0xff0000;
|
||||
else if (dir == 3)
|
||||
else if (dir == EAST)
|
||||
color = 0xffeb3b;
|
||||
else
|
||||
color = 0xff53ff;
|
||||
return (color);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dir values are:
|
||||
* 0: North
|
||||
* 1: South
|
||||
* 2: West
|
||||
* 3: East
|
||||
*/
|
||||
void render_walls(t_cub3d_data *data, t_ray *ray, int x)
|
||||
{
|
||||
int dir;
|
||||
t_cardinal_dir dir;
|
||||
int tex_x;
|
||||
unsigned int color;
|
||||
double step;
|
||||
|
|
@ -67,8 +60,8 @@ void render_walls(t_cub3d_data *data, t_ray *ray, int x)
|
|||
|
||||
dir = get_cardinal(ray);
|
||||
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 == NORTH && ray->dir_x < 0)
|
||||
|| (ray->side == SOUTH && ray->dir_y > 0))
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue