【问题标题】:Rotating the angle of my shape, depdning on the mouses position.根据鼠标的位置旋转我的形状的角度。
【发布时间】:2015-03-22 18:49:41
【问题描述】:

我正在尝试将rotate 我的形状更改为mouses X and Y position。就像在 2D 自上而下的游戏中一样,tank's turret 将旋转到mouses XY position

使用

glutPassiveMotionFunc(MousePassiveMotion);

我可以记录 X 和 Y 位置;

void MousePassiveMotion(int x, int y){
    //do something here
    myAtan2 = atan2(y - Pentagon.y, x - Pentagon.x)* 180 / PI;
    Pentagon.angle = myAtan2;
    cout << Pentagon.angle << endl;
}

调试给了我一个介于090 之间的值,我相信最大值。

但是,我的五角大楼没有旋转。

void DrawShape(){

    glTranslatef(x, y, z);//the x and y position of the shape 

    glRotatef(angle, 0, 0, 1.0f);
    glBegin(GL_TRIANGLE_FAN);
    glVertex3f(v[9].x, v[9].y, v[9].z);

上面的代码是struct,称为Shape{};,五角大楼是其中的类型。 DrawShape() 方法在 display function 中被调用,所以它应该是旋转的。但不是。

有人知道为什么吗?

【问题讨论】:

    标签: c++ opengl rotation glut


    【解决方案1】:

    确保您在鼠标回调或空闲/计时器回调中调用 glutPostRedisplay()。否则,您的显示回调只会在操作系统喜欢它时被调用(并且您的五边形会用新角度重新绘制)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-04
      • 1970-01-01
      • 2012-03-01
      相关资源
      最近更新 更多