// Pan left/right/up/down without rotating about the object.
void QGLGraphicsNavigationItemPrivate::pan(qreal deltax, qreal deltay)
{
    QGLCamera *camera = viewportItem->camera();
    QPointF delta = viewDelta(deltax, deltay);
    QVector3D t = camera->translation(delta.x(), -delta.y(), 0.0f);

    // Technically panning the eye left should make the object appear to
    // move off to the right, but this looks weird on-screen where the user
    // actually thinks they are picking up the object and dragging it rather
    // than moving the eye.  We therefore apply the inverse of the translation
    // to make it "look right".
    camera->setEye(camera->eye() - t);
    camera->setCenter(camera->center() - t);
}
Exemple #2
0
void SpotView::paintGL()
{
    QGLPainter painter(this);
    //painter.begin();
    painter.clear();

    // Set perspective transformation and position model-view matrix
    QGLCamera camera;
    QVector3D sceneOrigin = floor->boundingBox().center();
    camera.setCenter(sceneOrigin);
    camera.setEye(sceneOrigin + QVector3D(0.0f, 5.0f, 20.0f));
    camera.apply(&painter);

    paintGL(&painter);
}
Exemple #3
0
void CubeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (navigating) {
        QPoint delta = event->pos().toPoint() - pressedPos;
        int deltax = delta.x();
        int deltay = delta.y();
        QGLCamera *camera = this->camera();
        int rotation = camera->screenRotation();
        if (rotation == 90 || rotation == 270) {
            qSwap(deltax, deltay);
        }
        if (rotation == 90 || rotation == 180) {
            deltax = -deltax;
        }
        if (rotation == 180 || rotation == 270) {
            deltay = -deltay;
        }
        qreal anglex = deltax * 90.0f / rect().width();
        qreal angley = deltay * 90.0f / rect().height();
        QQuaternion q = startNavCamera->pan(-anglex);
        q *= startNavCamera->tilt(-angley);
        camera->setEye(startNavCamera->eye());
        camera->setCenter(startNavCamera->center());
        camera->setUpVector(startNavCamera->upVector());
        camera->rotateCenter(q);
    } else if (pressedFace != -1) {
        int face;
        QPoint pos = cubeIntersection
            (event->widget(), event->pos().toPoint(), &face);
        if (face != pressedFace)
            pos = QPoint(-1, -1);
        deliverSceneEvent(pos, event);
        return;
    }
    QGraphicsItem::mouseMoveEvent(event);
}