opengl 当应用程序处于活动状态时,glutWarpPointer()不工作

nzrxty8p  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(149)

我的问题是屏幕将不再旋转,而我的鼠标在屏幕上。只有当应用程序不再活动。
如果我把这些曲速指针取出来,它就会重新开始工作。
下面是我的鼠标更新:

mouse.x = x;
mouse.y = y;

if (x > screen.x/2)
{
    player.angle -= 0.05f;
    player.lx = sin(player.angle);
    player.lz = -cos(player.angle);
    glutWarpPointer(screen.x/2,screen.y/2);
}
else if (x < screen.x/2)
{
    player.angle += 0.05f;
    //if (player.vertAngle < 0)
        //player.vertAngle = 0;
    player.lx = sin(player.angle);
    player.lz = -cos(player.angle);
    glutWarpPointer(screen.x/2,screen.y/2);
}
if (y < screen.y/2)
{
    player.vertAngle += 0.05f;
    player.ly = sin(player.vertAngle);
    glutWarpPointer(screen.x/2,screen.y/2);
}
else if (y > screen.y/2)
{
    player.vertAngle -= 0.05f;
    //if (player.vertAngle > 360)
        //player.vertAngle = 360;
    player.ly = sin(player.vertAngle);
    glutWarpPointer(screen.x/2,screen.y/2);
}
n3schb8v

n3schb8v1#

使用标志忽略glutWarpPointer()生成的额外运动事件:

#include <GL/glut.h>

#include <iostream>
using namespace std;

bool capture = false;
void keyboard( unsigned char key, int x, int y )
{
    if( key == 'z' )
    {
        capture = !capture;
    }
}

void passiveMotion( int x, int y )
{
    static bool warped = false;
    if( warped )
    {
        warped = false;
        return;
    }

    if( capture )
    {
        warped = true;
        int w = glutGet( GLUT_WINDOW_WIDTH );
        int h = glutGet( GLUT_WINDOW_HEIGHT );
        glutWarpPointer( w / 2, h / 2 );

        int dx = ( w / 2 ) - x;
        int dy = ( h / 2 ) - y;
        cout << dx << " " << dy << endl;
    }
    else
    {
        cout << x << " " << y << endl;
    }
}

void display()
{
    glClear( GL_COLOR_BUFFER_BIT );
    glutSwapBuffers();
}

int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
    glutInitWindowSize( 640, 480 );
    glutCreateWindow( "GLUT" );
    glutKeyboardFunc( keyboard );
    glutPassiveMotionFunc( passiveMotion );
    glutDisplayFunc( display );
    glutMainLoop();
    return 0;
}

相关问题