Path Tracer
camera.hpp
1 #pragma once
2 
3 #include <common.hpp>
4 #include <camera/ray.hpp>
5 #include <utils.hpp>
6 #include <math3d/vec3.hpp>
7 //
8 using namespace ptracey;
9 namespace ptracey {
10 class camera {
11 public:
12  camera()
13  : camera(point3(0, 0, -1), point3(0, 0, 0),
14  vec3(0, 1, 0), 40, 1, 0, 10) {}
15 
16  camera(point3 lookfrom, point3 lookat, vec3 vup,
17  Real vfov, // vertical field-of-view in degrees
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;
24 
25  w = unit_vector(lookfrom - lookat);
26  u = unit_vector(cross(vup, w));
27  v = cross(w, u);
28 
29  origin = lookfrom;
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;
34 
35  lens_radius = aperture / 2;
36  time0 = _time0;
37  time1 = _time1;
38  }
39 
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);
48  }
49 
50 private:
51  point3 origin;
52  point3 lower_left_corner;
53  vec3 horizontal;
54  vec3 vertical;
55  vec3 u, v, w;
56  Real lens_radius;
57  Real time0, time1; // shutter open/close times
58 };
59 }
ptracey::ray
Definition: ray.hpp:8
ptracey::camera
Definition: camera.hpp:10
ptracey::vec3
Definition: vec3.hpp:7