-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.cpp
More file actions
51 lines (43 loc) · 1.38 KB
/
camera.cpp
File metadata and controls
51 lines (43 loc) · 1.38 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
51
#include "camera.hpp"
namespace trz
{
void camera::set_position(vec3 position) {
pos = position;
}
void camera::set_direction(vec3 direction) {
dir = direction;
}
void camera::set_orthographic_projection(float left, float right, float top, float bottom, float near, float far)
{
projMatrix = {{0}};
projMatrix.m[0][0] = 2.f / (right - left);
projMatrix.m[0][3] = -(right + left) / (right - left);
projMatrix.m[1][1] = 2.f / (top - bottom);
projMatrix.m[1][3] = -(top + bottom) / (top - bottom);
projMatrix.m[2][2] = -2.f / (far - near);
projMatrix.m[2][3] = -(far + near) / (far - near);
projMatrix.m[3][3] = 1.f;
}
void camera::set_perspective_projection(float field_of_view, float near, float far)
{
projMatrix = {{0}};
float half_fov = field_of_view / 2 * M_PI / 180;
projMatrix.m[0][0] = 1.f / (tan(half_fov));
projMatrix.m[1][1] = 1.f / (tan(half_fov));
projMatrix.m[2][2] = far / (far - near);
projMatrix.m[2][3] = -near * far / (far - near);
projMatrix.m[2][3] = 1.f;
}
vec3 camera::position() {
return pos;
}
vec3 camera::direction() {
return dir;
}
mat4 camera::projection() {
return projMatrix;
}
mat4 camera::view() {
return viewMatrix;
}
} // namespace trz