Repository navigation
Expand file tree
/
Copy pathcamera.cpp
More file actions
98 lines (82 loc) · 2.27 KB
/
Copy pathcamera.cpp
File metadata and controls
98 lines (82 loc) · 2.27 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "camera.h"
CameraMovementDirection direction = { false, false, false, false, false, false, };
Camera::Camera(bool mov, bool mos_mov, bool zoom)
{
Position = glm::vec3(0.0f, 0.0f, -3.0f);
WorldUp = glm::vec3(0.0f, 1.0f, 0.0f);
Yaw = -90.0f;
Pitch = 0.0f;
MovmentSpeed = 5.0f;
MouseSensitivity = 0.1f;
Zoom = 45.0f;
movement = mov;
mouse_movement = mos_mov;
zooming = zoom;
updateCamera();
}
Camera::Camera()
{
Position = glm::vec3(0.0f, 3.0f, 3.0f);
WorldUp = glm::vec3(0.0f, 1.0f, 0.0f);
Yaw = -90.0f;
Pitch = 0.0f;
MovmentSpeed = 5.0f;
MouseSensitivity = 0.1f;
Zoom = 45.0f;
movement = true;
mouse_movement = true;
zooming = true;
updateCamera();
}
glm::mat4 Camera::GetViewMatrix()
{
return glm::lookAt(Position, Position + Front, Up);
}
glm::mat4 Camera::GetPerspectiveMatrix(float aspect, float near_plane, float far_plane)
{
return glm::perspective(glm::radians(Zoom), aspect, near_plane, far_plane);
}
void Camera::ProcessMouseScroll(float yoffset)
{
if (zooming)
{
Zoom -= (float)yoffset;
if (Zoom < 1.0f)
Zoom = 1.0f;
if (Zoom > 45.0f)
Zoom = 45.0f;
}
}
void Camera::ProcessMouseMovement(float xoffset, float yoffset)
{
xoffset *= MouseSensitivity;
yoffset *= MouseSensitivity;
Yaw = glm::mod(Yaw + xoffset, 360.0f);
Pitch += yoffset;
if (Pitch > 89.0f)
Pitch = 89.0f;
if (Pitch < -89.0f)
Pitch = -89.0f;
updateCamera();
}
void Camera::ProcessKeyboard(float deltaTime)
{
float velocity = MovmentSpeed * deltaTime;
if (direction.Forward) Position += velocity * Front;
if (direction.Backward) Position -= velocity * Front;
if (direction.Left) Position -= velocity * Right;
if (direction.Right) Position += velocity * Right;
if (direction.Up) Position += velocity * glm::vec3(0.0f, 1.0f, 0.0f);
if (direction.Down) Position -= velocity * glm::vec3(0.0f, 1.0f, 0.0f);
}
void Camera::updateCamera()
{
glm::vec3 currentFront;
currentFront.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
currentFront.y = sin(glm::radians(Pitch));
currentFront.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
Front = glm::normalize(currentFront);
//printf("Camera Pos: %f %f %f\n", this->Position[0], this->Position[1], this->Position[2]);
Right = glm::normalize(glm::cross(Front, WorldUp));
Up = glm::normalize(glm::cross(Right, Front));
}