Beispiel #1
0
void	init_scene(t_scene **scene)
{
	t_coord	coord;
	t_vec3	v;

	init_coord(&coord, 0, 0, -50);
	init_vec3(&v, 0, 0, 1);
	//init_plane(scene, coord, v, 0x0000FF);

	init_coord(&coord, 0, -3, 0);
	init_vec3(&v, 0, 1, 0);
	init_plane(scene, coord, v, 0x00FF66);
	
	init_coord(&coord, -5, 4, -21);
	init_circle(scene, coord, 0xFFFFFF, 4);

	init_coord(&coord, 0, 4, -21);
	init_circle(scene, coord, 0xFF0000, 2);

	init_coord(&coord, 5, 2, -25);
	init_vec3(&v, 0, 0, 1);
	init_cylinder(scene, coord, v, 2, 0x0000FF);
	
	init_coord(&coord, -10, -2, -25);
	init_vec3(&v, 0, 0, 1);
	init_cone(scene, coord, v, 0x00FFFF);
}
int	intersect_shadow(float t, t_scene *scene, t_ray *ray)
{
	t_vec3	intersect_pt;
	t_ray	shadow;
	float	t_tmp;

	intersect_pt.x = ray->o.x + t * ray->d.x;
	intersect_pt.y = ray->o.y + t * ray->d.y;
	intersect_pt.z = ray->o.z + t * ray->d.z;
	init_coord(&shadow.o, 0, 0, -30);
	init_vec3(&(shadow.d), shadow.o.x - intersect_pt.x, shadow.o.y - intersect_pt.y, shadow.o.z - intersect_pt.z);
	t_tmp = -1;
	while (scene != NULL)
	{
		if (scene->type == CIRCLE)
			t_tmp = intersect_circle(&shadow, scene->object);
		else if (scene->type == PLANE)
			t_tmp = intersect_plane(&shadow, scene->object);
		else if (scene->type == CYLINDER)
			t_tmp = intersect_cylinder(&shadow, scene->object);
		if (t_tmp > 0)
		{
			return (1);
		}
		scene = scene->next;
	}
	return (0);
}