-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.h
More file actions
64 lines (55 loc) · 1.29 KB
/
camera.h
File metadata and controls
64 lines (55 loc) · 1.29 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
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <iostream>
struct PerspectiveCamera {
PerspectiveCamera() {};
PerspectiveCamera(
glm::vec3 eye,
glm::vec3 center,
glm::vec3 up,
float near,
float far,
float fov,
float aspect) {
this->eye = eye;
this->center = center;
glm::vec3 front = center - eye;
glm::vec3 right = glm::cross(front, up);
this->up = glm::normalize(glm::cross(right, front));
this->near = near;
this->far = far;
this->fov = fov;
this->aspect = aspect;
this->view = update_view();
this->proj = update_proj();
}
glm::mat4 update_view() {
view = glm::lookAtRH(eye, center, up);
return view;
}
glm::mat4 update_proj() {
proj = glm::perspectiveRH_ZO(fov, aspect, near, far);
proj[1][1] *= -1.0f;
return proj;
}
glm::vec3 eye;
glm::vec3 center;
glm::vec3 up;
float near;
float far;
float fov;
float aspect;
glm::mat4 view;
glm::mat4 proj;
//friend std::ostream & operator<<(std::ostream & os, const glm::vec3 & v) {
// os << v.x << ", " << v.y << ", " << v.z;
// return os;
//}
//friend std::ostream& operator<<(std::ostream& os, const PerspectiveCamera& cam) {
// os << "eye = " << cam.eye << ", center = " << cam.center << ", up = " << cam.up;
// return os;
//}
};
struct OrthoCamera {
};