-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
59 lines (47 loc) · 1.41 KB
/
Camera.cpp
File metadata and controls
59 lines (47 loc) · 1.41 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 "Camera.h"
float lastX = 400;
float lastY = 300;
bool firstMouse = true;
void Camera::mouseInput(double xpos, double ypos) {
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = (xpos - lastX) * sensitivity;
float yoffset = (lastY - ypos) * sensitivity;
lastX = xpos;
lastY = ypos;
yaw += xoffset;
pitch += yoffset;
if (pitch > 89.0f)
pitch = 89.0f;
if (pitch < -89.0f)
pitch = -89.0f;
glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
Front = glm::normalize(direction);
}
void Camera::scrollInput(double xoffset, double yoffset) {
fov -= (float)yoffset;
if (fov < 1.0f)
fov = 1.0f;
if (fov > 45.0f)
fov = 45.0f;
}
void Camera::keyboardInput(GLFWwindow* window, float deltaTime) {
const float cameraSpeed = speedCoeff * deltaTime;
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
Pos += cameraSpeed * Front;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
Pos -= cameraSpeed * Front;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
Pos -= glm::normalize(glm::cross(Front, Up)) * cameraSpeed;
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
Pos += glm::normalize(glm::cross(Front, Up)) * cameraSpeed;
}