diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-12-11 09:21:31 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-12-17 12:56:30 +0000 |
commit | aa86521ebde68c258ac85806d65dca194aa72da8 (patch) | |
tree | b910c2dd493ebf9a7e66fb7d0b9823ad7f10a606 /src/quick3d/quick3d | |
parent | 538fd7f2ff09cea4548069af39b98be0677cc694 (diff) |
Add QuaternionAnimation
Change-Id: I266d745e13fe0c1a3aa6a381a3b43f1b751d1445
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d/quick3d')
-rw-r--r-- | src/quick3d/quick3d/qquaternionanimation.cpp | 253 | ||||
-rw-r--r-- | src/quick3d/quick3d/qquaternionanimation_p.h | 133 | ||||
-rw-r--r-- | src/quick3d/quick3d/quick3d.pro | 8 |
3 files changed, 391 insertions, 3 deletions
diff --git a/src/quick3d/quick3d/qquaternionanimation.cpp b/src/quick3d/quick3d/qquaternionanimation.cpp new file mode 100644 index 000000000..986cc8af9 --- /dev/null +++ b/src/quick3d/quick3d/qquaternionanimation.cpp @@ -0,0 +1,253 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt 3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquaternionanimation_p.h" +#include <QtQuick/private/qquickanimation_p_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype QuaternionAnimation + \instantiates QQuaternionAnimation + \inherits PropertyAnimation + \inqmlmodule Qt3D + \since 5.6 + + \brief A PropertyAnimation for quaternions. + + A specialized \l{PropertyAnimation} that defines an animation between two + \l{QQuaternion}{quaternions}. + + By default spherical linear interpolation is used. This can be changed to + the faster but less accurate normalized linear interpolation by setting the + \a type property. + + Instead of specifying quaternions directly in the \a from and \a to + properties, it is also possible to provide euler angles in degrees in the + \a fromXRotation, \a toXRotation, \a fromYRotation, \a toYRotation, + \a fromZRotation, \a toZRotation properties. + + \note Avoid mixing the quaternion and euler angle-based properties. The + from and to values are expected to be fully specified either via a + quaternion or the three euler angles. + + \sa {Animation and Transitions in Qt Quick} QQuaternion QQuaternion::slerp() QQuaternion::nlerp() +*/ + +namespace Qt3DCore { +namespace Quick { + +class QQuaternionAnimationPrivate : public QQuickPropertyAnimationPrivate +{ + Q_DECLARE_PUBLIC(QQuaternionAnimation) + +public: + QQuaternionAnimationPrivate() : + type(QQuaternionAnimation::Slerp) + { } + + QQuaternionAnimation::Type type; + QVector3D anglesFrom; + QVector3D anglesTo; +}; + +QVariant q_quaternionInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress) +{ + return QVariant::fromValue(QQuaternion::slerp(from, to, progress)); +} + +QVariant q_quaternionNlerpInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress) +{ + return QVariant::fromValue(QQuaternion::nlerp(from, to, progress)); +} + +QQuaternionAnimation::QQuaternionAnimation(QObject *parent) + : QQuickPropertyAnimation(*(new QQuaternionAnimationPrivate), parent) +{ + Q_D(QQuaternionAnimation); + d->interpolatorType = qMetaTypeId<QQuaternion>(); + d->defaultToInterpolatorType = true; + d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType); +} + +QQuaternion QQuaternionAnimation::from() const +{ + Q_D(const QQuaternionAnimation); + return d->from.value<QQuaternion>(); +} + +void QQuaternionAnimation::setFrom(const QQuaternion &f) +{ + QQuickPropertyAnimation::setFrom(QVariant::fromValue(f)); +} + +QQuaternion QQuaternionAnimation::to() const +{ + Q_D(const QQuaternionAnimation); + return d->to.value<QQuaternion>(); +} + +void QQuaternionAnimation::setTo(const QQuaternion &t) +{ + QQuickPropertyAnimation::setTo(QVariant::fromValue(t)); +} + +QQuaternionAnimation::Type QQuaternionAnimation::type() const +{ + Q_D(const QQuaternionAnimation); + return d->type; +} + +void QQuaternionAnimation::setType(Type type) +{ + Q_D(QQuaternionAnimation); + if (d->type == type) + return; + + d->type = type; + switch (type) { + case Nlerp: + d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(&q_quaternionNlerpInterpolator); + break; + case Slerp: + default: + d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType); + break; + } + + emit typeChanged(type); +} + +float QQuaternionAnimation::fromXRotation() const +{ + Q_D(const QQuaternionAnimation); + return d->anglesFrom.x(); +} + +void QQuaternionAnimation::setFromXRotation(float f) +{ + Q_D(QQuaternionAnimation); + if (d->anglesFrom.x() == f) + return; + d->anglesFrom.setX(f); + setFrom(QQuaternion::fromEulerAngles(d->anglesFrom)); + emit fromXRotationChanged(f); +} + +float QQuaternionAnimation::fromYRotation() const +{ + Q_D(const QQuaternionAnimation); + return d->anglesFrom.y(); +} + +void QQuaternionAnimation::setFromYRotation(float f) +{ + Q_D(QQuaternionAnimation); + if (d->anglesFrom.y() == f) + return; + d->anglesFrom.setY(f); + setFrom(QQuaternion::fromEulerAngles(d->anglesFrom)); + emit fromYRotationChanged(f); +} + +float QQuaternionAnimation::fromZRotation() const +{ + Q_D(const QQuaternionAnimation); + return d->anglesFrom.z(); +} + +void QQuaternionAnimation::setFromZRotation(float f) +{ + Q_D(QQuaternionAnimation); + if (d->anglesFrom.z() == f) + return; + d->anglesFrom.setZ(f); + setFrom(QQuaternion::fromEulerAngles(d->anglesFrom)); + emit fromZRotationChanged(f); +} + +float QQuaternionAnimation::toXRotation() const +{ + Q_D(const QQuaternionAnimation); + return d->anglesTo.x(); +} + +void QQuaternionAnimation::setToXRotation(float f) +{ + Q_D(QQuaternionAnimation); + if (d->anglesTo.x() == f) + return; + d->anglesTo.setX(f); + setTo(QQuaternion::fromEulerAngles(d->anglesTo)); + emit toXRotationChanged(f); +} + +float QQuaternionAnimation::toYRotation() const +{ + Q_D(const QQuaternionAnimation); + return d->anglesTo.y(); +} + +void QQuaternionAnimation::setToYRotation(float f) +{ + Q_D(QQuaternionAnimation); + if (d->anglesTo.y() == f) + return; + d->anglesTo.setY(f); + setTo(QQuaternion::fromEulerAngles(d->anglesTo)); + emit toYRotationChanged(f); +} + +float QQuaternionAnimation::toZRotation() const +{ + Q_D(const QQuaternionAnimation); + return d->anglesTo.z(); +} + +void QQuaternionAnimation::setToZRotation(float f) +{ + Q_D(QQuaternionAnimation); + if (d->anglesTo.z() == f) + return; + d->anglesTo.setZ(f); + setTo(QQuaternion::fromEulerAngles(d->anglesTo)); + emit toZRotationChanged(f); +} + +} // namespace Quick +} // namespace Qt3DCore + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3d/qquaternionanimation_p.h b/src/quick3d/quick3d/qquaternionanimation_p.h new file mode 100644 index 000000000..2c968df58 --- /dev/null +++ b/src/quick3d/quick3d/qquaternionanimation_p.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt 3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUATERNIONANIMATION_P_H +#define QQUATERNIONANIMATION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DQuick/private/qt3dquick_global_p.h> +#include <QtQuick/private/qquickanimation_p.h> +#include <QtGui/qquaternion.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +namespace Quick { + +class QQuaternionAnimationPrivate; + +class QT3DQUICKSHARED_PRIVATE_EXPORT QQuaternionAnimation : public QQuickPropertyAnimation +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QQuaternionAnimation) + + Q_PROPERTY(QQuaternion from READ from WRITE setFrom) + Q_PROPERTY(QQuaternion to READ to WRITE setTo) + Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged) + + Q_PROPERTY(float fromXRotation READ fromXRotation WRITE setFromXRotation NOTIFY fromXRotationChanged) + Q_PROPERTY(float fromYRotation READ fromYRotation WRITE setFromYRotation NOTIFY fromYRotationChanged) + Q_PROPERTY(float fromZRotation READ fromZRotation WRITE setFromZRotation NOTIFY fromZRotationChanged) + Q_PROPERTY(float toXRotation READ toXRotation WRITE setToXRotation NOTIFY toXRotationChanged) + Q_PROPERTY(float toYRotation READ toYRotation WRITE setToYRotation NOTIFY toYRotationChanged) + Q_PROPERTY(float toZRotation READ toZRotation WRITE setToZRotation NOTIFY toZRotationChanged) + +public: + enum Type { + Slerp = 0, + Nlerp + }; + Q_ENUM(Type) + + QQuaternionAnimation(QObject *parent = 0); + + QQuaternion from() const; + void setFrom(const QQuaternion &f); + + QQuaternion to() const; + void setTo(const QQuaternion &t); + + Type type() const; + void setType(Type type); + + float fromXRotation() const; + void setFromXRotation(float f); + + float fromYRotation() const; + void setFromYRotation(float f); + + float fromZRotation() const; + void setFromZRotation(float f); + + float toXRotation() const; + void setToXRotation(float f); + + float toYRotation() const; + void setToYRotation(float f); + + float toZRotation() const; + void setToZRotation(float f); + +Q_SIGNALS: + void typeChanged(Type type); + void fromXRotationChanged(float value); + void fromYRotationChanged(float value); + void fromZRotationChanged(float value); + void toXRotationChanged(float value); + void toYRotationChanged(float value); + void toZRotationChanged(float value); +}; + +QT3DQUICKSHARED_PRIVATE_EXPORT QVariant q_quaternionInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress); + +} // namespace Quick +} // namespace Qt3DCore + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(Qt3DCore::Quick::QQuaternionAnimation) + +#endif // QQUATERNIONANIMATION_P_H diff --git a/src/quick3d/quick3d/quick3d.pro b/src/quick3d/quick3d/quick3d.pro index 4726b749a..a1d26a0ca 100644 --- a/src/quick3d/quick3d/quick3d.pro +++ b/src/quick3d/quick3d/quick3d.pro @@ -1,6 +1,6 @@ TARGET = Qt3DQuick -QT += core-private gui-private qml qml-private 3dcore 3dcore-private +QT += core-private gui-private qml qml-private quick quick-private 3dcore 3dcore-private DEFINES += QT3DQUICK_LIBRARY @@ -20,13 +20,15 @@ HEADERS += \ qt3dquickvaluetypes_p.h \ qt3dquicknodefactory_p.h \ qqmlaspectengine.h \ - qqmlaspectengine_p.h + qqmlaspectengine_p.h \ + qquaternionanimation_p.h SOURCES += \ qt3dquick_global.cpp \ qt3dquickvaluetypes.cpp \ qt3dquicknodefactory.cpp \ - qqmlaspectengine.cpp + qqmlaspectengine.cpp \ + qquaternionanimation.cpp !contains(QT_CONFIG, egl):DEFINES += QT_NO_EGL |