add struct wall
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
- resolve wall height
|
- resolve wall height
|
||||||
- resolve view buble
|
- resolve view buble
|
||||||
- resolve vertical ray
|
|
||||||
- add textures
|
- add textures
|
||||||
|
|
||||||
# ressources
|
# ressources
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ typedef struct s_vec
|
|||||||
t_coord end;
|
t_coord end;
|
||||||
} t_vec;
|
} t_vec;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct for walls 3d drawing
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct s_wall
|
||||||
|
{
|
||||||
|
t_vec pos;
|
||||||
|
int height;
|
||||||
|
} t_wall;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* struct with all elements for raycasting
|
* struct with all elements for raycasting
|
||||||
*/
|
*/
|
||||||
@@ -35,9 +45,6 @@ typedef struct s_rcast
|
|||||||
t_vec screen_dist;
|
t_vec screen_dist;
|
||||||
t_vec screen_size;
|
t_vec screen_size;
|
||||||
t_vec ray;
|
t_vec ray;
|
||||||
t_vec wall;
|
|
||||||
int tmp;
|
|
||||||
int wall_height;
|
|
||||||
int screen_width;
|
int screen_width;
|
||||||
int screen_height;
|
int screen_height;
|
||||||
int cell;
|
int cell;
|
||||||
@@ -125,6 +132,7 @@ typedef struct s_game
|
|||||||
t_plr plr;
|
t_plr plr;
|
||||||
// rays
|
// rays
|
||||||
t_rcast rcast;
|
t_rcast rcast;
|
||||||
|
t_wall wall;
|
||||||
// map
|
// map
|
||||||
t_map map;
|
t_map map;
|
||||||
// map window
|
// map window
|
||||||
|
|||||||
@@ -30,65 +30,67 @@
|
|||||||
}
|
}
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
static void wall_length(t_rcast *rcast)
|
static void wall_length(t_rcast *rcast, t_wall *wall)
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
rcast->wall.start.x = rcast->ray_nb;
|
wall->pos.start.x = rcast->ray_nb;
|
||||||
rcast->wall.end.x = rcast->ray_nb;
|
wall->pos.end.x = rcast->ray_nb;
|
||||||
if (rcast->is_x == 1)
|
if (rcast->is_x == 1)
|
||||||
{
|
{
|
||||||
length = rcast->next_x - rcast->ray_step_x;
|
length = rcast->next_x - rcast->ray_step_x;
|
||||||
if (rcast->slope_y)
|
if (rcast->slope_y)
|
||||||
length /= ft_abs(rcast->slope_y);
|
length /= ft_abs(rcast->slope_y);
|
||||||
// length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
|
length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
|
||||||
}
|
}
|
||||||
else if (rcast->is_x == 0)
|
else if (rcast->is_x == 0)
|
||||||
{
|
{
|
||||||
length = rcast->next_y - rcast->ray_step_y;
|
length = rcast->next_y - rcast->ray_step_y;
|
||||||
if (rcast->slope_x)
|
if (rcast->slope_x)
|
||||||
length /= ft_abs(rcast->slope_x);
|
length /= ft_abs(rcast->slope_x);
|
||||||
// length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_y;
|
length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_y;
|
||||||
}
|
}
|
||||||
rcast->ray_len = ft_abs(length);
|
rcast->ray_len = ft_abs(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wall_height(t_rcast *rcast)
|
static void wall_height(t_rcast *rcast, t_wall *wall)
|
||||||
{
|
{
|
||||||
int height;
|
int height;
|
||||||
|
|
||||||
height = rcast->wall_height - rcast->ray_len;
|
height = wall->height - rcast->ray_len;
|
||||||
|
|
||||||
if (height < 0)
|
if (height < 0)
|
||||||
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.end.y = rcast->screen_height / 2 - height / 2;
|
wall->pos.start.y = rcast->screen_height / 2 + height / 2;
|
||||||
|
wall->pos.end.y = rcast->screen_height / 2 - height / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_column(t_game *game, t_rcast *rcast)
|
void draw_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||||
{
|
{
|
||||||
t_vec plane;
|
t_vec plane;
|
||||||
int color;
|
int color;
|
||||||
|
|
||||||
plane.start.x = rcast->ray_nb;
|
plane.start.x = rcast->ray_nb;
|
||||||
plane.end.x = rcast->ray_nb;
|
plane.end.x = rcast->ray_nb;
|
||||||
if (rcast->wall.start.y > 0)
|
if (wall->pos.start.y > 0)
|
||||||
{
|
{
|
||||||
plane.start.y = rcast->screen_height;
|
plane.start.y = rcast->screen_height;
|
||||||
plane.end.y = rcast->wall.start.y;
|
plane.end.y = wall->pos.start.y;
|
||||||
draw_line(&game->img, &plane, 0x00FF0000);
|
draw_line(&game->img, &plane, 0x00FF0000);
|
||||||
}
|
}
|
||||||
if (rcast->wall.start.y < rcast->screen_height)
|
if (wall->pos.start.y < rcast->screen_height)
|
||||||
{
|
{
|
||||||
plane.start.y = rcast->wall.end.y;
|
plane.start.y = wall->pos.end.y;
|
||||||
plane.end.y = 0;
|
plane.end.y = 0;
|
||||||
draw_line(&game->img, &plane, 0x000000FF);
|
draw_line(&game->img, &plane, 0x000000FF);
|
||||||
}
|
}
|
||||||
color = 0x00FF00FF;
|
color = 0x00FF00FF;
|
||||||
if (rcast->is_x)
|
if (rcast->is_x)
|
||||||
color = 0x00EE00EE;
|
color = 0x00EE00EE;
|
||||||
draw_line(&game->img, &rcast->wall, color);
|
draw_line(&game->img, &wall->pos, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raycast(t_game *game, t_rcast *rcast)
|
void raycast(t_game *game, t_rcast *rcast)
|
||||||
@@ -106,15 +108,9 @@ void raycast(t_game *game, t_rcast *rcast)
|
|||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
|
|
||||||
wall_length(rcast);
|
wall_length(rcast, &game->wall);
|
||||||
wall_height(rcast);
|
wall_height(rcast, &game->wall);
|
||||||
draw_column(game, rcast);
|
draw_column(game, rcast, &game->wall);
|
||||||
(rcast->ray_nb)++;
|
(rcast->ray_nb)++;
|
||||||
|
|
||||||
// tmp, to draw the map
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf("\n");
|
|
||||||
// tmp end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ 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;
|
||||||
@@ -133,5 +132,6 @@ t_game *init_game(void)
|
|||||||
// raycasting
|
// raycasting
|
||||||
init_raycast(&(game->rcast));
|
init_raycast(&(game->rcast));
|
||||||
game->rcast.cell = game->map.cell;
|
game->rcast.cell = game->map.cell;
|
||||||
|
game->wall.height = WALL_HEIGHT;
|
||||||
return (game);
|
return (game);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user