-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.cpp
More file actions
59 lines (46 loc) · 1.46 KB
/
camera.cpp
File metadata and controls
59 lines (46 loc) · 1.46 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
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <vector>
#include <GLFW/glfw3.h>
#include "camera.h"
void Camera::changefov(double y) {
fov -= y;
if (fov < 1) fov = 1;
else if (fov > 120) fov = 120;
}
void Camera::rotateCamera(float xoffset, float yoffset) {
yaw += xoffset;
pitch += yoffset;
// So that you dont do a backflip
if (pitch > 89.0f) pitch = 89.0f;
else if (pitch < -89.0f) pitch = -89.0f;
updateCameraVectors();
}
void Camera::updateCameraVectors() {
// calculate the new front
glm::vec3 newFront;
newFront.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
newFront.y = sin(glm::radians(pitch));
newFront.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
front = glm::normalize(newFront);
right = glm::normalize(glm::cross(front, worldup));
up = glm::normalize(glm::cross(right, front));
}
void Camera::moveForward(float deltaTime) {
position += deltaTime * speed * front;
}
void Camera::moveBackward(float deltaTime) {
position -= deltaTime * speed * front;
}
void Camera::moveLeft(float deltaTime) {
position -= glm::normalize(glm::cross(front, up)) * speed * deltaTime;
}
void Camera::moveRight(float deltaTime) {
position += glm::normalize(glm::cross(front, up)) * speed * deltaTime;
}
void Camera::moveUp(float deltaTime) {
position.y += deltaTime * speed;
}
void Camera::moveDown(float deltaTime) {
position.y -= deltaTime * speed;
}