wall grows proportionally
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
# define SCREEN_FOCAL 90
|
# define SCREEN_FOCAL 90
|
||||||
/* size of a cell on the map */
|
/* size of a cell on the map */
|
||||||
# define CELL 20
|
# define CELL 20
|
||||||
|
/* height of a wall without perpectiv */
|
||||||
|
# define WALL_HEIGHT 300
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* keys macro
|
* keys macro
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ typedef struct s_rcast
|
|||||||
t_vec screen_size;
|
t_vec screen_size;
|
||||||
t_vec ray;
|
t_vec ray;
|
||||||
t_vec wall;
|
t_vec wall;
|
||||||
|
int wall_height;
|
||||||
int screen_width;
|
int screen_width;
|
||||||
int screen_height;
|
int screen_height;
|
||||||
int cell;
|
int cell;
|
||||||
|
|||||||
@@ -32,14 +32,18 @@
|
|||||||
|
|
||||||
static void calcul_wall(t_rcast *rcast)
|
static void calcul_wall(t_rcast *rcast)
|
||||||
{
|
{
|
||||||
|
int length;
|
||||||
int height;
|
int height;
|
||||||
|
|
||||||
rcast->wall.start.x = rcast->ray_nb;
|
rcast->wall.start.x = rcast->ray_nb;
|
||||||
rcast->wall.end.x = rcast->ray_nb;
|
rcast->wall.end.x = rcast->ray_nb;
|
||||||
if (rcast->is_x == 1 && rcast->slope_y != 0)
|
if (rcast->is_x == 1 && rcast->slope_y != 0)
|
||||||
height = (rcast->next_x - rcast->ray_step_x) / ft_abs(rcast->slope_y);
|
length = (rcast->next_x - rcast->ray_step_x) / ft_abs(rcast->slope_y);
|
||||||
if (rcast->is_x == 0 && rcast->slope_x != 0)
|
if (rcast->is_x == 0 && rcast->slope_x != 0)
|
||||||
height = (rcast->next_y - rcast->ray_step_y) / ft_abs(rcast->slope_x);
|
length = (rcast->next_y - rcast->ray_step_y) / ft_abs(rcast->slope_x);
|
||||||
|
height = rcast->wall_height - length;
|
||||||
|
if (height < 0)
|
||||||
|
height = 0;
|
||||||
if (height > rcast->screen_height)
|
if (height > rcast->screen_height)
|
||||||
height = rcast->screen_height;
|
height = rcast->screen_height;
|
||||||
rcast->wall.start.y = rcast->screen_height / 2 + height / 2;
|
rcast->wall.start.y = rcast->screen_height / 2 + height / 2;
|
||||||
@@ -48,26 +52,27 @@ static void calcul_wall(t_rcast *rcast)
|
|||||||
|
|
||||||
void draw_column(t_game *game, t_rcast *rcast)
|
void draw_column(t_game *game, t_rcast *rcast)
|
||||||
{
|
{
|
||||||
t_vec floor;
|
t_vec plane;
|
||||||
t_vec ceilling;
|
int color;
|
||||||
|
|
||||||
|
plane.start.x = rcast->ray_nb;
|
||||||
|
plane.end.x = rcast->ray_nb;
|
||||||
if (rcast->wall.start.y > 0)
|
if (rcast->wall.start.y > 0)
|
||||||
{
|
{
|
||||||
floor.start.x = rcast->ray_nb;
|
plane.start.y = rcast->screen_height;
|
||||||
floor.end.x = rcast->ray_nb;
|
plane.end.y = rcast->wall.start.y;
|
||||||
floor.start.y = rcast->screen_height;
|
draw_line(&game->img, &plane, 0x00FF0000);
|
||||||
floor.end.y = rcast->wall.start.y;
|
|
||||||
draw_line(&game->img, &floor, 0x00FF0000);
|
|
||||||
}
|
}
|
||||||
if (rcast->wall.start.y < rcast->screen_height)
|
if (rcast->wall.start.y < rcast->screen_height)
|
||||||
{
|
{
|
||||||
ceilling.start.x = rcast->ray_nb;
|
plane.start.y = rcast->wall.end.y;
|
||||||
ceilling.end.x = rcast->ray_nb;
|
plane.end.y = 0;
|
||||||
ceilling.start.y = rcast->wall.end.y;
|
draw_line(&game->img, &plane, 0x000000FF);
|
||||||
ceilling.end.y = 0;
|
|
||||||
draw_line(&game->img, &ceilling, 0x00FF0000);
|
|
||||||
}
|
}
|
||||||
draw_line(&game->img, &rcast->wall, 0x00FF00FF);
|
color = 0x00FF00FF;
|
||||||
|
if (rcast->is_x)
|
||||||
|
color = 0x00EE00EE;
|
||||||
|
draw_line(&game->img, &rcast->wall, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raycast(t_game *game, t_rcast *rcast)
|
void raycast(t_game *game, t_rcast *rcast)
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ static void init_raycast(t_rcast *rcast)
|
|||||||
dist = cos(dist) * ((SCREEN_WIDTH / 2) / sin(dist));
|
dist = cos(dist) * ((SCREEN_WIDTH / 2) / sin(dist));
|
||||||
rcast->screen_width = SCREEN_WIDTH;
|
rcast->screen_width = SCREEN_WIDTH;
|
||||||
rcast->screen_height = SCREEN_HEIGHT;
|
rcast->screen_height = SCREEN_HEIGHT;
|
||||||
|
rcast->wall_height = WALL_HEIGHT;
|
||||||
// screen dist
|
// screen dist
|
||||||
rcast->screen_dist.start.x = 0;
|
rcast->screen_dist.start.x = 0;
|
||||||
rcast->screen_dist.start.y = 0;
|
rcast->screen_dist.start.y = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user