diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_sprite.c | 30 | ||||
-rw-r--r-- | src/ft_get_player_spawn.c | 1 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 4 | ||||
-rw-r--r-- | src/ft_raycasting.c | 63 |
4 files changed, 46 insertions, 52 deletions
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 7e7114f..28ffb10 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,32 +16,24 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -/* -void - ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) -{ - if (cl->tlist[4].tex_x) -} -*/ + void ft_draw_sprite(t_cub *cl) { - int itx; - int ity; int d; int tex_x; int tex_y; - itx = cl->sp_list.s_start_x; - while (itx < cl->sp_list.s_end_x) + cl->sprites.x = cl->sprites.s_start_x; + while (cl->sprites.x < cl->sprites.s_end_x) { - tex_x = (int)((itx - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) - * cl->tlist[4].img_w / cl->sp_list.s_w); - ity = cl->sp_list.s_start_y; - while (ity < cl->sp_list.s_end_y) + tex_x = (int)((cl->sprites.x - (-cl->sprites.s_w / 2 + cl->sprites.s_screen_x)) + * cl->tlist[4].img_w / cl->sprites.s_w); + cl->sprites.y = cl->sprites.s_start_y; + while (cl->sprites.y < cl->sprites.s_end_y) { - d = ity * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; - tex_y = ((d * cl->tlist[4].img_h) / cl->sp_list.s_h) / 256; + d = cl->sprites.y * 256 - cl->wlist->y_size * 128 + cl->sprites.s_h * 128; + tex_y = ((d * cl->tlist[4].img_h) / cl->sprites.s_h) / 256; if (*(cl->tlist[4].ptr + tex_x + tex_y * cl->tlist[4].sizeline / 4)) { cl->img.ptr[tex_x * 4 + (cl->img.sizeline * tex_y)] = @@ -49,8 +41,8 @@ void cl->tlist[4].img_h * tex_y]; /*puts("qwe");*/ } - ity++; + cl->sprites.y++; } - itx++; + cl->sprites.x++; } } diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 617ec22..774a80e 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -82,6 +82,7 @@ void plist->start_x = plist->pos_x; plist->start_y = plist->pos_y; ft_get_start_side(clist->mlist->map[y][x], clist->plist); + ft_get_sprite_spawn(clist); return ; } x++; diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 806489f..76629c5 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -28,8 +28,8 @@ void { if (ft_ischarset("2", clist->mlist->map[y][x])) { - clist->sp_list.s_pos_x = x + 0.5; - clist->sp_list.s_pos_y = y + 0.5; + clist->sprites.s_pos_x = x + 0.5; + clist->sprites.s_pos_y = y + 0.5; return ; } x++; diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 5bf0785..be4a815 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -20,44 +20,45 @@ void ft_calc_sprite(t_cub *cl) { - cl->sp_list.s_x = cl->sp_list.s_pos_x - cl->plist->pos_x; - cl->sp_list.s_y = cl->sp_list.s_pos_y - cl->plist->pos_y; - cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_y + 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->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)); + 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); } void ft_calc_sprite_norme(t_cub *cl) { - 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; - /*ft_printf("start x: %d\nstart y : %d\n", cl->sp_list.s_start_x, cl->sp_list.s_start_y);*/ - /*ft_printf("end x: %d\nend y : %d\n", cl->sp_list.s_end_x, cl->sp_list.s_end_y);*/ - ft_draw_sprite(cl); + 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);*/ } |