Beispiel #1
0
t_bool	plane_intersection(t_ray *r, t_sphere *s, t_f64 *t0, t_f64 *t1)
{
	t_f64	denom;
	t_vec3f	v_n;
	t_vec3f	c;
	t_vec3f	f;

	v_n = normal_vec3f(&s->pos);
	denom = dot_vec3f(&v_n, &r->dir);
	if (denom > 1e-6)
	{
		f = sub_vec3f(&s->pos, &r->origin);
		*t1 = dot_vec3f(&f, &v_n) / denom;
		*t0 = *t1;
		c = scale_vec3f(&r->dir, *t0);
		c = add_vec3f(&c, &r->origin);
		if (!((c.x > s->pos.x) && (c.x < (s->pos.x + 10))))
			return (FALSE);
		if (!((c.y > s->pos.y) && (c.y < (s->pos.y + 10))))
			return (FALSE);
		if (!((c.x > s->pos.z) && (c.y < (s->pos.y + 10))))
			return (FALSE);
		return (*t0 >= 0);
	}
	return (FALSE);
}
Beispiel #2
0
void		cast_ray(int x, int y, t_vec3f *pixel, t_interface *env)
{
	t_vec3f	dir;
	t_ray	ray;
	t_f64	xx;
	t_f64	yy;

	xx = (2 * ((x + 0.5) * (1.0 / WIDTH)) - 1) * env->camera.angle * ARATIO;
	yy = (1 - 2 * ((y + 0.5) * (1.0 / HEIGHT))) * env->camera.angle;
	dir = new_vec3f(xx, yy, 0);
	dir = add_vec3f(&dir, &env->camera.up);
	ray = new_ray(env->camera.pos, normal_vec3f(&dir));
	*pixel = trace_ray(&ray, env->objects, 0);
}