i'm trying to make a fps camera while using QOpenGLWidget, gamer will have a CrossCursor in the center of the screen like most games do.
But when i use
QCursor::setPos(geometry().center());
the cursor is jumpy, and bounces all over; it really annoys me. Here is my code:
void Widget::mouseMoveEvent(QMouseEvent *event)
{
float xoffset = event->position().x() - rect().center().x();
float yoffset = rect().center().y() - event->position().y();
if(firstMouse){
xoffset = event->position().x();
yoffset = event->position().y();
firstMouse = false;
}
camera->processMouseMovement(xoffset,yoffset);//camera process
QCursor::setPos(geometry().center());// keep cenetered
QOpenGLWidget::mouseMoveEvent(event);
}
I don't really know if this mouseMoveEvent
in QOpenGLWidget
is same as in the QWidget
, or maybe there is a better way to implement this function.