From a25845a1e0c96111f42e96c9c87d33f0c42180bc Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 18 Feb 2020 16:18:09 +0100 Subject: hmmmmmmmmmmm --- src/ft_draw_scene.c | 2 +- src/ft_draw_verline.c | 3 ++- src/ft_raycasting.c | 1 - src/main.c | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index ec2cc89..60198e9 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -18,7 +18,7 @@ void ft_draw_scene(t_cub *clist) { - mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr); + /*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_verline.c b/src/ft_draw_verline.c index 0fad33a..0b97cc5 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -60,7 +60,8 @@ int8_t ft_choose_tex(cl); while (y <= y2) { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x0000eeaa : 0x0000ffaa; + cl->rlist.step_tex_v = 1.0 * cl->tlist[clist->w_side].img_w - cl->rlist.line_h; + /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ y++; } ft_draw_floor(cl, y, x); diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index ff73893..9a89dc4 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -71,7 +71,6 @@ void i = 0; wl = cl->wlist; - ft_wall_tex_init(cl); while (i < wl->x_size) { ft_initray(cl, i); diff --git a/src/main.c b/src/main.c index d102838..52bb211 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,7 @@ int ft_parse_map(argv[1], clist); if (ft_init_winlx(clist) < 0) return (ft_exit(3, clist)); + ft_wall_tex_init(clist); ft_draw_scene(clist); ft_hooks_and_loops(clist->wlist, clist); return (0); -- cgit v1.2.3 From f8cd383a3ed07be0fb3ad78ad25a0c053c53ae3d Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 18 Feb 2020 18:18:01 +0100 Subject: pas loin --- src/ft_draw_textures.c | 15 +++++++++++++++ src/ft_draw_verline.c | 8 ++++++-- src/ft_raycasting.c | 10 +++++----- 3 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 46e51d7..d412998 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -21,6 +21,21 @@ ** 4 : sprite */ +void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) +{ + /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ + 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 + 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 0b97cc5..5f93ce2 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -42,6 +42,7 @@ int8_t { int32_t y; int32_t t; + int32_t d; if (y1 < 0) y1 = 0; @@ -60,8 +61,11 @@ int8_t ft_choose_tex(cl); while (y <= y2) { - cl->rlist.step_tex_v = 1.0 * cl->tlist[clist->w_side].img_w - cl->rlist.line_h; - /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ + d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + cl->tlist[cl->w_side].tex_y = ((d * cl->tlist[cl->w_side].img_w) + / cl->rlist.line_h) / 256; + ft_draw_texture(cl, x, y, cl->tlist[cl->w_side].tex_y); + /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ y++; } ft_draw_floor(cl, y, x); diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 9a89dc4..3e658e3 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 * + 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 -- cgit v1.2.3 From cbf73a5e2d4f1fda6e6267854954b78417678540 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 18 Feb 2020 18:57:45 +0100 Subject: gang --- src/ft_draw_textures.c | 4 +++- src/ft_draw_verline.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index d412998..ec20f33 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -12,6 +12,7 @@ #include #include +#include /* ** 0 : no @@ -23,6 +24,7 @@ void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) { + /*printf("%c\n", cl->img.ptr[x * 4 + 4 * (cl->img.sizeline * y)] );*/ /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ 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 * @@ -33,7 +35,7 @@ void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) 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 + 4 * cl->wlist->x_size * y + 3] = (char)0; + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; } void ft_choose_tex(t_cub *clist) diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 5f93ce2..7d24301 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include +#include static void ft_draw_floor(t_cub *cl, int32_t y, int32_t x) @@ -59,14 +60,16 @@ int8_t y = y1; ft_draw_ceil(cl, y, x); ft_choose_tex(cl); - while (y <= y2) + while (y1 < y2) { d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + printf(" y : %d\ny_size : %d\nd : %d\nline_h : %d\n", y, cl->wlist->y_size, d, cl->rlist.line_h); cl->tlist[cl->w_side].tex_y = ((d * cl->tlist[cl->w_side].img_w) / cl->rlist.line_h) / 256; + /*printf("w_side : %d\nd : %d\ntex_y : %d\n", cl->w_side, d, cl->tlist[cl->w_side].tex_y);*/ ft_draw_texture(cl, x, y, cl->tlist[cl->w_side].tex_y); /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ - y++; + y1++; } ft_draw_floor(cl, y, x); return (0); -- cgit v1.2.3 From 2a25aa55bdf6fcca6a9b7dd51542950fdab2e707 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Tue, 18 Feb 2020 20:05:42 +0100 Subject: okok --- src/ft_draw_textures.c | 26 ++++++++++++++++++++++---- src/ft_draw_verline.c | 12 ++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index ec20f33..942e386 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -10,6 +10,7 @@ /* */ /* ************************************************************************** */ +#include #include #include #include @@ -24,16 +25,33 @@ void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) { + /* t_rgb rgb; */ /*printf("%c\n", cl->img.ptr[x * 4 + 4 * (cl->img.sizeline * y)] );*/ /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ - 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 * + /* ft_printf("DATA {{{{{%hd}}}}}\nW_SIDE> %d\n\n\n", */ + /* (int16_t)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->w_side); */ + /* rgb.r = */ + /* (int8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * */ + /* cl->tlist[cl->w_side].img_h * tex_y]; */ + /* rgb.g = */ + /* (int8_t)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]; */ + /* rgb.b = */ + /* (int8_t)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]; */ + /* *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); */ + + + 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 * + (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 * + (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; } diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 7d24301..65958ca 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -60,16 +60,16 @@ int8_t y = y1; ft_draw_ceil(cl, y, x); ft_choose_tex(cl); - while (y1 < y2) + while (y < y2) { d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; - printf(" y : %d\ny_size : %d\nd : %d\nline_h : %d\n", y, cl->wlist->y_size, d, cl->rlist.line_h); - cl->tlist[cl->w_side].tex_y = ((d * cl->tlist[cl->w_side].img_w) - / cl->rlist.line_h) / 256; + (d <= 0) ? (d = 1) : 0; + /* printf("y : %d\ny_size : %d\nd : %d\nline_h : %d\n", y1, cl->wlist->y_size, d, cl->rlist.line_h); */ + cl->tlist[cl->w_side].tex_y = ((d * cl->tlist[cl->w_side].img_w) / cl->rlist.line_h) / 256; /*printf("w_side : %d\nd : %d\ntex_y : %d\n", cl->w_side, d, cl->tlist[cl->w_side].tex_y);*/ ft_draw_texture(cl, x, y, cl->tlist[cl->w_side].tex_y); - /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ - y1++; + /* (int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa; */ + y++; } ft_draw_floor(cl, y, x); return (0); -- cgit v1.2.3 From 01ce065c54d205b1d8432eebfa350f57e6f6c3a8 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 19 Feb 2020 16:34:13 +0100 Subject: yes :^) ! --- src/ft_draw_textures.c | 19 ------------------- src/ft_draw_verline.c | 31 ++++++++----------------------- src/ft_raycasting.c | 4 ++-- 3 files changed, 10 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 942e386..25a6863 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -25,25 +25,6 @@ void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) { - /* t_rgb rgb; */ - /*printf("%c\n", cl->img.ptr[x * 4 + 4 * (cl->img.sizeline * y)] );*/ - /**(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa;*/ - /* ft_printf("DATA {{{{{%hd}}}}}\nW_SIDE> %d\n\n\n", */ - /* (int16_t)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->w_side); */ - /* rgb.r = */ - /* (int8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * */ - /* cl->tlist[cl->w_side].img_h * tex_y]; */ - /* rgb.g = */ - /* (int8_t)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]; */ - /* rgb.b = */ - /* (int8_t)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]; */ - /* *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); */ - - 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]; diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 65958ca..6cbdc00 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -39,36 +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) { d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; - (d <= 0) ? (d = 1) : 0; - /* printf("y : %d\ny_size : %d\nd : %d\nline_h : %d\n", y1, cl->wlist->y_size, d, cl->rlist.line_h); */ - cl->tlist[cl->w_side].tex_y = ((d * cl->tlist[cl->w_side].img_w) / cl->rlist.line_h) / 256; - /*printf("w_side : %d\nd : %d\ntex_y : %d\n", cl->w_side, d, cl->tlist[cl->w_side].tex_y);*/ - ft_draw_texture(cl, x, y, cl->tlist[cl->w_side].tex_y); - /* (int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x2200ffaa : 0x0000ffaa; */ + 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 3e658e3..394d6dc 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -26,7 +26,7 @@ void clist->rlist.wall_dist * clist->rlist.x_ray_dir; 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); + (double)clist->tlist[clist->w_side].img_w); if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) clist->tlist[clist->w_side].tex_x = clist->tlist[clist->w_side].img_w - clist->tlist[clist->w_side].tex_x - 1; @@ -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++; } } -- cgit v1.2.3