-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.cpp
38 lines (34 loc) · 1.05 KB
/
Camera.cpp
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
//
// Camera.cpp
// Curvature
//
// Created by Simon Demeule on 2019-03-29.
// Copyright © 2019 Simon Demeule. All rights reserved.
//
#include "Camera.hpp"
#include <math.h>
Camera::Camera(glm::vec3 originNew, glm::vec3 frontNew, glm::vec3 topNew, float fieldOfViewNew, float focalLengthNew, float aspectRatioNew) :
origin(originNew),
front(glm::normalize(frontNew)),
top(glm::normalize(topNew)),
right(glm::normalize(glm::cross(frontNew, topNew))),
fieldOfView(fieldOfViewNew),
focalLength(focalLengthNew),
aspectRatio(aspectRatioNew)
{}
// cast a ray from normalized coordinates
// input:
// x -> [-1, -1]
// y -> [-1 / aspectRatio, 1 / aspectRatio]
Ray Camera::castNormalized(glm::vec2 normalizedCoordinates) {
static float scalar = std::tanf(fieldOfView / 360.0 * M_PI) * aspectRatio;
Ray ray;
ray.origin = origin;
ray.direction = glm::normalize(
front +
right * (normalizedCoordinates.x * scalar) +
top * (normalizedCoordinates.y * scalar)
);
ray.isCameraRay = true;
return ray;
}