textures start to appears
This commit is contained in:
@@ -36,6 +36,7 @@ typedef struct s_wall
|
|||||||
int height;
|
int height;
|
||||||
int delta;
|
int delta;
|
||||||
int posx;
|
int posx;
|
||||||
|
int imgx;
|
||||||
} t_wall;
|
} t_wall;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -20,7 +20,19 @@ static void draw_floor_ceiling(t_game *game, t_rcast *rcast, t_txt *txt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_txt_line(t_img *img, t_rcast *rcast, t_wall *wall, t_img *txt_img, int color)
|
static int get_texture(t_img *img, int imgx, int j, int height)
|
||||||
|
{
|
||||||
|
char *color;
|
||||||
|
int y;
|
||||||
|
int position;
|
||||||
|
|
||||||
|
y = (j * img->height) / height;
|
||||||
|
position = y * img->szl + imgx * (img->bpp / 8);
|
||||||
|
color = img->data + position;
|
||||||
|
return (*(int*)color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_txt_column(t_img *img, t_rcast *rcast, t_wall *wall, t_img *txt_img, int color)
|
||||||
{
|
{
|
||||||
(void)img;
|
(void)img;
|
||||||
(void)wall;
|
(void)wall;
|
||||||
@@ -30,26 +42,18 @@ static void draw_txt_line(t_img *img, t_rcast *rcast, t_wall *wall, t_img *txt_i
|
|||||||
// draw_line(img, &wall->vec, color);
|
// draw_line(img, &wall->vec, color);
|
||||||
|
|
||||||
int img_x;
|
int img_x;
|
||||||
|
int j;
|
||||||
|
|
||||||
img_x = (wall->posx * txt_img->width) / rcast->cell;
|
img_x = (wall->posx * txt_img->width) / rcast->cell;
|
||||||
printf("img_x:%i\n", img_x);
|
//printf("img_x:%i - img_width:%i\n", img_x, txt_img->width);
|
||||||
|
|
||||||
// t_coord dist;
|
j = 0;
|
||||||
// int i;
|
while (j < wall->height)
|
||||||
// int j;
|
{
|
||||||
//
|
color = get_texture(txt_img, img_x, j, wall->height);
|
||||||
// dist.x = (*vec).end.x - (*vec).start.x;
|
draw_pixel(img, wall->vec.start.x, wall->vec.start.y + j, color);
|
||||||
// dist.y = (*vec).end.y - (*vec).start.y;
|
j++;
|
||||||
// i = 0;
|
}
|
||||||
// j = 0;
|
|
||||||
// while (ft_abs(i) <= ft_abs(dist.x) && ft_abs(j) <= ft_abs(dist.y))
|
|
||||||
// {
|
|
||||||
// draw_pixel(img, (*vec).start.x + i, (*vec).start.y + j, color);
|
|
||||||
// if (!ft_abs(dist.x) || ft_abs(j) < ft_abs(i * dist.y / dist.x))
|
|
||||||
// j += ft_sign(dist.y);
|
|
||||||
// else
|
|
||||||
// i += ft_sign(dist.x);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_column(t_game *game, t_rcast *rcast, t_wall *wall, t_txt *txt)
|
void draw_column(t_game *game, t_rcast *rcast, t_wall *wall, t_txt *txt)
|
||||||
@@ -66,7 +70,7 @@ void draw_column(t_game *game, t_rcast *rcast, t_wall *wall, t_txt *txt)
|
|||||||
color_o = 0x00CCCCCC;
|
color_o = 0x00CCCCCC;
|
||||||
draw_floor_ceiling(game, rcast, txt);
|
draw_floor_ceiling(game, rcast, txt);
|
||||||
if (!rcast->is_x && rcast->slope_y > 0)
|
if (!rcast->is_x && rcast->slope_y > 0)
|
||||||
draw_txt_line(&game->img, rcast, wall, &txt->img_n, color_n);
|
draw_txt_column(&game->img, rcast, wall, &txt->img_n, color_n);
|
||||||
if (!rcast->is_x && rcast->slope_y < 0)
|
if (!rcast->is_x && rcast->slope_y < 0)
|
||||||
draw_line(&game->img, &rcast->wall.vec, color_s);
|
draw_line(&game->img, &rcast->wall.vec, color_s);
|
||||||
if (rcast->is_x && rcast->slope_x > 0)
|
if (rcast->is_x && rcast->slope_x > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user