73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
#include "funcs.h"
|
|
|
|
extern float deltaTime;
|
|
extern float lastX, lastY;
|
|
extern const float mouseSensitivity = 0.08f;
|
|
extern float zoom;
|
|
|
|
glm::vec3 camPos = glm::vec3(0.0f, 0.0f, 3.0f);
|
|
glm::vec3 camDir = glm::vec3(0.0f, 0.0f, -1.0f);
|
|
glm::vec3 camUp = glm::vec3(0.0f, 1.0f, 0.0f);
|
|
float yaw=-90.0f, pitch=0.0f, roll=0.0f;
|
|
bool firstMouse = true;
|
|
|
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
|
glViewport(0, 0, width, height);
|
|
}
|
|
|
|
void mouse_callback(GLFWwindow*, double xpos, double ypos) {
|
|
if (firstMouse) {
|
|
lastX = xpos;
|
|
lastY = ypos;
|
|
firstMouse = false;
|
|
}
|
|
|
|
float xOffset = xpos - lastX;
|
|
float yOffset = lastY - ypos;
|
|
lastX = xpos;
|
|
lastY = ypos;
|
|
xOffset *= mouseSensitivity;
|
|
yOffset *= mouseSensitivity;
|
|
|
|
yaw += xOffset;
|
|
pitch += yOffset;
|
|
pitch = (pitch > 89.0f)?89.0f: ((pitch < -89.0f)?-89.0f:pitch );
|
|
camDir.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
|
camDir.y = sin(glm::radians(pitch));
|
|
camDir.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
|
|
camDir = glm::normalize(camDir);
|
|
}
|
|
|
|
void scroll_callback(GLFWwindow*, double xOffset, double yOffset) {
|
|
zoom -= (float)yOffset;
|
|
if (zoom < 1.0f) {
|
|
zoom = 1.0f;
|
|
} else if ( zoom > 45.0f) {
|
|
zoom = 45.0f;
|
|
}
|
|
}
|
|
|
|
void processInput(GLFWwindow* window) {
|
|
float camSpeed = 3.5f * deltaTime;
|
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
|
glfwSetWindowShouldClose(window, true);
|
|
}
|
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
|
|
camPos += camSpeed * camDir;
|
|
}
|
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
|
camPos -= camSpeed * camDir;
|
|
}
|
|
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
|
camPos -= camSpeed * glm::cross(camDir, camUp);
|
|
}
|
|
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
|
camPos += camSpeed * glm::cross(camDir, camUp);
|
|
}
|
|
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
|
camPos += camSpeed * camUp;
|
|
}
|
|
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
|
|
camPos -= camSpeed * camUp;
|
|
}
|
|
} |