hab grad ma angefangen, n bissl mit qt rumzuprogrammiern. ich wollte eine recht grosse szene mit opengl darstellen. in dieser szene wollte ich mich dann mittels mouse und tastatur bewegen koennen - so wie im 3d-spiel. jedoch scheinen die events sich gegenseitig zu behindern:
- mehrere tasten gleichzeitig geht nur willkuerlich
- mouse und tastatur zusammen ruckelt (bei konstanter fps)
Code: Alles auswählen
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
QCursor c;
if(_navScene)
{
c.setShape(Qt::BlankCursor);
QPoint p=c.pos();
yaw += 0.002f * ( p.x() - 500);
pitch -= 0.002f * ( p.y() - 500);
if (pitch > 1.0f ) pitch = 1.0f;
else if (pitch < -1.0f) pitch = -1.0f;
_v3set( tempDir, float(cos(yaw)*cos(pitch)),
float(sin(pitch)),
float(sin(yaw)*cos(pitch)));
_v3add( camPos, tempDir, camDir);
_v3crs( tempDir, camUp, tempDirCrs);
_v3scl( tempDir, 0.5f, tempDir);
_v3scl( tempDirCrs, 0.5f, tempDirCrs);
c.setPos(500,500);
setCursor(c);
updateGL();
}
}
void GLWidget::keyPressEvent(QKeyEvent *event)
{
switch(event->key())
{
case Qt::Key_D:
if(_navScene)
{
_v3add(camPos, tempDirCrs, camPos);
_v3add(camDir, tempDirCrs, camDir);
}
break;
case Qt::Key_A:
if(_navScene)
{
_v3sub(camPos, tempDirCrs, camPos);
_v3sub(camDir, tempDirCrs, camDir);
}
break;
case Qt::Key_S:
if(_navScene)
{
_v3sub(camPos, tempDir, camPos);
_v3sub(camDir, tempDir, camDir);
}
break;
case Qt::Key_W:
if(_navScene)
{
_v3add(camPos, tempDir, camPos);
_v3add(camDir, tempDir, camDir);
}
break;
}
updateGL();
}
thx