被动运动检测

时间:2012-11-24 09:03:51

标签: c glut

如何使用opengl检测鼠标被动运动?换句话说,我怎么能理解它是向前,向后,向左,向右?

我已经完成了

glutPassiveMotionFunc ( func ) 

void func ( int x, int y ) {

   // x and y always positive, I wait it should be negative if it goes left 
   //   acc. to  my coordinate system determined in glLookAt.
}

2 个答案:

答案 0 :(得分:1)

来自docs

  

x和y回调参数指示窗口相对坐标中的鼠标位置。

如果您对光标在两个帧(三角形)之间移动感兴趣,请每帧存储光标位置并计算“当前”位置和“上次看到”位置之间的差异。

答案 1 :(得分:0)

你不是用OpenGL做的,而是用GLUT做的。

存储先前录制的鼠标位置。将新位置与先前位置进行比较,以了解它是向上,向下,向左还是向右。

这样的事情:

int x=0, y=0;
enum { LEFT, RIGHT, UP, DOWN };
int direction;

void func(int mx, int my)
{
     if(mx < x) direction = LEFT;
     else if(mx > x) direction = RIGHT;
     else if(my > y) direction = DOWN;
     else if(my < y) direction = UP;

     x = mx;
     y = my;
}

原点位于左上角。

相关问题