-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.hpp
71 lines (66 loc) · 2.52 KB
/
camera.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Homepage: https://github.com/ananthvk/cpp-raytracer
#pragma once
#include "commons.hpp"
#include "config.h"
#include <iostream>
#include <ostream>
using namespace linalg::ostream_overloads;
// An abstract class which represents a camera and is used to get rays according
// to the pixel coordinates
class Camera
{
public:
virtual Ray get_ray(int row, int col, bool sample = false) const = 0;
virtual void debug_info(std::ostream &os) const = 0;
virtual ~Camera() {}
};
// A simple camera class which implements depth-of-field, field-of-view, lookat and position
// Note unless specified, all angle values are in radians
class MovableCamera : public Camera
{
private:
// A vector which represents the alignment of the camera
vec3 up;
// A vector which points to the right of the camera
vec3 right;
// The direction the camera is looking at
vec3 direction;
// Position of the camera
vec3 position;
// Distance between the camera and the viewport screen
double focal_length;
// FOV angle
double fov;
// Width of the image (in pixels)
int image_width;
// Height of the image (in pixels)
int image_height;
// Aspect ratio is width / height
double aspect_ratio;
// Width of the virtual viewport (in metres)
double viewport_width;
// Height of the virtual viewport (in metres)
double viewport_height;
// It is the horizontal spacing between two adjacent pixels in the viewport
double delta_x;
// It is the vertical spacing between two adjacent pixels in the viewport
double delta_y;
// The angle through which the rays are spread out from the origin of the camera
double defocus_angle;
// The radius of disk from which rays are cast to the screen
double defocus_radius;
/// Returns a random origin for a new ray on the defocus disk
vec3 get_defocused_origin() const;
public:
MovableCamera(const Config &conf);
/// Returns a ray which passes through a pixel at (row, col)
/// Note: pixels start from (0,0), which is the top left corner
/// @param row y coordinate or row of the pixel
/// @param col x coordinate or column of the pixel
/// @param sample Randomize the ray or not(by default, false)
/// @return A ray which passes through the given pixel from the center of the camera
Ray get_ray(int row, int col, bool sample = false) const override;
/// Prints debug information to the given stream
/// @param os - std::ostream object
void debug_info(std::ostream &os) const override;
};