-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
50 lines (42 loc) · 1.77 KB
/
Camera.cpp
File metadata and controls
50 lines (42 loc) · 1.77 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
39
40
41
42
43
44
45
46
47
48
49
50
//
// Created by user on 2/15/2021.
//
/* Start Header -------------------------------------------------------
* Copyright (C) 2020 DigiPen Institute of Technology.
* Reproduction or disclosure of this file or its contents without the prior
* written consent of DigiPen Institute of Technology is prohibited.
* File Name: Camera.cpp
* Purpose: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Language: C++, G++
* Platform: g++ (Ubuntu 9.3.0-10ubuntu2) 9.3, ThinkPad T430u, Nvidia GT 620M,
* OpenGL version string: 4.6.0 NVIDIA 390.138
* Project: gnu
* Author: Roland Shum, roland.shum@digipen.edu
* Creation date: 2/15/2021
* End Header --------------------------------------------------------*/
#include "stdafx.h"
#include "Camera.h"
#include "Ray.h"
Ray Camera::getRay(double s, double t) const {
vec3 rd = lensRadius * RandomUnitDisk();
vec3 offset = u * rd.x + v * rd.y;
return Ray(origin + offset, lowerLeftCornor + s * horizontal + t * vertical - origin - offset,
randomDouble(time0, time1));
}
Camera::Camera(vec3 lookFrom, vec3 lookAt, vec3 up, double aspectRatio, double fov, double aperture, double focusDist,
double time0, double time1) {
const double theta = degreesToRadians(fov);
const double h = tan(theta/2);
const double viewportHeight = 2.0 * h;
const double viewportWidth = aspectRatio * viewportHeight;
w = glm::normalize(lookFrom - lookAt);
u = glm::normalize(glm::cross(up, w));
v = cross(w,u);
origin = lookFrom;
horizontal = focusDist * viewportWidth * u;
vertical = focusDist * viewportHeight * v;
lowerLeftCornor = origin - (horizontal / 2.0) - (vertical / 2.0) - focusDist * w;
lensRadius = aperture / 2;
this->time0 = time0;
this->time1 = time1;
}