4 #include <camera/ray.hpp>
6 #include <math3d/vec3.hpp>
8 using namespace ptracey;
14 vec3(0, 1, 0), 40, 1, 0, 10) {}
18 Real aspect_ratio, Real aperture, Real focus_dist,
19 Real _time0 = 0, Real _time1 = 0) {
20 auto theta = degrees_to_radians(vfov);
21 auto h = tan(theta / 2);
22 auto viewport_height = 2.0 * h;
23 auto viewport_width = aspect_ratio * viewport_height;
25 w = unit_vector(lookfrom - lookat);
26 u = unit_vector(cross(vup, w));
30 horizontal = focus_dist * viewport_width * u;
31 vertical = focus_dist * viewport_height * v;
32 lower_left_corner = origin - horizontal / 2 -
33 vertical / 2 - focus_dist * w;
35 lens_radius = aperture / 2;
40 ray get_ray(Real s, Real t,
41 unsigned int wavelength = 1)
const {
42 vec3 rd = lens_radius * random_in_unit_disk();
43 vec3 offset = u * rd.x() + v * rd.y();
44 return ray(origin + offset,
45 lower_left_corner + s * horizontal +
46 t * vertical - origin - offset,
47 random_real(time0, time1), wavelength);