diff options
author | salaaad2 <arthudurant263@gmail.com> | 2020-02-25 17:33:15 +0100 |
---|---|---|
committer | salaaad2 <arthudurant263@gmail.com> | 2020-02-25 17:33:15 +0100 |
commit | 51dd3734caadd0c3b943da3410772c65558280cc (patch) | |
tree | 20753d7dc65e749c849ad9eb1f0b003fe65bde2a /src/ft_raycasting.c | |
parent | bunch of garbage (diff) | |
download | 42-cub3d-51dd3734caadd0c3b943da3410772c65558280cc.tar.gz 42-cub3d-51dd3734caadd0c3b943da3410772c65558280cc.tar.bz2 42-cub3d-51dd3734caadd0c3b943da3410772c65558280cc.tar.xz 42-cub3d-51dd3734caadd0c3b943da3410772c65558280cc.tar.zst 42-cub3d-51dd3734caadd0c3b943da3410772c65558280cc.zip |
???
Diffstat (limited to 'src/ft_raycasting.c')
-rw-r--r-- | src/ft_raycasting.c | 85 |
1 files changed, 43 insertions, 42 deletions
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index be4a815..d97c231 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -18,49 +18,49 @@ #include <math.h> void - ft_calc_sprite(t_cub *cl) + ft_sprite_height(t_cub *cl, t_sprite *sprite) { - cl->sprites.s_x = cl->sprites.s_pos_x - cl->plist->pos_x; - cl->sprites.s_y = cl->sprites.s_pos_y - cl->plist->pos_y; - cl->sprites.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - - cl->plist->dir_x * cl->plist->plane_y); - cl->sprites.sprite_transform_x = cl->sprites.inv_c_m - * (cl->plist->dir_y * cl->sprites.s_x - - cl->plist->dir_x * cl->sprites.s_y); - cl->sprites.sprite_transform_y = cl->sprites.inv_c_m - * (-cl->plist->plane_y * cl->sprites.s_x - + cl->plist->plane_x * cl->sprites.s_y); - cl->sprites.s_screen_x = (int)((cl->wlist->x_size / 2) - * (1 + cl->sprites.sprite_transform_x - / cl->sprites.sprite_transform_y)); - cl->sprites.s_h = - abs((int)(cl->wlist->y_size * cl->sprites.sprite_transform_y)); - ft_calc_sprite_norme(cl); + sprite->spriteheight = abs((int)(cl->wlist->y_size / (sprite->transformy))); + sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist->y_size / 2; + if (sprite->drawstarty < 0) + sprite->drawstarty = 0; + sprite->drawendy = sprite->spriteheight / 2 + cl->wlist->y_size / 2; + if (sprite->drawendy >= (int)cl->wlist->y_size) + sprite->drawendy = cl->wlist->y_size; } void - ft_calc_sprite_norme(t_cub *cl) + ft_sprite_width(t_cub *cl, t_sprite *sprite) { - cl->sprites.s_start_y = -cl->sprites.s_h / 2 + cl->wlist->y_size / 2; - if (cl->sprites.s_start_y < 0) - cl->sprites.s_start_y = 0; - cl->sprites.s_end_y = cl->sprites.s_h / 2 + cl->wlist->y_size / 2; - if (cl->sprites.s_end_y > (int)cl->wlist->y_size) - cl->sprites.s_end_y = cl->wlist->y_size - 1; - cl->sprites.s_w = abs((int)(cl->wlist->y_size - / cl->sprites.sprite_transform_y)); /*sprite width*/ - cl->sprites.s_start_x = -cl->sprites.s_w / 2 + cl->sprites.s_screen_x; - if (cl->sprites.s_start_x < 0) - cl->sprites.s_start_x = 0; - cl->sprites.s_end_x = cl->sprites.s_w / 2 + cl->sprites.s_screen_x; - printf("%d\n", cl->sprites.s_w); - if (cl->sprites.s_end_x > (int)cl->wlist->x_size) - cl->sprites.s_end_x = cl->wlist->x_size - 1; - /*ft_printf("start x: %d\nend x : %d\n", cl->sprites.s_start_x, cl->sprites.s_end_x);*/ - /*ft_printf("start y: %d\nend y : %d\n", cl->sprites.s_start_y, cl->sprites.s_end_y);*/ - /*ft_draw_sprite(cl);*/ + sprite->spritewidth = abs((int)(cl->wlist->x_size / (sprite->transformy))); + sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx; + if (sprite->drawstartx < 0) + sprite->drawstartx = 0; + sprite->drawendx = sprite->spritewidth / 2 + sprite->spritescreenx; + if (sprite->drawendx >= (int)cl->wlist->x_size) + sprite->drawendx = cl->wlist->x_size; } +void + ft_calc_sprite(t_cub *cl) +{ + t_sprite sprite; + + sprite = cl->sprites; + sprite.spritex = (sprite.spritex + 0.5) - cl->plist->pos_x; + sprite.spritey = (sprite.spritey + 0.5) - cl->plist->pos_y; + sprite.invdet = 1.0 / (cl->plist->plane_x * + cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); + sprite.transformx = sprite.invdet * (cl->plist->dir_y * + sprite.spritex - cl->plist->dir_x * sprite.spritey); + sprite.transformy = sprite.invdet * + (-cl->plist->plane_y * sprite.spritex + cl->plist->plane_x * sprite.spritey); + sprite.spritescreenx = (int)((cl->wlist->x_size / 2) * + (1 + sprite.transformx / sprite.transformy)); + ft_sprite_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_sprite(cl, &sprite); +} void ft_calc_tex(t_cub *clist) @@ -82,8 +82,8 @@ void - clist->tlist[clist->w_side].tex_x - 1; } -static void - ft_initray(t_cub *cl, uint16_t i) + static void +ft_initray(t_cub *cl, uint16_t i) { t_win *wl; t_player *pl; @@ -103,15 +103,15 @@ static void 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; @@ -130,6 +130,7 @@ void cl->rlist.wall_b = wl->y_size - 1; ft_choose_tex(cl); ft_calc_tex(cl); + ft_calc_sprite(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); i++; } |