diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2020-03-09 15:50:02 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2020-03-09 15:50:02 +0100 |
commit | f00d3d412bdbbe45c6a84930e9d392bf915a25b9 (patch) | |
tree | 77dd102e7dbd84a16b7d767c3edad64841c6628c /src | |
parent | ils se cachent (mal) (diff) | |
download | 42-cub3d-f00d3d412bdbbe45c6a84930e9d392bf915a25b9.tar.gz 42-cub3d-f00d3d412bdbbe45c6a84930e9d392bf915a25b9.tar.bz2 42-cub3d-f00d3d412bdbbe45c6a84930e9d392bf915a25b9.tar.xz 42-cub3d-f00d3d412bdbbe45c6a84930e9d392bf915a25b9.tar.zst 42-cub3d-f00d3d412bdbbe45c6a84930e9d392bf915a25b9.zip |
start over n
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_sprite.c | 56 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 51 |
2 files changed, 30 insertions, 77 deletions
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 29a8a46..b8d9506 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -59,19 +59,19 @@ void 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; + sprite->drawendy = cl->wlist->y_size - 1; } void ft_sprite_width(t_cub *cl, t_sprite *sprite) { - sprite->spritewidth = abs((int)(cl->wlist->x_size / (sprite->transformy))); - sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx; + sprite->spritewidth = abs((int)(cl->wlist->y_size / (sprite->transformy))); + sprite->drawstarty = -sprite->spritewidth / 2 + sprite->spritescreenx; if (sprite->drawstartx < 0) sprite->drawstartx = 0; - sprite->drawendx = sprite->spritewidth / 2 + sprite->spritescreenx; + sprite->drawendy = sprite->spritewidth / 2 + sprite->spritescreenx; if (sprite->drawendx >= (int)cl->wlist->x_size) - sprite->drawendx = cl->wlist->x_size; + sprite->drawendx = cl->wlist->x_size - 1; } void @@ -81,23 +81,22 @@ void int i = 0; while (i < cl->mlist->sprite_nbr) - { - sprite = cl->sprites[i]; - sprite.spritex = sprite.s_pos_x - (cl->plist->pos_x - 0.5); - sprite.spritey = sprite.s_pos_y - (cl->plist->pos_y - 0.5); - 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.spritey - cl->plist->dir_x * sprite.spritex); - sprite.transformy = sprite.invdet * - (-cl->plist->plane_y * sprite.spritex + cl->plist->plane_x * sprite.spritey); - printf("[%f] [%f] x [%f] y [%f] [%d]\n", sprite.spritex, sprite.spritey, sprite.transformx, sprite.transformy, i); - sprite.spritescreenx = (int)((cl->wlist->y_size / 2) * - (1 + sprite.transformx / sprite.transformy)); - ft_sprite_height(cl, &sprite); - ft_sprite_width(cl, &sprite); - ft_draw_sprite(cl, &sprite); - i++; + { + sprite = cl->sprites[i]; + sprite.spritex = sprite.s_pos_x - (cl->plist->pos_x); + sprite.spritey = sprite.s_pos_y - (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.spritey - cl->plist->dir_x * sprite.spritex); + 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); + i++; } } @@ -106,23 +105,23 @@ void { int32_t d; - /* printf("start x : %d\nstart y : %d\nend x : %d\nend y : %d\n", sprite->drawstartx, sprite->drawstarty, sprite->drawendy, sprite->drawendy); */ sprite->x = sprite->drawstartx; + printf("y : [%d] [%d] x : [%d] [%d] x : [%f] y : [%f]\n", sprite->drawstarty, sprite->drawendy, sprite->drawstartx, sprite->drawendx, cl->plist->dir_x, cl->plist->dir_y); while (sprite->x < sprite->drawendx) { sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + sprite->spritescreenx)) * cl->tlist[4].img_w / sprite->spritewidth); sprite->y = sprite->drawstarty; - if (sprite->transformy > 0 && sprite->x >= 0 && - sprite->x < (int32_t)cl->wlist->x_size) while (sprite->y < sprite->drawendy) { d = sprite->y * 256 - cl->wlist->y_size * 128 + sprite->spriteheight * 128; sprite->tex_y = ((d * cl->tlist[4].img_h / 2) / sprite->spriteheight) / 128; - if (cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y] && cl->rlist.wall_dist_tab[sprite->x] > cl->rlist.wall_dist) - {cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = + if (cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y] + && cl->rlist.wall_dist_tab[sprite->x] > cl->rlist.wall_dist) + { + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y]; cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = @@ -136,3 +135,6 @@ void sprite->x++; } } + + +/* printf("[%f] [%f] x [%f] y [%f] [%d]\n", sprite.spritex, sprite.spritey, sprite.transformx, sprite.transformy, i); */ diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 220badb..99fff3c 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -12,23 +12,6 @@ #include <stdio.h> #include <cub3d.h> -uint32_t - ft_gradient(t_rgb rgb, int it) -{ - uint32_t res; - - (void)it; - res = 0; - while (it < 500) - { - rgb.r += 1; - rgb.g += 1; - rgb.b += 1; - it++; - } - res += ((rgb.r << 16) + (rgb.g << 8) + rgb.b); - return (res); -} static void ft_draw_floor(t_cub *cl, int32_t y, int32_t x) @@ -36,7 +19,7 @@ static void while ((uint32_t)y < cl->wlist->y_size) { *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = ft_gradient(cl->f_rgb, y); + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(cl->f_rgb); y++; } } @@ -55,38 +38,6 @@ static void } } -/* -** #include <libft.h> -** static void -** ft_draw_ceil_tex(t_cub *cl, int x, int y) -** { -** int16_t i; -** int32_t d; -** int32_t tex_y; -** -** i = 0; -** while (i < y) -** { -** d = i * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; -** d = (d <= 0) ? (-d) : (d); -** ft_printf("%d\n", d); -** tex_y = ((d * cl->tlist[1].img_h) / cl->rlist.line_h) / 256; -** (tex_y <= 0) ? (tex_y = 1) : 0; -** cl->img.ptr[x * 4 + (cl->img.sizeline * i)] = -** (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * -** cl->tlist[1].img_h * tex_y]; -** cl->img.ptr[x * 4 + (cl->img.sizeline * i) + 1] = -** (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * -** cl->tlist[1].img_h * tex_y + 1]; -** cl->img.ptr[x * 4 + (cl->img.sizeline * i) + 2] = -** (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * -** cl->tlist[1].img_h * tex_y + 2]; -** cl->img.ptr[x * 4 + cl->wlist->x_size * i + 3] = (char)0; -** i++; -** } -** } -*/ - int8_t ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2) { |