I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom in and out of a scene? How do I do that?
observe case 3 and 4 in the switch statement below in the mouseClick callback
glutMouseFunc(mouseClick);
...
void mouseClick(int btn, int state, int x, int y) {
if (state == GLUT_DOWN) {
switch(btn) {
case GLUT_LEFT_BUTTON:
std::cout << "left click at: (" << x << ", " << y << ")\n";
break;
case GLUT_RIGHT_BUTTON:
std::cout << "right click at: (" << x << ", " << y << ")\n";
break;
case GLUT_MIDDLE_BUTTON:
std::cout << "middle click at: (" << x << ", " << y << ")\n";
break;
case 3: //mouse wheel scrolls
std::cout << "mouse wheel scroll up\n";
break;
case 4:
std::cout << "mouse wheel scroll down\n";
break;
default:
break;
}
}
glutPostRedisplay();
}