clean of debug rays vertical and horizontal
This commit is contained in:
@@ -1,45 +1,19 @@
|
|||||||
#include "cube3d.h"
|
#include "cube3d.h"
|
||||||
|
|
||||||
static void init_raycast(t_rcast *rcast, t_vec *ray)
|
static void init_ray_params(t_rcast *rcast, t_vec *ray)
|
||||||
{
|
{
|
||||||
rcast->is_x = 0;
|
|
||||||
// ray sign
|
|
||||||
rcast->ray_sign_x = 1;
|
rcast->ray_sign_x = 1;
|
||||||
if (ray->start.x < ray->end.x)
|
if (ray->start.x < ray->end.x)
|
||||||
rcast->ray_sign_x = -1;
|
rcast->ray_sign_x = -1;
|
||||||
rcast->ray_sign_y = 1;
|
rcast->ray_sign_y = 1;
|
||||||
if (ray->start.y < ray->end.y)
|
if (ray->start.y < ray->end.y)
|
||||||
rcast->ray_sign_y = -1;
|
rcast->ray_sign_y = -1;
|
||||||
// cell position of ray
|
|
||||||
rcast->cell_x = ray->start.x / rcast->cell;
|
rcast->cell_x = ray->start.x / rcast->cell;
|
||||||
rcast->cell_y = ray->start.y / rcast->cell;
|
rcast->cell_y = ray->start.y / rcast->cell;
|
||||||
// slope of ray
|
|
||||||
rcast->slope_x = ray->end.x - ray->start.x;
|
rcast->slope_x = ray->end.x - ray->start.x;
|
||||||
rcast->slope_y = ray->end.y - ray->start.y;
|
rcast->slope_y = ray->end.y - ray->start.y;
|
||||||
// direction of next cell
|
|
||||||
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
|
|
||||||
rcast->ray_step_x = 0;
|
|
||||||
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
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf(" [slope_x:%i, slope_y:%i]", rcast->slope_x, rcast->slope_y);
|
|
||||||
//tmp
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_first_step(t_rcast *rcast, t_vec *ray)
|
static void init_first_step(t_rcast *rcast, t_vec *ray)
|
||||||
@@ -60,45 +34,39 @@ static void init_first_step(t_rcast *rcast, t_vec *ray)
|
|||||||
rcast->next_y = ft_abs(rcast->first_next_y);
|
rcast->next_y = ft_abs(rcast->first_next_y);
|
||||||
if (rcast->slope_x != 0)
|
if (rcast->slope_x != 0)
|
||||||
rcast->next_y *= ft_abs(rcast->slope_x);
|
rcast->next_y *= ft_abs(rcast->slope_x);
|
||||||
|
}
|
||||||
|
|
||||||
// tmp
|
static void init_steps(t_rcast *rcast)
|
||||||
if (rcast->tmp)
|
{
|
||||||
printf(" [next_x:%i, next_y:%i]", rcast->next_x, rcast->next_y);
|
rcast->ray_step_x = 0;
|
||||||
//tmp
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void next_cell(t_rcast *rcast)
|
static void next_cell(t_rcast *rcast)
|
||||||
{
|
{
|
||||||
|
|
||||||
// tmp
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf("\n [next_x(%i) > next_y(%i) ?]", rcast->next_x, rcast->next_y);
|
|
||||||
//tmp
|
|
||||||
|
|
||||||
if (!rcast->slope_x || (rcast->next_x > rcast->next_y && rcast->slope_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;
|
||||||
rcast->is_x = 0;
|
rcast->is_x = 0;
|
||||||
|
|
||||||
// tmp
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf(" [yes] (increase y by %i)", rcast->ray_step_y);
|
|
||||||
//tmp
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rcast->cell_x += rcast->next_cell_x;
|
rcast->cell_x += rcast->next_cell_x;
|
||||||
rcast->next_x += rcast->ray_step_x;
|
rcast->next_x += rcast->ray_step_x;
|
||||||
rcast->is_x = 1;
|
rcast->is_x = 1;
|
||||||
|
|
||||||
// tmp
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf(" [no] (increase x by %i)", rcast->ray_step_x);
|
|
||||||
//tmp
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,25 +78,9 @@ void ray_intersect(t_game *game, t_rcast *rcast, t_vec *ray)
|
|||||||
ray->end.x += rcast->ray_nb;
|
ray->end.x += rcast->ray_nb;
|
||||||
ray->end.y = rcast->ray.end.y + game->plr.pos.y;
|
ray->end.y = rcast->ray.end.y + game->plr.pos.y;
|
||||||
rotate(&(game->plr), &(ray->end));
|
rotate(&(game->plr), &(ray->end));
|
||||||
|
init_ray_params(rcast, ray);
|
||||||
// tmp
|
|
||||||
rcast->tmp = 0;
|
|
||||||
if (ray->end.x - ray->start.x == 0)
|
|
||||||
rcast->tmp = 1;
|
|
||||||
if (ray->end.y - ray->start.y == 0)
|
|
||||||
rcast->tmp = 1;
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf("[ray nb : %3i]", rcast->ray_nb);
|
|
||||||
//tmp end
|
|
||||||
|
|
||||||
init_raycast(rcast, ray);
|
|
||||||
init_first_step(rcast, ray);
|
init_first_step(rcast, ray);
|
||||||
|
init_steps(rcast);
|
||||||
while (!is_wall(game, rcast->cell_x, rcast->cell_y))
|
while (!is_wall(game, rcast->cell_x, rcast->cell_y))
|
||||||
next_cell(rcast);
|
next_cell(rcast);
|
||||||
|
|
||||||
// tmp
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf("\n");
|
|
||||||
//tmp end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,55 +36,21 @@ static void wall_length(t_rcast *rcast)
|
|||||||
|
|
||||||
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->slope_x == 0)
|
if (rcast->is_x == 1)
|
||||||
{
|
{
|
||||||
|
length = rcast->next_x - rcast->ray_step_x;
|
||||||
// tmp, to draw the map
|
if (rcast->slope_y)
|
||||||
if (rcast->tmp)
|
length /= ft_abs(rcast->slope_y);
|
||||||
printf("(slope_x == 0) ");
|
|
||||||
// tmp end
|
|
||||||
|
|
||||||
length = (rcast->next_y - rcast->ray_step_y);
|
|
||||||
}
|
|
||||||
else if (rcast->slope_y == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
// tmp, to draw the map
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf("(slope_y == 0) ");
|
|
||||||
// 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;
|
// 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;
|
||||||
// tmp, to draw the map
|
if (rcast->slope_x)
|
||||||
if (rcast->tmp)
|
length /= ft_abs(rcast->slope_x);
|
||||||
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;
|
// 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
|
|
||||||
if (rcast->tmp)
|
|
||||||
printf("length:%i", rcast->ray_len);
|
|
||||||
// tmp end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wall_height(t_rcast *rcast)
|
static void wall_height(t_rcast *rcast)
|
||||||
|
|||||||
Reference in New Issue
Block a user