aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_raycasting.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_raycasting.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 464eb95..9657b18 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -17,15 +17,14 @@
#include <stdlib.h>
#include <math.h>
-
-void
+static void
ft_calc_tex(t_cub *clist)
{
if (clist->rlist.side == 0)
- clist->rlist.wall_hit_x = (clist->plist->pos_x) +
+ clist->rlist.wall_hit_x = (clist->plist.pos_x) +
clist->rlist.wall_dist * clist->rlist.y_ray_dir;
else
- clist->rlist.wall_hit_x = (clist->plist->pos_y) +
+ clist->rlist.wall_hit_x = (clist->plist.pos_y) +
clist->rlist.wall_dist * clist->rlist.x_ray_dir;
clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x);
clist->tlist[clist->w_side].tex_x = (int)(clist->rlist.wall_hit_x *
@@ -38,14 +37,14 @@ void
- clist->tlist[clist->w_side].tex_x - 1;
}
- static void
-ft_initray(t_cub *cl, uint16_t i)
+static void
+ ft_initray(uint16_t i, t_cub *cl)
{
t_win *wl;
t_player *pl;
- wl = cl->wlist;
- pl = cl->plist;
+ wl = &cl->wlist;
+ pl = &cl->plist;
pl->cam_x = 2 * i / (float)(wl->x_size) - 1;
cl->rlist.x_ray_pos = pl->pos_y;
cl->rlist.y_ray_pos = pl->pos_x;
@@ -59,29 +58,34 @@ ft_initray(t_cub *cl, uint16_t i)
if (cl->rlist.side == 0)
{
cl->rlist.wall_dist = (cl->rlist.sqx - cl->rlist.x_ray_pos +
- (1 - cl->mlist->x_step) / 2) / cl->rlist.x_ray_dir;
+ (1 - cl->mlist.x_step) / 2) / cl->rlist.x_ray_dir;
}
else
+ {
cl->rlist.wall_dist = (cl->rlist.sqy - cl->rlist.y_ray_pos +
- (1 - cl->mlist->y_step) / 2) / cl->rlist.y_ray_dir;
+ (1 - cl->mlist.y_step) / 2) / cl->rlist.y_ray_dir;
+ }
}
- void
-ft_castray(t_cub *cl)
+void
+ ft_castray(t_cub *cl)
{
uint16_t i;
t_win *wl;
- float *dist_tab;
+ float *dist_tab;
- if (!(dist_tab = malloc(sizeof(float) * cl->wlist->x_size)))
- return ;
- if (!(cl->rlist.wall_dist_tab = malloc(sizeof(float) * cl->wlist->x_size)))
- return ;
+ wl = &cl->wlist;
+ i = (wl->y_size / 2) + 1;
+ while (++i < wl->y_size)
+ ft_floor_cast(i, cl);
+ if (!(dist_tab = malloc(sizeof(float) * cl->wlist.x_size)))
+ return ;
+ if (!(cl->rlist.wall_dist_tab = malloc(sizeof(float) * cl->wlist.x_size)))
+ return ;
i = 0;
- wl = cl->wlist;
while (i < wl->x_size)
{
- ft_initray(cl, i);
+ ft_initray(i, cl);
cl->rlist.line_h = (int16_t)(wl->y_size / cl->rlist.wall_dist);
cl->rlist.wall_t = -cl->rlist.line_h / 2 + wl->y_size / 2;
if (cl->rlist.wall_t < 0)
@@ -92,8 +96,8 @@ ft_castray(t_cub *cl)
ft_choose_tex(cl);
ft_calc_tex(cl);
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
- dist_tab[i] = cl->rlist.wall_dist;
- cl->rlist.wall_dist_tab = dist_tab;
+ dist_tab[i] = cl->rlist.wall_dist;
+ cl->rlist.wall_dist_tab = dist_tab;
i++;
}
}