-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcamera.cpp
81 lines (62 loc) · 2.2 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
#include "camera.h"
#include "math.h"
#define degreesToRadians(angleDegrees) ((angleDegrees) * M_PI / 180.0)
#define radiansToDegrees(angleRadians) ((angleRadians) * 180.0 / M_PI)
QMatrix4x4 Camera::getCameraViewMatrix(){
QMatrix4x4 viewMatrix;
//viewMatrix.lookAt(cameraPos, QVector3D(0.0f, 0.0f, 0.0f), cameraUp);
viewMatrix.lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
return viewMatrix;
}
void Camera::updateCameraVectors(){
QVector3D frontDirection = QVector3D(0.0f, 0.0f, -1.0f);
double radians = 90 * M_PI / 180;
frontDirection.setX(qCos(qDegreesToRadians((float)yaw)));
frontDirection.setZ(qSin(qDegreesToRadians((float)yaw)));
frontDirection.setY(qSin(qDegreesToRadians((float)pitch)));
cameraFront = frontDirection.normalized();
cameraRight = QVector3D::crossProduct(cameraFront, worldUp).normalized();
cameraUp = QVector3D::crossProduct(cameraRight, cameraFront).normalized();
}
void Camera::processKeyboard(cameraMovement direction, float deltaTime){
float velocity = movementSpeed * deltaTime;
if (direction == FORWARD)
cameraPos += velocity * cameraFront;
if (direction == BACKWARD)
cameraPos -= velocity * cameraFront;
if (direction == LEFT)
cameraPos -= velocity * cameraRight;
if (direction == RIGHT)
cameraPos += velocity * cameraRight;
}
void Camera::processMouseMovement(float xoffset, float yoffset, bool constrainPitch) {
xoffset *= mouseSensitivity;
yoffset *= mouseSensitivity;
yaw += xoffset;
pitch -= yoffset;
if (constrainPitch) {
if (pitch > 89.0f)
pitch = 89.0f;
if (pitch < -89.0f)
pitch = -89.0f;
}
updateCameraVectors();
}
void Camera::processMouseScroll(float yoffset) {
cameraPos += ((float)yoffset * fov_speed) * cameraFront;
}
void Camera::setMovementSpeed(float movSpeed){
movementSpeed = movSpeed;
}
void Camera::setRotationSpeed(float rotSpeed){
mouseSensitivity = rotSpeed;
}
void Camera::setFov(float fov){
this->fov = fov;
}
void Camera::setNearDistance(float nearDistance){
this->nearDistance = nearDistance;
}
void Camera::setFarDistance(float farDistance){
this->farDistance = farDistance;
}