Tracer
camera.h
1 #ifndef camera_h
2 #define camera_h
3 
4 #include <curand_kernel.h>
5 #include "ray.h"
6 #include "vec3.h"
7 
8 
9 class camera {
10 public:
11  float width;//create constant width&length
12  float height;
13  vec3 orgin;
14  vec3 left_corner;
15  vec3 horizontal;
16  vec3 vertical;
17  vec3 u, v, w;
18  float lens_radius;
19  __device__ camera(vec3 from, vec3 lookat, vec3 vup, float deg, float aspect,
20  float aperture, float focus) {
21  lens_radius = aperture / 2.0f;
22  float rad = deg * 3.14159265359f / 180.0f;
23  height = tan(rad / 2.0f);
24  width = height * aspect;
25 
26  orgin = from;
27  w = (from - lookat).normalize();
28  u = (vup.cross(w)).normalize();
29  v = w.cross(u);
30 
31  left_corner = orgin - u * width * focus - v * height * focus - w * focus;
32  horizontal = u * 2.0f * width * focus;
33  vertical = v * 2.0f * height * focus;
34  }
35 
36  __device__ ray get_ray(float a, float b, curandState* local_rand_state) {
37  vec3 rd = random_unit_sphere(local_rand_state) * lens_radius;
38  vec3 offset = u * rd.x + v * rd.y;
39  return ray(orgin + offset, left_corner + horizontal * a + vertical * b - orgin - offset);
40  }
41 };
42 
43 #endif
Definition: vec3.h:10
Definition: ray.h:4
Definition: camera.h:9