-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.h
More file actions
33 lines (26 loc) · 1.06 KB
/
Copy pathcamera.h
File metadata and controls
33 lines (26 loc) · 1.06 KB
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
#pragma once
#include "ray.h"
#include "vector3.h"
class Camera {
public:
Camera()
: m_lower_left_corner (Vector3(-2.0, -1.0, -1.0)),
m_horizontal (Vector3( 4.0, 0.0, 0.0)),
m_vertical (Vector3( 0.0, 2.0, 0.0)),
m_camera (Vector3( 0.0, 0.0, 0.0)) {}
// This returns a ray given by the horizontal and vertical fractional coordinates.
// Both u and v must be in the range [0, 1].
Ray get_ray(float u, float v) {
// Calculate a position on the viewing screen.
Vector3 screen_pos = m_lower_left_corner + u*m_horizontal + v*m_vertical;
// Calculate a ray from the camera through the position on the viewing screen.
return Ray(m_camera, screen_pos - m_camera);
} // get_ray
private:
// Position of camera.
Vector3 m_camera;
// Position of viewing screen.
Vector3 m_lower_left_corner;
Vector3 m_horizontal;
Vector3 m_vertical;
}; // class Camera