game image created but all wrong
This commit is contained in:
@@ -30,27 +30,44 @@
|
||||
}
|
||||
// tmp end
|
||||
|
||||
void draw_column(t_game *game, t_rcast *rcast, t_vec *ray)
|
||||
static void calcul_wall(t_rcast *rcast)
|
||||
{
|
||||
t_vec wall;
|
||||
int height;
|
||||
|
||||
(void)game;
|
||||
(void)rcast;
|
||||
(void)ray;
|
||||
(void)wall;
|
||||
|
||||
wall.start.x = rcast->ray_nb;
|
||||
wall.end.x = rcast->ray_nb;
|
||||
rcast->wall.start.x = rcast->ray_nb;
|
||||
rcast->wall.end.x = rcast->ray_nb;
|
||||
if (rcast->is_x == 1 && rcast->slope_y != 0)
|
||||
height = (rcast->next_x - rcast->ray_step_x) / ft_abs(rcast->slope_y);
|
||||
if (rcast->is_x == 0 && rcast->slope_x != 0)
|
||||
height = (rcast->next_y - rcast->ray_step_y) / ft_abs(rcast->slope_x);
|
||||
if (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;
|
||||
}
|
||||
|
||||
void draw_column(t_game *game, t_rcast *rcast)
|
||||
{
|
||||
t_vec floor;
|
||||
t_vec ceilling;
|
||||
|
||||
if (rcast->wall.start.y > 0)
|
||||
{
|
||||
rcast->wall_height = rcast->next_x - rcast->ray_step_x;
|
||||
rcast->wall_height /= ft_abs(rcast->slope_y);
|
||||
rcast->wall_height /= 2;
|
||||
//printf("rcast->wall: %i\n", rcast->wall_height);
|
||||
wall.start.y = rcast->screen_center / 2 + rcast->wall_height;
|
||||
wall.end.y = rcast->screen_center / 2 - rcast->wall_height;
|
||||
floor.start.x = rcast->ray_nb;
|
||||
floor.end.x = rcast->ray_nb;
|
||||
floor.start.y = rcast->screen_height;
|
||||
floor.end.y = rcast->wall.start.y;
|
||||
draw_line(&game->img, &floor, 0x00FF0000);
|
||||
}
|
||||
// draw_line(&game->img, wall, 0x00FF0000);
|
||||
if (rcast->wall.start.y < rcast->screen_height)
|
||||
{
|
||||
ceilling.start.x = rcast->ray_nb;
|
||||
ceilling.end.x = rcast->ray_nb;
|
||||
ceilling.start.y = rcast->wall.end.y;
|
||||
ceilling.end.y = 0;
|
||||
draw_line(&game->img, &ceilling, 0x00FF0000);
|
||||
}
|
||||
draw_line(&game->img, &rcast->wall, 0x00FF00FF);
|
||||
}
|
||||
|
||||
void raycast(t_game *game, t_rcast *rcast)
|
||||
@@ -58,16 +75,17 @@ void raycast(t_game *game, t_rcast *rcast)
|
||||
t_vec ray;
|
||||
|
||||
rcast->ray_nb = 0;
|
||||
while (rcast->ray_nb <= rcast->screen_def)
|
||||
while (rcast->ray_nb <= rcast->screen_width)
|
||||
{
|
||||
ray_intersect(game, rcast, &ray);
|
||||
|
||||
// tmp, to draw the map
|
||||
calcul_ray_end(rcast, &ray);
|
||||
draw_line(&game->map_img, ray, 0x00FF00FF);
|
||||
draw_line(&game->map_img, &ray, 0x00FF00FF);
|
||||
// tmp end
|
||||
|
||||
draw_column(game, rcast, &ray);
|
||||
calcul_wall(rcast);
|
||||
draw_column(game, rcast);
|
||||
(rcast->ray_nb)++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user