Exemplo n.º 1
0
void QCamera::rotate( const QQuaternion& q )
{
    setUpVector(q * upVector());
    QVector3D viewVector = viewCenter() - position();
    QVector3D cameraToCenter = q * viewVector;
    setViewCenter(position() + cameraToCenter);
}
Exemplo n.º 2
0
void QCamera::translateWorld(const QVector3D& vWorld , CameraTranslationOption option )
{
    // Update the camera position using the calculated world vector
    setPosition(position() + vWorld);

    // May be also update the view center coordinates
    if ( option == TranslateViewCenter )
        setViewCenter(viewCenter() + vWorld);
}
Exemplo n.º 3
0
void QCamera::translate( const QVector3D& vLocal, CameraTranslationOption option )
{
    QVector3D viewVector = viewCenter() - position(); // From "camera" position to view center

    // Calculate the amount to move by in world coordinates
    QVector3D vWorld;
    if ( !qFuzzyIsNull( vLocal.x() ) )
    {
        // Calculate the vector for the local x axis
        QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized();
        vWorld += vLocal.x() * x;
    }

    if ( !qFuzzyIsNull( vLocal.y() ) )
        vWorld += vLocal.y() * upVector();

    if ( !qFuzzyIsNull( vLocal.z() ) )
        vWorld += vLocal.z() * viewVector.normalized();

    // Update the camera position using the calculated world vector
    setPosition(position() + vWorld);

    // May be also update the view center coordinates
    if ( option == TranslateViewCenter )
        setViewCenter(viewCenter() + vWorld);

    // Refresh the camera -> view center vector
    viewVector = viewCenter() - position();

    // Calculate a new up vector. We do this by:
    // 1) Calculate a new local x-direction vector from the cross product of the new
    //    camera to view center vector and the old up vector.
    // 2) The local x vector is the normal to the plane in which the new up vector
    //    must lay. So we can take the cross product of this normal and the new
    //    x vector. The new normal vector forms the last part of the orthonormal basis
    QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized();
    setUpVector(QVector3D::crossProduct(x, viewVector).normalized());
}
Exemplo n.º 4
0
void Camera::playSequence()
{
    Q_D(Camera);

    int curveIndex = MathHelper::toInt(floor(MathHelper::toFloat(d->play_tick) / MathHelper::toFloat(d->play_ticks / d->curves.count())));
    int playTicks  = d->play_ticks / d->curves.count();
    int playTick   = d->play_tick - (playTicks * curveIndex);

    if(curveIndex >= d->curves.count())
        stop();

    BezierCurve* curve = d->curves.at(curveIndex);

    ++d->play_tick;

    float t = 1.0f / playTicks * playTick;

    setPosition(curve->calculatePoint(t));
    setViewCenter(curve->calculateViewCenter(t));
    setUpVector(curve->calculateUpVector(t));

    if(d->play_tick == d->play_ticks)
        stop(false);
}