aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/cub3d.h1
-rw-r--r--inc/cub3d_structs.h4
-rw-r--r--src/ft_draw_textures.c15
-rw-r--r--src/ft_draw_verline.c8
-rw-r--r--src/ft_raycasting.c10
5 files changed, 29 insertions, 9 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 2362d07..d3e018e 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -78,5 +78,6 @@ int ft_key_release(int keycode, t_cub *clist);
int8_t ft_check_ext(const char *filep, const char *ext);
int32_t ft_convert_keycode(const int32_t tmp_code);
int ft_key_loop(t_cub *cl);
+void ft_draw_texture(t_cub *cl, int x, int y, int tex_y);
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index e2d5100..18edfd8 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -36,6 +36,8 @@ typedef struct s_img
int endian;
int img_w;
int img_h;
+ int tex_x;
+ int tex_y;
} t_img;
typedef struct s_rgb
@@ -83,8 +85,6 @@ typedef struct s_ray
size_t sqy;
uint8_t hit;
double wall_hit_x;
- int tex_x;
- int tex_y;
double step_tex_v;
} t_ray;
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