From 065c77190d6e3c93c68f400dc9cf9688f2bcd6eb Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 17 Nov 2010 23:33:46 +0100 Subject: [PATCH] Added scroll navigation. --- examples/wave.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/wave.c b/examples/wave.c index d42897cd..543b5d22 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -285,11 +285,12 @@ void key_callback(GLFWwindow window, int key, int action) beta += 5; break; case GLFW_KEY_PAGEUP: - if (zoom > 1) - zoom -= 1; + zoom -= 0.25f; + if (zoom < 0.f) + zoom = 0.f; break; case GLFW_KEY_PAGEDOWN: - zoom += 1; + zoom += 0.25f; break; default: break; @@ -336,6 +337,18 @@ void mouse_position_callback(GLFWwindow window, int x, int y) } +//======================================================================== +// Callback function for scroll events +//======================================================================== + +void scroll_callback(GLFWwindow window, int x, int y) +{ + zoom += y / 4.f; + if (zoom < 0) + zoom = 0; +} + + //======================================================================== // Callback function for window resize events //======================================================================== @@ -389,6 +402,7 @@ int main(int argc, char* argv[]) glfwSetWindowSizeCallback(window_resize_callback); glfwSetMouseButtonCallback(mouse_button_callback); glfwSetMousePosCallback(mouse_position_callback); + glfwSetScrollCallback(scroll_callback); // Initialize OpenGL init_opengl();