-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
38 lines (32 loc) · 1.16 KB
/
Copy pathCamera.cpp
File metadata and controls
38 lines (32 loc) · 1.16 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
33
34
35
36
37
38
#include "Camera.h"
#include "Ray.h"
// Empty constructor
Camera::Camera()
{
float aspectRatio = 16.0f / 9.0f;
float viewportHeight = 2.0f;
float viewportWidth = aspectRatio * viewportHeight;
float focalLength = 1.0f;
origin = glm::vec3(0.0f, 0.0f, 0.0f);
horizontal = glm::vec3(viewportWidth, 0.0f, 0.0f);
vertical = glm::vec3(0.0f, viewportHeight, 0.0f);
lowerLeftCorner = origin - (horizontal / 2.0f) - (vertical / 2.0f) - glm::vec3(0.0f, 0.0f, focalLength);
}
// Constructor with screen resoluiton as input
Camera::Camera(glm::ivec2 _res)
{
float aspectRatio = (float)_res.x / (float)_res.y;
float viewportHeight = 2.0f;
float viewportWidth = aspectRatio * viewportHeight;
float focalLength = 1.0f;
origin = glm::vec3(0.0f, 0.0f, 0.0f);
horizontal = glm::vec3(viewportWidth, 0.0f, 0.0f);
vertical = glm::vec3(0.0f, viewportHeight, 0.0f);
lowerLeftCorner = origin - (horizontal / 2.0f) - (vertical / 2.0f) - glm::vec3(0.0f, 0.0f, focalLength);
}
// Casts ray from camera
Ray Camera::getRay(float _u, float _v)
{
// Cast ray from origin of camera to specified spot in viewport
return Ray(origin, lowerLeftCorner + (_u * horizontal) + (_v * vertical) - origin);
}