示例#1
0
文件: reflection.c 项目: jikiliou/rt
t_color		reflection(t_scene *scene, t_inter *inter, t_color pixel_color, int level)
{
	t_color	reflec;
	t_ray	ray;

	if (level >= MAX_REFLEC)
		return (pixel_color);
	if (inter->obj->mat->reflec > 0)
	{
		ray.o = inter->pos;
		ray.dir = inter->reflect;
		reflec = ray_go_to_the_world_and_dont_forget_to_draw(scene, &ray, level + 1);
		reflec = add_color(mult_color(reflec, inter->obj->mat->reflec),
							mult_color(pixel_color, (1 - inter->obj->mat->reflec)));
	}
	else
		reflec = pixel_color;
	return (reflec);
}
示例#2
0
文件: light.c 项目: bsisic42/42
u_int		calc_light(t_mlx *mlx, t_xyz *spot)
{
	t_xyz	p;
	t_xyz	light;
	t_xyz	normal;
	double	cos_a;
	u_int	new_color;

	p = (t_xyz){mlx->eye.x + mlx->k * mlx->vector.x,
				mlx->eye.y + mlx->k * mlx->vector.y,
				mlx->eye.z + mlx->k * mlx->vector.z};
	light = (t_xyz){spot->x - p.x, spot->y - p.y, spot->z - p.z};
	new_color = mlx->cur_obj->color;
	get_normal(&normal, &p, mlx->cur_obj);
	cos_a = (normal.x * light.x + normal.y * light.y + normal.z * light.z)
		/ (norme_vector(&normal) * norme_vector(&light));
	new_color = (cos_a >= 0 && cos_a <= 1)
		? mult_color(mlx->cur_obj->color, cos_a) : 0;
	return (new_color);
}