diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2020-02-22 20:56:50 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2020-02-22 20:56:50 +0100 |
commit | d2f53e38cbf711e35035a4576070a5211a1d055d (patch) | |
tree | 318b304f44283bab6971eed8aa4c192c0c6e0424 /src/ft_raycasting.c | |
parent | que des maths (diff) | |
download | 42-cub3d-d2f53e38cbf711e35035a4576070a5211a1d055d.tar.gz 42-cub3d-d2f53e38cbf711e35035a4576070a5211a1d055d.tar.bz2 42-cub3d-d2f53e38cbf711e35035a4576070a5211a1d055d.tar.xz 42-cub3d-d2f53e38cbf711e35035a4576070a5211a1d055d.tar.zst 42-cub3d-d2f53e38cbf711e35035a4576070a5211a1d055d.zip |
shpritz
Diffstat (limited to 'src/ft_raycasting.c')
-rw-r--r-- | src/ft_raycasting.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 589d2da..b42e0b7 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -13,6 +13,7 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> +#include <stdlib.h> #include <math.h> void @@ -23,7 +24,21 @@ void cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_x - cl->plist->dir_y * cl->plist->plane_y); cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m * (cl->plist->dir_y * cl->sp_list.s_x - cl->plist->dir_x * cl->sp_list.s_y); cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m * (cl->plist->plane_y * cl->sp_list.s_x - cl->plist->plane_x * cl->sp_list.s_y); - + cl->sp_list.s_screen_x = (int)((cl->wlist->y_size / 2) * (1 + cl->sp_list.sprite_transform_x / cl->sp_list.sprite_transform_y)); + cl->sp_list.s_h = abs((int)(cl->wlist->y_size * cl->sp_list.sprite_transform_y)); /*sprite height*/ + cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sp_list.s_start_y < 0) + cl->sp_list.s_start_y = 0; + cl->sp_list.s_end_y = cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sp_list.s_end_y > (int)cl->wlist->y_size) + cl->sp_list.s_end_y = cl->wlist->y_size - 1;; + cl->sp_list.s_w = abs((int)(cl->wlist->x_size * cl->sp_list.sprite_transform_y)); /*sprite width*/ + cl->sp_list.s_start_x = -cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x; + if (cl->sp_list.s_start_x < 0) + cl->sp_list.s_start_y = 0; + cl->sp_list.s_end_x = cl->sp_list.s_w / 2 + cl->wlist->x_size; + if (cl->sp_list.s_end_x < (int)cl->wlist->x_size) + cl->sp_list.s_end_x = cl->wlist->x_size - 1; } static void @@ -35,7 +50,7 @@ static void else 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->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); clist->tlist[clist->w_side].tex_x = (int)(clist->rlist.wall_hit_x * (double)clist->tlist[clist->w_side].img_w); if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) @@ -95,6 +110,7 @@ void ft_choose_tex(cl); ft_calc_tex(cl); ft_calc_sprite(cl); + ft_draw_sprite(cl , i); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); i++; } |