Using the mouse scrollwheel in GLUT

后端 未结 3 437
孤独总比滥情好
孤独总比滥情好 2020-12-01 07:39

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?

3条回答
  •  忘掉有多难
    2020-12-01 08:05

    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();
    }
    

提交回复
热议问题