wip calcul texture image x position, and add protection when creating texture
This commit is contained in:
@@ -1,35 +1,52 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (rcast->is_x == 1)
|
||||
{
|
||||
tmp = (rcast->slope_y + wall->delta) / ft_abs(rcast->slope_x);
|
||||
tmp += game->plr.pos.y;
|
||||
wall->posx = tmp % rcast->cell;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (rcast->slope_x + wall->delta) / ft_abs(rcast->slope_y);
|
||||
tmp += game->plr.pos.x;
|
||||
wall->posx = tmp % rcast->cell;
|
||||
}
|
||||
}
|
||||
|
||||
static void fill_wall_vector(t_rcast *rcast, int height)
|
||||
{
|
||||
if (height < 0)
|
||||
height = 0;
|
||||
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;
|
||||
rcast->wall.vec.start.y = rcast->screen_height / 2 + height / 2;
|
||||
rcast->wall.vec.end.y = rcast->screen_height / 2 - height / 2;
|
||||
}
|
||||
|
||||
static void calcul_wall(t_rcast *rcast)
|
||||
{
|
||||
long int height;
|
||||
int delta;
|
||||
|
||||
rcast->wall.start.x = rcast->ray_nb;
|
||||
rcast->wall.end.x = rcast->ray_nb;
|
||||
rcast->wall.vec.start.x = rcast->ray_nb;
|
||||
rcast->wall.vec.end.x = rcast->ray_nb;
|
||||
if (rcast->is_x == 1)
|
||||
delta = rcast->next_x - rcast->ray_step_x;
|
||||
else if (rcast->is_x == 0)
|
||||
delta = rcast->next_y - rcast->ray_step_y;
|
||||
rcast->wall.delta = rcast->next_x - rcast->ray_step_x;
|
||||
else
|
||||
rcast->wall.delta = rcast->next_y - rcast->ray_step_y;
|
||||
height = rcast->screen_height * rcast->cell;
|
||||
if (rcast->slope_x)
|
||||
height *= rcast->slope_x;
|
||||
if (rcast->slope_y)
|
||||
height *= rcast->slope_y;
|
||||
if (delta && rcast->screen_dist)
|
||||
height /= (delta * rcast->screen_dist);
|
||||
height = ft_abs(height);
|
||||
fill_wall_vector(rcast, height);
|
||||
if (rcast->wall.delta && rcast->screen_dist)
|
||||
height /= (rcast->wall.delta * rcast->screen_dist);
|
||||
rcast->wall.height = ft_abs(height);
|
||||
fill_wall_vector(rcast, rcast->wall.height);
|
||||
}
|
||||
|
||||
void raycast(t_game *game, t_rcast *rcast)
|
||||
@@ -39,9 +56,10 @@ void raycast(t_game *game, t_rcast *rcast)
|
||||
rcast->ray_nb = 0;
|
||||
while (rcast->ray_nb <= rcast->screen_width)
|
||||
{
|
||||
ray_intersect(game, rcast, &ray);
|
||||
ray_intersect_wall(game, rcast, &ray);
|
||||
calcul_wall(rcast);
|
||||
draw_column(game, rcast);
|
||||
calcul_img_column(game, rcast, &rcast->wall);
|
||||
draw_column(game, rcast, &rcast->wall, &game->txt);
|
||||
(rcast->ray_nb)++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user