Exemple #1
0
// Zoom in and out according to the change in wheel delta.
void QGLView::wheel(int delta)
{
    if (d->options & QGLView::FOVZoom) {     
        //Use field-of view as zoom (much like a traditional camera)
        qreal scale = qAbs(viewDelta(delta, delta).x());
        if (delta < 0)
            scale = -scale;
        if (scale >= 0.0f)
            scale += 1.0f;
        else
            scale = 1.0f / (1.0f - scale);
        qreal fov = d->camera->fieldOfView();
        if (fov != 0.0f)
            d->camera->setFieldOfView(d->camera->fieldOfView() / scale);
        else
            d->camera->setViewSize(d->camera->viewSize() / scale);
    } else {
        // enable this to get wheel navigation that actually zooms by moving the
        // camera back, as opposed to making the angle of view wider.        
        QVector3D viewVector= camera()->eye() - camera()->center();
        qreal zoomMag = viewVector.length();
        qreal zoomIncrement = -float(delta) / 100.0f;
        if (!qFuzzyIsNull(zoomIncrement))
        {
            zoomMag += zoomIncrement;
            if (zoomMag < 1.0f)
                zoomMag = 1.0f;

            QRay3D viewLine(camera()->center(), viewVector.normalized());
            camera()->setEye(viewLine.point(zoomMag));
        }
    }

}
Exemple #2
0
// Pan left/right/up/down without rotating about the object.
void QGLView::pan(int deltax, int deltay)
{
    QPointF delta = viewDelta(deltax, deltay);
    QVector3D t = d->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".
    d->camera->setEye(d->camera->eye() - t);
    d->camera->setCenter(d->camera->center() - t);
}
// 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 #4
0
// Zoom in and out according to the change in wheel delta.
void QGLView::wheel(int delta)
{
    qreal scale = qAbs(viewDelta(delta, delta).x());
    if (delta < 0)
        scale = -scale;
    if (scale >= 0.0f)
        scale += 1.0f;
    else
        scale = 1.0f / (1.0f - scale);
    qreal fov = d->camera->fieldOfView();
    if (fov != 0.0f)
        d->camera->setFieldOfView(d->camera->fieldOfView() / scale);
    else
        d->camera->setViewSize(d->camera->viewSize() / scale);
}
// Zoom in and out according to the change in wheel delta.
void QGLGraphicsNavigationItemPrivate::wheel(qreal delta)
{
    QGLCamera *camera = viewportItem->camera();
    qreal scale = qAbs(viewDelta(delta, delta).x());
    if (delta < 0)
        scale = -scale;
    if (scale >= 0.0f)
        scale += 1.0f;
    else
        scale = 1.0f / (1.0f - scale);
    qreal fov = camera->fieldOfView();
    if (fov != 0.0f)
        camera->setFieldOfView(camera->fieldOfView() / scale);
    else
        camera->setViewSize(camera->viewSize() / scale);
}