rays verticals and horizontals are working
This commit is contained in:
@@ -32,11 +32,11 @@ typedef struct s_vec
|
|||||||
|
|
||||||
typedef struct s_rcast
|
typedef struct s_rcast
|
||||||
{
|
{
|
||||||
int tmp;
|
|
||||||
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;
|
t_vec wall;
|
||||||
|
int tmp;
|
||||||
int wall_height;
|
int wall_height;
|
||||||
int screen_width;
|
int screen_width;
|
||||||
int screen_height;
|
int screen_height;
|
||||||
|
|||||||
@@ -20,8 +20,20 @@ static void init_raycast(t_rcast *rcast, t_vec *ray)
|
|||||||
rcast->next_cell_x = -rcast->ray_sign_x;
|
rcast->next_cell_x = -rcast->ray_sign_x;
|
||||||
rcast->next_cell_y = -rcast->ray_sign_y;
|
rcast->next_cell_y = -rcast->ray_sign_y;
|
||||||
// ray steps in both axis
|
// ray steps in both axis
|
||||||
rcast->ray_step_x = ft_abs(rcast->cell * rcast->slope_y);
|
rcast->ray_step_x = 0;
|
||||||
rcast->ray_step_y = ft_abs(rcast->cell * rcast->slope_x);
|
if (rcast->slope_x)
|
||||||
|
{
|
||||||
|
rcast->ray_step_x = ft_abs(rcast->cell);
|
||||||
|
if (rcast->slope_y)
|
||||||
|
rcast->ray_step_x *= ft_abs(rcast->slope_y);
|
||||||
|
}
|
||||||
|
rcast->ray_step_y = 0;
|
||||||
|
if (rcast->slope_y)
|
||||||
|
{
|
||||||
|
rcast->ray_step_y = ft_abs(rcast->cell);
|
||||||
|
if (rcast->slope_x)
|
||||||
|
rcast->ray_step_y *= ft_abs(rcast->slope_x);
|
||||||
|
}
|
||||||
|
|
||||||
// tmp
|
// tmp
|
||||||
if (rcast->tmp)
|
if (rcast->tmp)
|
||||||
@@ -42,8 +54,12 @@ static void init_first_step(t_rcast *rcast, t_vec *ray)
|
|||||||
rcast->first_next_y = ray->start.y % rcast->cell;
|
rcast->first_next_y = ray->start.y % rcast->cell;
|
||||||
if (rcast->ray_sign_y < 0)
|
if (rcast->ray_sign_y < 0)
|
||||||
rcast->first_next_y -= rcast->cell;
|
rcast->first_next_y -= rcast->cell;
|
||||||
rcast->next_x = ft_abs(rcast->first_next_x * rcast->slope_y);
|
rcast->next_x = ft_abs(rcast->first_next_x);
|
||||||
rcast->next_y = ft_abs(rcast->first_next_y * rcast->slope_x);
|
if (rcast->slope_y != 0)
|
||||||
|
rcast->next_x *= ft_abs(rcast->slope_y);
|
||||||
|
rcast->next_y = ft_abs(rcast->first_next_y);
|
||||||
|
if (rcast->slope_x != 0)
|
||||||
|
rcast->next_y *= ft_abs(rcast->slope_x);
|
||||||
|
|
||||||
// tmp
|
// tmp
|
||||||
if (rcast->tmp)
|
if (rcast->tmp)
|
||||||
@@ -60,7 +76,7 @@ static void next_cell(t_rcast *rcast)
|
|||||||
printf("\n [next_x(%i) > next_y(%i) ?]", rcast->next_x, rcast->next_y);
|
printf("\n [next_x(%i) > next_y(%i) ?]", rcast->next_x, rcast->next_y);
|
||||||
//tmp
|
//tmp
|
||||||
|
|
||||||
if (rcast->slope_x == 0 || rcast->next_x > rcast->next_y)
|
if (!rcast->slope_x || (rcast->next_x > rcast->next_y && rcast->slope_y))
|
||||||
{
|
{
|
||||||
rcast->cell_y += rcast->next_cell_y;
|
rcast->cell_y += rcast->next_cell_y;
|
||||||
rcast->next_y += rcast->ray_step_y;
|
rcast->next_y += rcast->ray_step_y;
|
||||||
|
|||||||
@@ -34,40 +34,55 @@ static void wall_length(t_rcast *rcast)
|
|||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
// tmp, to draw the map
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf("length:");
|
|
||||||
// tmp end
|
|
||||||
|
|
||||||
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->slope_x == 0)
|
||||||
{
|
{
|
||||||
length = (rcast->next_x - rcast->ray_step_x) / ft_abs(rcast->slope_y);
|
|
||||||
length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
|
|
||||||
|
|
||||||
// tmp, to draw the map
|
// tmp, to draw the map
|
||||||
if (rcast->tmp)
|
if (rcast->tmp)
|
||||||
printf("(is_x == 1, slope_y != 0)");
|
printf("(slope_x == 0) ");
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
|
length = (rcast->next_y - rcast->ray_step_y);
|
||||||
}
|
}
|
||||||
if (rcast->is_x == 0 && rcast->slope_x != 0)
|
else if (rcast->slope_y == 0)
|
||||||
{
|
{
|
||||||
length = (rcast->next_y - rcast->ray_step_y) / ft_abs(rcast->slope_x);
|
|
||||||
length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_y;
|
|
||||||
|
|
||||||
// tmp, to draw the map
|
// tmp, to draw the map
|
||||||
if (rcast->tmp)
|
if (rcast->tmp)
|
||||||
printf("(is_x == 0, slope_x != 0)");
|
printf("(slope_y == 0) ");
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
|
length = (rcast->next_x - rcast->ray_step_x);
|
||||||
|
}
|
||||||
|
else if (rcast->is_x == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
// tmp, to draw the map
|
||||||
|
if (rcast->tmp)
|
||||||
|
printf("(is_x == 1) ");
|
||||||
|
// tmp end
|
||||||
|
|
||||||
|
length = (rcast->next_x - rcast->ray_step_x) / ft_abs(rcast->slope_y);
|
||||||
|
// length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
|
||||||
|
}
|
||||||
|
else if (rcast->is_x == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
// tmp, to draw the map
|
||||||
|
if (rcast->tmp)
|
||||||
|
printf("(is_x == 0) ");
|
||||||
|
// tmp end
|
||||||
|
|
||||||
|
length = (rcast->next_y - rcast->ray_step_y) / ft_abs(rcast->slope_x);
|
||||||
|
// 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);
|
||||||
|
|
||||||
// tmp, to draw the map
|
// tmp, to draw the map
|
||||||
if (rcast->tmp)
|
if (rcast->tmp)
|
||||||
printf(" %i", rcast->ray_len);
|
printf("length:%i", rcast->ray_len);
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user