ok, I've added an array of flags to record which keys were pressed:
bool keypress[256];
and changed the keyPressEvent and keyReleaseEvent to:
void MainWindowImpl
::keyReleaseEvent( QKeyEvent *e
)
{
switch( e->key() )
{
if (keyboardControl)
{
case Qt::Key_W:
case Qt::Key_S:
case Qt::Key_A:
case Qt::Key_D:
case Qt::Key_Q:
case Qt::Key_E:
keypress[e->key()] = false;
break;
}
}
}
void MainWindowImpl
::keyPressEvent( QKeyEvent *e
)
{
switch( e->key() )
{
if (keyboardControl)
{
case Qt::Key_W:
case Qt::Key_S:
case Qt::Key_A:
case Qt::Key_D:
case Qt::Key_Q:
case Qt::Key_E:
keypress[e->key()] = true;
break;
}
}
}
void MainWindowImpl::keyReleaseEvent( QKeyEvent *e )
{
switch( e->key() )
{
if (keyboardControl)
{
case Qt::Key_W:
case Qt::Key_S:
case Qt::Key_A:
case Qt::Key_D:
case Qt::Key_Q:
case Qt::Key_E:
keypress[e->key()] = false;
break;
}
}
}
void MainWindowImpl::keyPressEvent( QKeyEvent *e )
{
switch( e->key() )
{
if (keyboardControl)
{
case Qt::Key_W:
case Qt::Key_S:
case Qt::Key_A:
case Qt::Key_D:
case Qt::Key_Q:
case Qt::Key_E:
keypress[e->key()] = true;
break;
}
}
}
To copy to clipboard, switch view to plain text mode
and changed the time out routine to:
void OGLWidget::timeOutSlot()
{
if (keypress[Qt::Key_W])
camera[currentCamera].Movement_z -= 0.01;
if (keypress[Qt::Key_S])
camera[currentCamera].Movement_z += 0.01;
if (keypress[Qt::Key_A])
camera[currentCamera].Movement_x -= 0.01;
if (keypress[Qt::Key_D])
camera[currentCamera].Movement_x += 0.01;
if (keypress[Qt::Key_Q])
camera[currentCamera].Movement_y -= 0.01;
if (keypress[Qt::Key_E])
camera[currentCamera].Movement_y += 0.01;
updateGL();
}
void OGLWidget::timeOutSlot()
{
if (keypress[Qt::Key_W])
camera[currentCamera].Movement_z -= 0.01;
if (keypress[Qt::Key_S])
camera[currentCamera].Movement_z += 0.01;
if (keypress[Qt::Key_A])
camera[currentCamera].Movement_x -= 0.01;
if (keypress[Qt::Key_D])
camera[currentCamera].Movement_x += 0.01;
if (keypress[Qt::Key_Q])
camera[currentCamera].Movement_y -= 0.01;
if (keypress[Qt::Key_E])
camera[currentCamera].Movement_y += 0.01;
updateGL();
}
To copy to clipboard, switch view to plain text mode
but the results are still erratic, how would I go about polling key press events using a timer or can you suggest an example or tutorial that I could refer to?
Bookmarks