Add several parameters to camera.

This commit is contained in:
Faerbit 2020-06-07 00:17:33 +02:00
parent 3683a309c5
commit a35cf30535
2 changed files with 20 additions and 9 deletions

View File

@ -1,20 +1,30 @@
#ifndef CAMERA_H
#define CAMERA_H
#include <cmath>
#include "vec3.h"
class Camera {
public:
Camera() {
auto aspect_ratio = 16.0 / 9.0;
auto viewport_height = 2.0;
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 = std::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 {

View File

@ -49,8 +49,9 @@ int main() {
world.add(std::make_shared<Sphere>(Point3(-1, 0, -1), 0.5, std::make_shared<Dielectric>(1.45)));
world.add(std::make_shared<Sphere>(Point3(-1, 0, -1), -0.45, std::make_shared<Dielectric>(1.45)));
Camera cam;
Camera cam(Point3(-2, 2, 1), Point3(0, 0, -1), Vec3(0, 1, 0), 75, aspect_ratio);
auto image = std::make_unique<Color[]>(image_height*image_width);