在 GLUT 中使用鼠标滚轮 [英] Using the mouse scrollwheel in GLUT
问题描述
我想在我的 OpenGL GLUT 程序中使用鼠标滚轮来放大和缩小场景?我该怎么做?
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?
推荐答案
请注意可敬的 Nate Robin 的GLUT 库不支持滚轮.但是,像 FreeGLUT 这样的 GLUT 的后续实现会这样做.
Note that venerable Nate Robin's GLUT library doesn't support the scrollwheel. But, later implementations of GLUT like FreeGLUT do.
在 FreeGLUT 中使用滚轮非常简单.方法如下:
Using the scroll wheel in FreeGLUT is dead simple. Here is how:
声明一个回调函数,只要滚动滚轮就会调用该回调函数.这是原型:
Declare a callback function that shall be called whenever the scroll wheel is scrolled. This is the prototype:
void mouseWheel(int, int, int, int);
使用(免费)GLUT 函数glutMouseWheelFunc()注册回调.
Register the callback with the (Free)GLUT function glutMouseWheelFunc().
glutMouseWheelFunc(mouseWheel);
定义回调函数.第二个参数给出了滚动的方向.+1 的值是向前的,-1 是向后的.
Define the callback function. The second parameter gives the direction of the scroll. Values of +1 is forward, -1 is backward.
void mouseWheel(int button, int dir, int x, int y)
{
if (dir > 0)
{
// Zoom in
}
else
{
// Zoom out
}
return;
}
就是这样!
这篇关于在 GLUT 中使用鼠标滚轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!