Files
42_INT_10_cube3d/srcs/draw/draw_column.c

77 lines
1.8 KiB
C

#include "cube3d.h"
static void draw_floor_ceiling(t_game *game, t_rcast *rcast, t_txt *txt)
{
t_vec plan;
plan.start.x = rcast->ray_nb;
plan.end.x = rcast->ray_nb;
if (rcast->wall.vec.start.y > 0)
{
plan.start.y = rcast->screen_height;
plan.end.y = rcast->wall.vec.start.y;
draw_line(&game->img, &plan, txt->rgb_floor);
}
if (rcast->wall.vec.start.y < rcast->screen_height)
{
plan.start.y = rcast->wall.vec.end.y;
plan.end.y = 0;
draw_line(&game->img, &plan, txt->rgb_ceiling);
}
}
static void draw_txt_line(t_img *img, t_rcast *rcast, t_wall *wall, t_img *txt_img, int color)
{
(void)img;
(void)wall;
(void)txt_img;
(void)color;
// draw_line(img, &wall->vec, color);
int img_x;
img_x = (wall->posx * txt_img->width) / rcast->cell;
printf("img_x:%i\n", img_x);
// t_coord dist;
// int i;
// int j;
//
// dist.x = (*vec).end.x - (*vec).start.x;
// dist.y = (*vec).end.y - (*vec).start.y;
// 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)
{
int color_n;
int color_s;
int color_e;
int color_o;
(void)wall;
color_n = 0x00FF00FF;
color_s = 0x0000EEEE;
color_e = 0x00DDDD00;
color_o = 0x00CCCCCC;
draw_floor_ceiling(game, rcast, txt);
if (!rcast->is_x && rcast->slope_y > 0)
draw_txt_line(&game->img, rcast, wall, &txt->img_n, color_n);
if (!rcast->is_x && rcast->slope_y < 0)
draw_line(&game->img, &rcast->wall.vec, color_s);
if (rcast->is_x && rcast->slope_x > 0)
draw_line(&game->img, &rcast->wall.vec, color_e);
if (rcast->is_x && rcast->slope_x < 0)
draw_line(&game->img, &rcast->wall.vec, color_o);
}