-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
70 lines (53 loc) · 1.69 KB
/
Copy pathCamera.cpp
File metadata and controls
70 lines (53 loc) · 1.69 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
#include "Camera.h"
using namespace _Camera;
Camera::Camera():Camera(vec3(0.0f, 0.0f, 5.0f), vec3(0.0f, 0.0f, 0.0f)) {
}
Camera::Camera(vec3 position, vec3 target) :Entity(position, target) {
front = direction;
cameraUp = normalize(cross(right, front));
update();
std::cout << "Camera Setup Complete" << std::endl;
}
vec3 Camera::getFront() {
return this->front;
}
void Camera::update() {
matrix = lookAt(position, position + front, cameraUp);
}
void Camera::processInput(std::string key) {
float movementSpeed = (cameraSpeed * deltaTime) * speedModifier;
if (key == "space") { position -= movementSpeed * normalize(cross(front, right)); }
if (key == "ctrl") { position += movementSpeed * normalize(cross(front, right)); }
if (key == "w") { position += movementSpeed * front; }
if (key == "s") { position -= movementSpeed * front; }
if (key == "a") { position -= movementSpeed * normalize(cross(front, cameraUp)); }
if (key == "d") { position += movementSpeed * normalize(cross(front, cameraUp)); }
if (key == "shift") {
speedModifier = 2.0f;
} else {
speedModifier = 1.0f;
/* printMsg("position and front");
printVector(position);
printVector(front);*/
}
}
void Camera::processMouse(float x, float y){
Entity::processMouse(x, y);
// Default yaw value as -90.0f
yaw += offsetX;
pitch += offsetY;
if (pitch > 89.0f) { pitch = 89.0f; }
if (pitch < -89.0f) { pitch = -89.0f; }
front.x = cos(radians(yaw)) * cos(radians(pitch));
front.y = sin(radians(pitch));
front.z = sin(radians(yaw)) * cos(radians(pitch));
front = normalize(front);
right = normalize(cross(front, worldUp));
cameraUp = normalize(cross(right, front));
}
/*
Cube:
Top = Green
Right = Red
Face = Blue
*/