gpt4 book ai didi

opengl - 在 GLUT 中使用鼠标滚轮

转载 作者:行者123 更新时间:2023-12-01 19:16:00 29 4
gpt4 key购买 nike

我想在 OpenGL GLUT 程序中使用鼠标滚轮来放大和缩小场景?我该怎么做?

最佳答案

Freeglut 的 glutMouseWheelFunc 回调与版本相关,并且在 X 中不可靠。使用标准鼠标功能并测试按钮 3 和 4。

OpenGlut 关于 glutMouseWheelFunc 状态的注释:

Due to lack of information about the mouse, it is impossible to implement this correctly on X at this time. Use of this function limits the portability of your application. (This feature does work on X, just not reliably.) You are encouraged to use the standard, reliable mouse-button reporting, rather than wheel events.

使用标准的 GLUT 鼠标报告:

#include <GL/glut.h>

<snip...>

void mouse(int button, int state, int x, int y)
{
// Wheel reports as button 3(scroll up) and button 4(scroll down)
if ((button == 3) || (button == 4)) // It's a wheel event
{
// Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
printf("Scroll %s At %d %d\n", (button == 3) ? "Up" : "Down", x, y);
}else{ // normal button event
printf("Button %s At %d %d\n", (state == GLUT_DOWN) ? "Down" : "Up", x, y);
}
}

<snip...>

glutMouseFunc(mouse);

正如OP所说,它“非常简单”。他只是错了。

关于opengl - 在 GLUT 中使用鼠标滚轮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14378/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com