diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_textures.c | 15 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 8 | ||||
-rw-r--r-- | src/ft_raycasting.c | 10 |
3 files changed, 26 insertions, 7 deletions
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 |