我的程序中有鼠标跟踪问题,在屏幕的第一个垂直半部分它正常工作,但是当我越过屏幕的垂直中间时,它无法正常工作。
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(
0.0f, 0.0f, 3.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
glRotatef(xrot, 0.0, 0.0f, 1.0f);
drawBox();
glFlush();
glutSwapBuffers();
}
void idle()
{
if (!mouseDown)
{
xrot += 0.0f;
yrot += 0.0f;
}
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseDown = true;
xdiff = x - yrot;
ydiff = -y + xrot;
}
else
mouseDown = false;
}
void mouseMotion(int x, int y)
{
if (mouseDown)
{
yrot = x - xdiff;
xrot = y + ydiff;
glutPostRedisplay();
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(50, 50);
glutInitWindowSize(800, 600);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Still not working");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(specialKeyboard);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
glutReshapeFunc(resize);
//glutIdleFunc(idle);
if (!init())
return 1;
glutMainLoop();
return 0;
}
我编写了上面的程序,但仍在学习这整个openGL语言,所以如果您有任何想法,谢谢!