-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcamera3d.cpp
More file actions
executable file
·84 lines (71 loc) · 1.77 KB
/
Copy pathcamera3d.cpp
File metadata and controls
executable file
·84 lines (71 loc) · 1.77 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "camera3d.h"
Camera3D::Camera3D(QVector3D pos_, QVector3D up_, float pitch_,
float roll_, float fov_, float aspectRatio_,
float nearPlane_, float farPlane_, float sensitivity_) :
pos(pos_),
up(up_),
front(QVector3D(0, 0.0174524, -0.999848)),
pitch(pitch_),
roll(roll_),
fov(fov_),
aspectRatio(aspectRatio_),
nearPlane(nearPlane_),
farPlane(farPlane_),
sensitivity(sensitivity_)
{
updateViewMatrix();
updateProjectionMatrix();
}
void Camera3D::viewRotate(QVector2D degrees)
{
degrees *= sensitivity;
roll -= degrees.x();
pitch += degrees.y();
if(pitch > 89.0)
pitch = 89.0;
else if(pitch < -89.0)
pitch = -89.0;
float rpitch = qDegreesToRadians(pitch);
float rroll = qDegreesToRadians(roll);
QVector3D front(qCos(rpitch)*qSin(rroll), qCos(rpitch)*qCos(rroll), qSin(rpitch));
this->front = front.normalized();
updateViewMatrix();
}
void Camera3D::setFov(float fov)
{
this->fov = fov;
updateProjectionMatrix();
}
void Camera3D::setFovBias(float bias)
{
float fov = this->fov + bias * sensitivity;
if(fov < 45.0)
fov = 45.0;
else if(fov > 150.0)
fov = 150.0;
this->fov = fov;
updateProjectionMatrix();
}
void Camera3D::setAspectRatio(float aspectRatio)
{
this->aspectRatio = aspectRatio;
updateProjectionMatrix();
}
const QMatrix4x4 &Camera3D::viewMatrix()
{
return view;
}
const QMatrix4x4 &Camera3D::perspectMatrix()
{
return projection;
}
void Camera3D::updateViewMatrix()
{
view.setToIdentity();
view.lookAt(pos, pos + front, up);
}
void Camera3D::updateProjectionMatrix()
{
projection.setToIdentity();
projection.perspective(fov, aspectRatio, nearPlane, farPlane);
}