Camera positioning and orienting

This commit is contained in:
Armin Friedl 2022-07-30 21:03:30 +02:00
parent b8bdd91e40
commit 01d3166ae2
2 changed files with 13 additions and 10 deletions

View file

@ -5,24 +5,27 @@
class camera {
public:
camera(double vfov /*vertical field-of-view in degrees*/, double aspect_ratio) {
camera(point3 lookfrom, point3 lookat, vec3 vup, double vfov /*vertical field-of-view in degrees*/,
double aspect_ratio) {
auto theta = degrees_to_radians(vfov);
auto h = tan(theta / 2);
auto viewport_height = 2.0 * h;
auto viewport_width = aspect_ratio * viewport_height;
auto focal_length = 1.0;
origin = point3(0, 0, 0);
horizontal = vec3(viewport_width, 0.0, 0.0);
vertical = vec3(0.0, viewport_height, 0.0);
lower_left_corner =
origin - horizontal / 2 - vertical / 2 - vec3(0, 0, focal_length);
auto w = unit_vector(lookfrom - lookat);
auto u = unit_vector(cross(vup, w));
auto v = cross(w, u);
origin = lookfrom;
horizontal = viewport_width * u;
vertical = viewport_height * v;
lower_left_corner = origin - horizontal/2 - vertical/2 - w;
}
ray get_ray(double u, double v) const {
ray get_ray(double s, double t) const {
return ray(origin,
lower_left_corner + u * horizontal + v * vertical - origin);
lower_left_corner + s*horizontal + t*vertical - origin);
}
private:

View file

@ -59,7 +59,7 @@ int main() {
// Camera
camera cam(90, aspect_ratio);
camera cam(point3(-2,2,1), point3(0,0,-1), vec3(0,1,0), 90, aspect_ratio);
// Render