52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#ifndef CAMERA_H
|
|
#define CAMERA_H
|
|
|
|
#include "rtweekend.hpp"
|
|
|
|
struct camera {
|
|
/* Attributes */
|
|
point3 origin;
|
|
point3 lower_left_corner;
|
|
vec3 horizontal;
|
|
vec3 vertical;
|
|
vec3 u,v,w;
|
|
float lens_radius;
|
|
|
|
/* Constructors */
|
|
camera(point3 lookfrom,
|
|
point3 lookat,
|
|
vec3 vup,
|
|
float vfov,
|
|
float aspect_ratio,
|
|
float aperture,
|
|
float focus_dist)
|
|
{
|
|
float theta = degrees_to_radians(vfov);
|
|
float h = tan(theta/2);
|
|
float viewport_height = 2.0 * h;
|
|
float viewport_width = aspect_ratio * viewport_height;
|
|
|
|
w = normalize(lookfrom - lookat);
|
|
u = normalize(cross(vup,w));
|
|
v = cross(w, u);
|
|
|
|
origin = lookfrom;
|
|
horizontal = focus_dist * viewport_width * u;
|
|
vertical = focus_dist * viewport_height * v;
|
|
lower_left_corner = origin - horizontal/2 - vertical/2 - focus_dist*w;
|
|
|
|
lens_radius = aperture/2;
|
|
}
|
|
|
|
/* Methods */
|
|
|
|
ray get_ray(float s, float t, int32_t thread_id = 0) const
|
|
{
|
|
vec3 rd = lens_radius * random_in_unit_disk(thread_id);
|
|
vec3 offset = u * rd.x + v * rd.y;
|
|
|
|
return ray(origin + offset, lower_left_corner + s*horizontal + t*vertical - origin - offset);
|
|
};
|
|
};
|
|
|
|
#endif
|