-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks.cpp
More file actions
54 lines (41 loc) · 1.52 KB
/
callbacks.cpp
File metadata and controls
54 lines (41 loc) · 1.52 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
#include <GL/glew.h>
#define GLFW_DLL
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <iostream>
#include "callbacks.hpp"
auto error_callback(int error, const char* description) -> void {
std::cerr << "OpenGL Error: " << description << std::endl;
}
auto framebufferSizeCallback(GLFWwindow *window, int w, int h) -> void {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;
float ratio = 1.0f * w / h;
glfwMakeContextCurrent(window);
glViewport(0, 0, w, h);
projection = glm::perspective(0.7f, ratio, 1.0f, 800.0f);
// glm::lookAt()
}
auto key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) -> void {
constexpr float ZOOM_STEP = 0.5;
constexpr float ROT_STEP = 0.2;
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
if (key == GLFW_KEY_E && (action == GLFW_PRESS || action == GLFW_REPEAT))
zoom -= ZOOM_STEP;
if (key == GLFW_KEY_Q && (action == GLFW_PRESS || action == GLFW_REPEAT))
zoom += ZOOM_STEP;
if (key == GLFW_KEY_A && (action == GLFW_PRESS || action == GLFW_REPEAT))
rotZ -= ROT_STEP;
if (key == GLFW_KEY_D && (action == GLFW_PRESS || action == GLFW_REPEAT))
rotZ += ROT_STEP;
if (key == GLFW_KEY_W && (action == GLFW_PRESS || action == GLFW_REPEAT))
rotX += ROT_STEP;
if (key == GLFW_KEY_S && (action == GLFW_PRESS || action == GLFW_REPEAT))
rotX -= ROT_STEP;
}