-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCamera.cpp
More file actions
59 lines (42 loc) · 1.5 KB
/
Camera.cpp
File metadata and controls
59 lines (42 loc) · 1.5 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
////////////////////////////////////////
// Camera.cpp
////////////////////////////////////////
#include "Camera.h"
#include <glm/gtx/euler_angles.hpp>
////////////////////////////////////////////////////////////////////////////////
Camera::Camera() {
Reset();
}
////////////////////////////////////////////////////////////////////////////////
void Camera::Update() {
// Compute camera world matrix
glm::mat4 world(1);
world[3][2] = _distance;
world = glm::eulerAngleY(glm::radians(-_azimuth)) * glm::eulerAngleX(glm::radians(-_incline)) * world;
// Compute the Camera position
_cameraPosition = world * glm::vec4(0, 0, 0, 1);
// Compute view matrix (inverse of world matrix)
glm::mat4 view = glm::inverse(world);
// Compute perspective projection matrix
glm::mat4 project = glm::perspective(glm::radians(_FOV), _aspect, _nearPlane, _farPlane);
// Compute final view-projection matrix
_viewProjectMtx = project * view;
}
void Camera::UpdateAngles(int a, int i) {
_azimuth = _azimuth + a * _angleRate;
_incline = glm::clamp(_incline - i * _angleRate, -90.0f, 90.0f);
}
void Camera::UpdateDistance(int d) {
_distance = glm::clamp(_distance * (1.0f - d * _distanceRate), 0.01f, 1000.0f);
}
////////////////////////////////////////////////////////////////////////////////
void Camera::Reset() {
_FOV = 45.0f;
_aspect = 1.33f;
_nearPlane = 0.1f;
_farPlane = 100.0f;
_distance = 2.5f;
_azimuth = 0.0f;
_incline = 20.0f;
}
////////////////////////////////////////////////////////////////////////////////