-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
74 lines (59 loc) · 1.74 KB
/
Camera.cpp
File metadata and controls
74 lines (59 loc) · 1.74 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
#include "Camera.h"
#include <glm/glm.hpp>
Camera::Camera(float3 a_pos, float3 a_up, float3 a_front, GLfloat a_yaw, GLfloat a_pitch,
GLfloat a_moveSpeed, GLfloat a_mouseSensitivity, GLfloat a_zoom) : pos(a_pos), front(a_front), up(a_up),
yaw(a_yaw), pitch(a_pitch), moveSpeed(a_moveSpeed), mouseSensitivity(a_mouseSensitivity), zoom(a_zoom)
{
right = normalize(cross(a_up, a_front));
worldUp = up;
}
float4x4 Camera::GetViewMatrix() const
{
return lookAtTransposed(pos, pos + front, up);
}
void Camera::ProcessKeyboard(Movement_Direction dir, GLfloat deltaTime)
{
GLfloat velocity = moveSpeed * deltaTime;
if (dir == FORWARD)
pos += front * velocity;
if (dir == BACKWARD)
pos -= front * velocity;
if (dir == LEFT)
pos -= right * velocity;
if (dir == RIGHT)
pos += right * velocity;
}
void Camera::ProcessMouseMove(GLfloat deltaX, GLfloat deltaY, GLboolean limitPitch)
{
deltaX *= mouseSensitivity;
deltaY *= mouseSensitivity;
yaw += deltaX;
pitch += deltaY;
if (limitPitch)
{
if (pitch > 89.0f)
pitch = 89.0f;
if (pitch < -89.0f)
pitch = -89.0f;
}
updateCameraVectors();
}
void Camera::ProcessMouseScroll(GLfloat deltaY)
{
if (zoom >= 1.0f && zoom <= 45.0f)
zoom -= deltaY;
if (zoom <= 1.0f)
zoom = 1.0f;
if (zoom >= 45.0f)
zoom = 45.0f;
}
void Camera::updateCameraVectors()
{
float3 tmpFront;
tmpFront.x = cos(DEG_TO_RAD*yaw) * cos(DEG_TO_RAD*pitch);
tmpFront.y = sin(DEG_TO_RAD*pitch);
tmpFront.z = sin(DEG_TO_RAD*yaw) * cos(DEG_TO_RAD*pitch);
front = normalize(tmpFront);
right = normalize(cross(front, worldUp));
up = normalize(cross(right, front));
}