在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屋!