Пример #1
0
void			ft_draw_raytracer(t_data *d, int x, int y)
{
	t_vect		inter;
	int			nb_obj;
	int			index[2];

	index[0] = 0;
	while (index[0] < d->img.size[0])
	{
		index[1] = 0;
		while (index[1] < d->img.size[1])
		{
			d->c.c = 0;
			nb_obj = ft_ray_tracing(d, index, &inter);
			if (nb_obj > -1)
				ft_getcolor(d, &inter, nb_obj);
			ft_put_pixel_to_image(d, index[0] + x, index[1] + y, d->c.c);
			index[1]++;
		}
		index[0]++;
	}
	write(2, BLUE, 7);
	write(2, "Draw: done\n", 11);
	write(2, END, 4);
}
Пример #2
0
void		ft_gen_fract(double (*fct)(t_env *, int, int), t_env *e)
{
	int		i;
	int		j;
	int		color;
	double	d;

	i = -1;
	while (++i <= e->height)
	{
		j = -1;
		while (++j <= e->width)
		{
			d = fct(e, i, j);
			color = ft_color(d, e);
			ft_put_pixel_to_image(e, j, i, color);
		}
	}
}
Пример #3
0
void		ft_render2(t_env env)
{
	t_color3	rgba;
	t_ray	ray;
	float	y;
	float	x;
	t_object arr[16];
	t_object light[16];
	float invW = 1 / (float)env.resolution.width;
	float invH = 1 / (float)env.resolution.height;
	float ratio = env.resolution.width / (float)env.resolution.height;
	float angle = tanf(M_PI * 0.5f * env.fov / 180.);

	ft_bzero(arr, sizeof(t_object) * 16);
	ft_bzero(light, sizeof(t_object) * 16);
	create_scene(parser(env.file), arr, light);
	y = 0;
	while (y < env.resolution.height)
	{
		x = 0;
		while (x < env.resolution.width)
		{
			ray.pos = env.pos_absolute_camera;
			ray.dir.x = (2. *(x * invW) - 1.) * angle * ratio;
			ray.dir.y = (1. - 2. * (y * invH)) * angle;
			ray.dir.z = 1;
			ray.dir = vector_unit(ray.dir);
			rgba = ft_trace_ray(arr, light, ray, 0, NULL, env);
			ft_put_pixel_to_image(env.img, x, y, rgba);
			x++;
		}
		y++;
	}
	dprintf(2, "The end\n");
	mlx_put_image_to_window(env.mlx, env.win, env.img.ptr, 0, 0);
}