Qt鼠标事件左键没有翻译qt对象

时间:2014-05-16 23:27:41

标签: c++ qt

我在QGLWidget类上有以下鼠标事件...

void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    QPointF mousePosition = event->pos(); 
     float dx = event->x() - lastPos.x();
     float dy = event->y() - lastPos.y();

     if (event->buttons() & Qt::LeftButton) {
         setXRotation(xRot + 8.0 * dy);
         setYRotation(yRot + 8.0 * dx);
     } else if (event->buttons() & Qt::RightButton) {
         xTrans += dx;
         yTrans -= dy;  
     }    
     lastPos = event->pos();
}

油漆GL中的旋转正在起作用但不能翻译。我做错了什么......?

void GLWidget::paintGL()
    {

     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glMatrixMode(GL_MODELVIEW);
     glPushMatrix();
     glLoadIdentity();
     glTranslatef(0.0, 0.0, -5.0);
     glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
     glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
     glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);


glTranslatef(xTrans, yTrans, 0.0f);
             glScalef(scale, scale, scale);
    //draw function here
glPopMatrix();

            }

1 个答案:

答案 0 :(得分:-1)

您必须弹出矩阵才能将其应用

http://www.swiftless.com/tutorials/opengl/pop_and_push_matrices.html

允许推送矩阵实际完成计算并使用。

glPopMatrix(); //end the current object transformations

希望有所帮助。

相关问题