Exemplo n.º 1
0
bool yz_rect::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
	double t = (k - r.origin().x()) / r.direction().x();

	if (t<t_min || t>t_max) return false;

	double y = r.origin().y() + t*r.direction().y();
	double z = r.origin().z() + t*r.direction().z();

	if (y<y0 || y>y1 || z<z0 || z>z1) return false;

	rec.u = (y - y0) / (y1 - y0);
	rec.v = (z - z0) / (z1 - z0);
	rec.t = t;
	rec.mat_ptr = mat_ptr;
	rec.point = r.point_at_parameter(t);
	rec.normal = vec3(1.0, 0.0, 0.0);
	return true;
}