-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppCallback.cpp
More file actions
93 lines (86 loc) · 3.37 KB
/
AppCallback.cpp
File metadata and controls
93 lines (86 loc) · 3.37 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include "App.h"
void App::error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
void App::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if ((action == GLFW_PRESS) || (action == GLFW_REPEAT)) {
switch (key) {
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, GLFW_TRUE);
break;
case GLFW_KEY_F:
std::cout << "F clicked!\n";
is_fullscreen_on = !is_fullscreen_on;
if (is_fullscreen_on) {
glfwGetWindowPos(window, &window_xcor, &window_ycor);
glfwGetWindowSize(window, &window_width_return_from_fullscreen, &window_height_return_from_fullscreen);
if (window_height_return_from_fullscreen == 0) window_height_return_from_fullscreen++;
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
}
else {
glfwSetWindowMonitor(window, nullptr, window_xcor, window_ycor, window_width_return_from_fullscreen, window_height_return_from_fullscreen, 0);
}
break;
case GLFW_KEY_V:
std::cout << "V clicked!\n";
is_vsync_on = !is_vsync_on;
glfwSwapInterval(is_vsync_on);
if (is_vsync_on) {
std::cout << "VSync is ON!" << "\n";
}
else {
std::cout << "VSync is OFF!" << "\n";
}
break;
case GLFW_KEY_E:
std::cout << "E clicked!\n";
//std::cout << "holdItem: " << holdItem << "\n";
// static x no static - dumb ... later repair logic for pick up
holdItem = !holdItem;
break;
case GLFW_KEY_G:
std::cout << "G clicked!\n";
isFlashlightOn = !isFlashlightOn;
break;
case GLFW_KEY_L:
std::cout << "L clicked!\n";
isLampOn = !isLampOn;
break;
}
}
// Sprint
if (action == GLFW_PRESS && key == GLFW_KEY_LEFT_SHIFT) {
std::cout << "LEFT_SHIFT clicked!\n";
camera.toggleSprint();
}
}
void App::scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
// Zoooooom
auto this_inst = static_cast<App*>(glfwGetWindowUserPointer(window));
this_inst->FOV += 10.0f * static_cast<float>(yoffset);
this_inst->FOV = std::clamp(this_inst->FOV, 20.0f, 170.0f); // limit FOV to reasonable values...
this_inst->UpdateProjectionMatrix();
}
void App::framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
auto this_inst = static_cast<App*>(glfwGetWindowUserPointer(window));
this_inst->window_width = width;
this_inst->window_height = height;
// set viewport
glViewport(0, 0, width, height);
//now your canvas has [0,0] in bottom left corner, and its size is [width x height]
this_inst->UpdateProjectionMatrix();
}
void App::mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
std::cout << "Right click!\n";
} else if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
std::cout << "Left click!\n";
projectile.onKeyboardEvent(window, camera.getPosition(), button, action, mods);
}
}