Camera view geometry

This commit is contained in:
Armin Friedl 2022-07-30 20:50:18 +02:00
parent 0a0080ce80
commit b8bdd91e40
2 changed files with 23 additions and 20 deletions

View file

@ -5,9 +5,11 @@
class camera {
public:
camera() {
auto aspect_ratio = 16.0 / 9.0;
auto viewport_height = 2.0;
camera(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;

View file

@ -54,11 +54,12 @@ int main() {
make_shared<sphere>(point3(0.0, -100.5, -1.0), 100.0, material_ground));
world.add(make_shared<sphere>(point3(0.0, 0.0, -1.0), 0.5, material_center));
world.add(make_shared<sphere>(point3(-1.0, 0.0, -1.0), 0.5, material_left));
world.add(make_shared<sphere>(point3(-1.0, 0.0, -1.0), -0.4, material_left));
world.add(make_shared<sphere>(point3(1.0, 0.0, -1.0), 0.5, material_right));
// Camera
camera cam;
camera cam(90, aspect_ratio);
// Render