Skip to content

Commit f5875f3

Browse files
committed
Agregado mouse callback
Se agrego el método onmouse para manejar la posición del ratón
1 parent 4eefd47 commit f5875f3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Common/OpenGLWindow.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class OpenGLWindow {
3838
glfwSetKeyCallback(window, key_callback);
3939
glfwSetWindowCloseCallback(window, close_callback);
4040
glfwSetFramebufferSizeCallback(window, resize_callback);
41+
glfwSetCursorPosCallback(window, mouse_callback);
4142

4243
if (glewInit() != GLEW_OK) {
4344
glfwTerminate();
@@ -74,6 +75,10 @@ class OpenGLWindow {
7475
cout << endl;
7576
}
7677

78+
GLFWwindow* getGLFWwindow() {
79+
return window;
80+
}
81+
7782
private:
7883

7984
static void error_callback(int error, const char* description)
@@ -99,6 +104,12 @@ class OpenGLWindow {
99104
win_app->onresize(width, height);
100105
}
101106

107+
static void mouse_callback(GLFWwindow* window, double xpos, double ypos)
108+
{
109+
OpenGLWindow* win_app = getOpenGLWinApp(window);
110+
win_app->onmouse(xpos, ypos);
111+
}
112+
102113
inline static OpenGLWindow* getOpenGLWinApp(GLFWwindow* window) {
103114
return static_cast<OpenGLWindow*>(glfwGetWindowUserPointer(window));
104115
}
@@ -111,6 +122,8 @@ class OpenGLWindow {
111122
virtual void onkey(int key, int scancode, int action, int mods) { };
112123

113124
virtual void onrender(double time) = 0;
125+
126+
virtual void onmouse(double xpos, double ypos) { };
114127

115128
virtual void onresize(int width, int height) {
116129
aspect_ratio = max(0.0f, width / (float)height);

0 commit comments

Comments
 (0)