-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.cpp
106 lines (77 loc) · 1.99 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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "m_camera.h"
void Camera::setScreenRatio(float _screenRatio){
ratio = _screenRatio;
}
void Camera::setPosition(Vector3f _position){
position = _position;
}
void Camera::setTarget(Vector3f _target){
}
void Camera::setFOV(Vector2f _fov){
fov = _fov;
}
void Camera::setNear(float _near){
nearFar = Vector2f(_near, nearFar.y);
}
void Camera::setFar(float _far){
nearFar = Vector2f(nearFar.x, _far);
}
void Camera::setSpeed(float _speed){
speed = _speed;
}
void Camera::lookAt(Vector3f, Vector3f){
}
void Camera::onRender(){
}
void Camera::onKeyboard(int _key){
switch(_key){
case GLFW_KEY_PAGE_UP:
{
position += (front * speed);
}
break;
case GLFW_KEY_PAGE_DOWN:
{
position -= (front * speed);
}
break;
case GLFW_KEY_LEFT:
{
Vector3f left = front.cross(up);
left.normalize();
position += (left * speed);
}
break;
case GLFW_KEY_RIGHT:
{
Vector3f right = up.cross(front);
right.normalize();
position += (right * speed);
}
break;
case GLFW_KEY_UP:
{
position.y += speed;
}
break;
case GLFW_KEY_DOWN:
{
position.y -= speed;
}
break;
}
}
void Camera::onMouse(int x, int y){
}
void Camera::getMatrix(Matrix4f* ret){
PerspectiveProjectionMatrix projection(fov, ratio, nearFar);
front.normalize();
Vector3f u = up.cross(front);
u.normalize();
//UP could be V, but it is probably not perpendicular to Front/Target, so we cross Front/Target with U to get V
Vector3f v = front.cross(u);
v.normalize();
TranslationMatrix cameraTranslation(position * -1);
ViewMatrix view(u, v, front);
*ret = projection * (view * cameraTranslation);
}