Skip to content

Commit

Permalink
camera with adjustable fov
Browse files Browse the repository at this point in the history
  • Loading branch information
alysssssa committed Apr 29, 2023
1 parent 9defe76 commit 6ebf147
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
11 changes: 8 additions & 3 deletions raytracer/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

class camera {
public:
camera() {
camera(
double vfov, // vertical field-of-view in degrees
double aspect_ratio
) {
// x - right, y - up, z - out of the screen
auto aspect_ratio = 16.0 / 9.0;
auto viewport_height = 2.0;
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);
Expand Down
19 changes: 7 additions & 12 deletions raytracer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,17 @@ int main() {
const int max_depth = 50;

// world
auto R = cos(pi/4);
hittable_list world;

auto material_ground = make_shared<lambertian>(colour(0.8, 0.8, 0.0));
auto material_center = make_shared<lambertian>(colour(0.1, 0.2, 0.5));
auto material_left = make_shared<dielectric>(1.5);
auto material_right = make_shared<metal>(colour(0.8, 0.6, 0.2), 0.0);
auto material_left = std::make_shared<lambertian>(colour(0, 0, 1));
auto material_right = std::make_shared<lambertian>(colour(1, 0, 0));

world.add(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));
// making a hollow glass sphere - with negative radius (the geometry is unaffected, but the surface normal points inward
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));
world.add(std::make_shared<sphere>(point3(-R, 0, -1), R, material_left));
world.add(std::make_shared<sphere>(point3(R, 0, -1), R, material_right));

// camera
camera cam;
// camera - scene with wide-angle view
camera cam(90, aspect_ratio);

// ppm format:
// P3 - colours in ASCII; column number; row number; 255 - for max colour;
Expand Down

0 comments on commit 6ebf147

Please sign in to comment.