diff options
author | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-19 16:57:39 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-19 16:57:39 +0100 |
commit | 94b688c234660708edacf5d49df0e8bd3243cd6a (patch) | |
tree | 00debcda04429d9814de1789f08245355ec4e502 /src | |
parent | Tweaks (diff) | |
parent | yes :^) ! (diff) | |
download | 42-cub3d-94b688c234660708edacf5d49df0e8bd3243cd6a.tar.gz 42-cub3d-94b688c234660708edacf5d49df0e8bd3243cd6a.tar.bz2 42-cub3d-94b688c234660708edacf5d49df0e8bd3243cd6a.tar.xz 42-cub3d-94b688c234660708edacf5d49df0e8bd3243cd6a.tar.zst 42-cub3d-94b688c234660708edacf5d49df0e8bd3243cd6a.zip |
Merge branch 'textures'
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_scene.c | 1 | ||||
-rw-r--r-- | src/ft_draw_textures.c | 16 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 31 | ||||
-rw-r--r-- | src/ft_raycasting.c | 14 |
4 files changed, 35 insertions, 27 deletions
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 966d357..3bf453a 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -18,7 +18,6 @@ void ft_draw_scene(t_cub *clist) { - /* mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr); */ clist->img.img = mlx_new_image(clist->wlist->wlx, clist->wlist->x_size, clist->wlist->y_size); clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 46e51d7..25a6863 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -10,8 +10,10 @@ /* */ /* ************************************************************************** */ +#include <libft.h> #include <cub3d.h> #include <stdint.h> +#include <stdio.h> /* ** 0 : no @@ -21,6 +23,20 @@ ** 4 : sprite */ +void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) +{ + cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y + 1]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y + 2]; + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; +} + void ft_choose_tex(t_cub *clist) { if (clist->rlist.side == 0 && clist->rlist.x_ray_dir < 0) diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 0fad33a..6cbdc00 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include <cub3d.h> +#include <stdio.h> static void ft_draw_floor(t_cub *cl, int32_t y, int32_t x) @@ -38,29 +39,21 @@ static void } int8_t - ft_draw_verline(t_cub *cl, int32_t x, int32_t y1, int32_t y2) + ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2) { - int32_t y; - int32_t t; + int32_t d; + int32_t tex_y; - if (y1 < 0) - y1 = 0; - if (y2 < 0) - y2 = 0; - if ((uint32_t)y2 >= cl->wlist->y_size) - y2 = cl->wlist->x_size - 1; - if (y1 > y2) - { - t = y1; - y1 = y2; - y2 = t; - } - y = y1; + (y < 0) ? (y = 0) : 0; + (y2 < 0) ? (y2 = 0) : 0; ft_draw_ceil(cl, y, x); - ft_choose_tex(cl); - while (y <= y2) + while (y < y2) { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x0000eeaa : 0x0000ffaa; + d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + d = (d <= 0) ? (-d) : (d); + tex_y = ((d * cl->tlist[cl->w_side].img_h) / cl->rlist.line_h) / 256; + (tex_y < 0) ? (tex_y = 0) : 0; + ft_draw_texture(cl, x, y, tex_y); y++; } ft_draw_floor(cl, y, x); diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 9a89dc4..394d6dc 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -25,14 +25,14 @@ void clist->rlist.wall_hit_x = clist->plist->pos_x + clist->rlist.wall_dist * clist->rlist.x_ray_dir; clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); - clist->rlist.tex_x = (int)(clist->rlist.wall_hit_x * - (double)clist->tlist[clist->w_side].img_w); + 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) - clist->rlist.tex_x = clist->tlist[clist->w_side].img_w - - clist->rlist.tex_x - 1; + clist->tlist[clist->w_side].tex_x = clist->tlist[clist->w_side].img_w + - clist->tlist[clist->w_side].tex_x - 1; if (clist->rlist.side == 1 && clist->rlist.y_ray_dir < 0) - clist->rlist.tex_x = clist->tlist[clist->w_side].img_w - - clist->rlist.tex_x - 1; + clist->tlist[clist->w_side].tex_x = clist->tlist[clist->w_side].img_w + - clist->tlist[clist->w_side].tex_x - 1; } static void @@ -83,7 +83,7 @@ void cl->rlist.wall_b = wl->y_size - 1; ft_choose_tex(cl); ft_calc_tex(cl); - ft_draw_verline(cl, i, cl->rlist.wall_t - 1, cl->rlist.wall_b); + ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); i++; } } |