Exemplo n.º 1
0
void	eb_trace_line(t_data *d, t_pos a, t_pos b, int color)
{
	int		x;
	int		y;

	if (a.x == b.x && a.y == b.y)
		return ;
	else if (eb_abs(b.x - a.x) >= eb_abs(b.y - a.y))
	{
		if (a.x > b.x)
			eb_swap_pos(&a, &b);
		x = a.x;
		while (x <= b.x)
		{
			y = a.y + ((b.y - a.y) * (x - a.x)) / (b.x - a.x);
			eb_put_pixel_to_img(d, x, y, color);
			x++;
		}
	}
	else
	{
		if (a.y > b.y)
			eb_swap_pos(&a, &b);
		y = a.y;
		while (y <= b.y)
		{
			x = a.x + ((b.x - a.x) * (y - a.y)) / (b.y - a.y);
			eb_put_pixel_to_img(d, x, y, color);
			y++;
		}
	}
}
Exemplo n.º 2
0
void	eb_search_wall(t_data *d, t_pos *pos, double alpha, t_colision *col)
{
	int		dist;
	double	x;
	double	y;
	int		colision;

	dist = 0;
	x = (double)pos->x;
	y = (double)pos->y;
	d->inter_colision = 0;
	while ((colision = eb_collision(d, pos)) <= 0)
	{
		if (d->save[4])
			eb_put_pixel_to_img(d, (pos->x * RM) / RA, (pos->y * RM) / RA,
				colision == -1 ? 0x23eb67 : 0xFFFFFF);
		if (colision < 0)
			d->inter_colision = colision;
		pos->x = (int)x;
		pos->y = (int)y;
		x = x + (cos(alpha) * 1);
		y = y + (sin(alpha) * 1);
		dist += 1;
	}
	col->face = colision;
	col->dist = (double)dist;
}
Exemplo n.º 3
0
void	eb_clean_map(t_img *img)
{
	int		x;
	int		y;

	x = 0;
	while (x <= WIDTH)
	{
		y = 0;
		while (y <= HEIGHT)
		{
			eb_put_pixel_to_img(img, x, y, 0x000000);
			y++;
		}
		x++;
	}
}
Exemplo n.º 4
0
void	display_pixel(t_img *img, int x, int y, t_ray *rayon)
{
	t_data		*d;
	t_vector	b;
	t_vector	ray_dir;
	int			color;

	d = data_init();
	vector_set(&b, x - (d->win_size_x / 2), y - (d->win_size_y / 2), 0);
	vector_set(&ray_dir, b.x - d->cam->x, b.y - d->cam->y, b.z - d->cam->z);
	vector_normalize(&ray_dir);
	vector_set(rayon->o, d->cam->x, d->cam->y, d->cam->z);
	vector_set(rayon->d, ray_dir.x, ray_dir.y, ray_dir.z);
	vector_normalize(rayon->d);
	color = color_pixel(rayon, 200000, DEPTH);
	eb_debug(ft_concat2("couleur du pixel : ", ft_lutohex(color)), 1);
	eb_put_pixel_to_img(img, x, y, color);
}
Exemplo n.º 5
0
void	eb_print_wend(t_data *d, double alpha, int dist, double dist_wall)
{
	double		height = ((d->dist_screen * (double)HEIGHT) / dist_wall) / 20;
	double hipotenus_wall = height / sin(alpha);
	double dist_wall_screen = (((double)HEIGHT / 2) / sin(alpha)) - hipotenus_wall;
	double dist_floor_screen = dist * dist_wall_screen / dist_wall;
	// alpha += d->map->alpha;
	double y = (HEIGHT - dist_floor_screen * sin(alpha)) / 2 + HEIGHT / 2;
	double x = WIDTH / 2 + dist_floor_screen * cos(alpha);
	// x *= -1;
	// double d->dist_screen = (WIDTH / 2) / tan((VISION * DEG_TO_RAD) / 2);
	// printf("x = %f, y = %f\n", x, y);

	x = (x >= WIDTH ? WIDTH : x);
	x = x < 0 ? 0 : x;
	y = (y >= HEIGHT ? HEIGHT : y);
	y = y < 0 ? 0 : y;
	eb_put_pixel_to_img(d, (int)x, (int)y, 0x23eb67);
}