Ejemplo n.º 1
0
static double normalize_v( double *a )
{
	double const k = 1./length_v(a);
	a[0] *= k;
	a[1] *= k;
	a[2] *= k;
}
Ejemplo n.º 2
0
void normalise_v(Vertex &v) {
  GLdouble length = length_v(v);
  if (length==0) { length = 1; }
  v.x/=length;
  v.y/=length;
  v.z/=length;
};
Ejemplo n.º 3
0
t_surface			*is_in_light(t_surface *surface, t_scene *scene,
	t_light *light, double *dot_light)
{
	t_vector		light_ray;
	t_double3		light_distance;
	t_surface		*light_intersect;
	double			dot_light_dir;

	light_ray.pos = surface->point;
	light_distance = v_minus_v(light->pos, surface->point);
	light_ray.dir = normalize(light_distance);
	*dot_light = dot_product(light_ray.dir, surface->normal);
	*dot_light = max_double(0, *dot_light);
	if (length_v(light->dir) > 0.01)
	{
		dot_light_dir = abs_double(dot_product(light_ray.dir, normalize(light->dir)));
		dot_light_dir = max_double(0, dot_light_dir);
		*dot_light *= dot_light_dir;
	}
	light_intersect = intersect(light_ray, scene, surface->object);
	if (light_intersect->object != NULL)
		light_intersect->distance -= length_v(light_distance);
	return (light_intersect);
}
Ejemplo n.º 4
0
t_double3			direct_light(t_vector ray, t_scene *scene,
	t_double3 color_hit)
{
	t_light			*light;
	t_double3		light_vector;
	t_surface		*light_intersect;
	double			dot_light;

	light = scene->light;
	while (light)
	{
		light_vector = v_minus_v(light->pos, ray.pos);
		dot_light = dot_product(normalize(light_vector), ray.dir);
		dot_light = max_double(0, exp(dot_light +  7.51745) -5000);
		light_intersect = intersect((t_vector){scene->camera.pos,
			normalize(light_vector)}, scene, NULL);
		if (light_intersect->object == NULL || (light_intersect->distance >
			length_v(light_vector)))
			color_hit = color_mix(light->color, dot_light, color_hit);
		free(light_intersect);
		light = light->next;
	}
	return (color_hit);
}