Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dquaternionanimation.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
7#include <QtQuick/private/qquickanimation_p_p.h>
8
10
11/*!
12 \qmltype QuaternionAnimation
13 \inherits PropertyAnimation
14 \inqmlmodule QtQuick3D
15 \since 5.15
16
17 \brief A PropertyAnimation for quaternions.
18
19 A specialized \l{PropertyAnimation} that defines an animation between two
20 \l{QQuaternion}{quaternions}.
21
22 By default spherical linear interpolation is used. This can be changed to
23 the faster but less accurate normalized linear interpolation by setting the
24 \a type property.
25
26 Instead of specifying quaternions directly in the \a from and \a to
27 properties, it is also possible to provide euler angles in degrees in the
28 \a fromXRotation, \a toXRotation, \a fromYRotation, \a toYRotation,
29 \a fromZRotation, \a toZRotation properties.
30
31 \note Avoid mixing the quaternion and euler angle-based properties. The
32 from and to values are expected to be fully specified either via a
33 quaternion or the three euler angles.
34
35 \sa {Animation and Transitions in Qt Quick} QQuaternion QQuaternion::slerp() QQuaternion::nlerp()
36*/
37
51
52
53QVariant q_quaternionInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress)
54{
55 return QVariant::fromValue(QQuaternion::slerp(from, to, progress));
56}
57
58QVariant q_quaternionNlerpInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress)
59{
60 return QVariant::fromValue(QQuaternion::nlerp(from, to, progress));
61}
62
63QQuick3DQuaternionAnimation::QQuick3DQuaternionAnimation(QObject *parent)
64 : QQuickPropertyAnimation(*(new QQuick3DQuaternionAnimationPrivate), parent)
65{
66 Q_D(QQuick3DQuaternionAnimation);
67 d->interpolatorType = qMetaTypeId<QQuaternion>();
68 d->defaultToInterpolatorType = true;
69 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
70}
71
72/*!
73 \qmlproperty quaternion QtQuick3D::QuaternionAnimation::from
74
75 This property holds the starting value for the animation.
76
77*/
78
79QQuaternion QQuick3DQuaternionAnimation::from() const
80{
81 Q_D(const QQuick3DQuaternionAnimation);
82 return d->from.value<QQuaternion>();
83}
84
85void QQuick3DQuaternionAnimation::setFrom(const QQuaternion &f)
86{
87 QQuickPropertyAnimation::setFrom(QVariant::fromValue(f));
88}
89
90/*!
91 \qmlproperty quaternion QtQuick3D::QuaternionAnimation::to
92
93 This property holds the ending value for the animation.
94
95*/
96
97QQuaternion QQuick3DQuaternionAnimation::to() const
98{
99 Q_D(const QQuick3DQuaternionAnimation);
100 return d->to.value<QQuaternion>();
101}
102
103void QQuick3DQuaternionAnimation::setTo(const QQuaternion &t)
104{
105 QQuickPropertyAnimation::setTo(QVariant::fromValue(t));
106}
107
108/*!
109 \qmlproperty enumeration QtQuick3D::QuaternionAnimation::type
110
111 This property defines the interpolation mode.
112
113 \value QuaternionAnimation.Slerp Spherical linear interpolation.
114 \value QuaternionAnimation.Nlerp Normalized linear interpolation.
115
116*/
117
118QQuick3DQuaternionAnimation::Type QQuick3DQuaternionAnimation::type() const
119{
120 Q_D(const QQuick3DQuaternionAnimation);
121 return d->type;
122}
123
124void QQuick3DQuaternionAnimation::setType(Type type)
125{
126 Q_D(QQuick3DQuaternionAnimation);
127 if (d->type == type)
128 return;
129
130 d->type = type;
131 switch (type) {
132 case Nlerp:
133 d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void(*)()>(&q_quaternionNlerpInterpolator));
134 break;
135 case Slerp:
136 default:
137 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
138 break;
139 }
140
141 emit typeChanged(type);
142}
143
144/*!
145 \qmlproperty real QtQuick3D::QuaternionAnimation::fromXRotation
146
147 This property holds the starting value of the animation for the X axis as
148 an euler angle in degrees.
149
150*/
151
152float QQuick3DQuaternionAnimation::fromXRotation() const
153{
154 Q_D(const QQuick3DQuaternionAnimation);
155 return d->anglesFrom.x();
156}
157
158void QQuick3DQuaternionAnimation::setFromXRotation(float f)
159{
160 Q_D(QQuick3DQuaternionAnimation);
161 if (d->anglesFrom.x() == f)
162 return;
163 d->anglesFrom.setX(f);
164 setFrom(QQuaternion::fromEulerAngles(d->anglesFrom));
165 emit fromXRotationChanged(f);
166}
167
168/*!
169 \qmlproperty real QtQuick3D::QuaternionAnimation::fromYRotation
170
171 This property holds the starting value of the animation for the Y axis as
172 an euler angle in degrees.
173
174*/
175
176float QQuick3DQuaternionAnimation::fromYRotation() const
177{
178 Q_D(const QQuick3DQuaternionAnimation);
179 return d->anglesFrom.y();
180}
181
182void QQuick3DQuaternionAnimation::setFromYRotation(float f)
183{
184 Q_D(QQuick3DQuaternionAnimation);
185 if (d->anglesFrom.y() == f)
186 return;
187 d->anglesFrom.setY(f);
188 setFrom(QQuaternion::fromEulerAngles(d->anglesFrom));
189 emit fromYRotationChanged(f);
190}
191
192/*!
193 \qmlproperty real QtQuick3D::QuaternionAnimation::fromZRotation
194
195 This property holds the starting value of the animation for the Z axis as
196 an euler angle in degrees.
197
198*/
199
200float QQuick3DQuaternionAnimation::fromZRotation() const
201{
202 Q_D(const QQuick3DQuaternionAnimation);
203 return d->anglesFrom.z();
204}
205
206void QQuick3DQuaternionAnimation::setFromZRotation(float f)
207{
208 Q_D(QQuick3DQuaternionAnimation);
209 if (d->anglesFrom.z() == f)
210 return;
211 d->anglesFrom.setZ(f);
212 setFrom(QQuaternion::fromEulerAngles(d->anglesFrom));
213 emit fromZRotationChanged(f);
214}
215
216/*!
217 \qmlproperty real QtQuick3D::QuaternionAnimation::toXRotation
218
219 This property holds the ending value of the animation for the X axis as
220 an euler angle in degrees.
221
222*/
223
224float QQuick3DQuaternionAnimation::toXRotation() const
225{
226 Q_D(const QQuick3DQuaternionAnimation);
227 return d->anglesTo.x();
228}
229
230void QQuick3DQuaternionAnimation::setToXRotation(float f)
231{
232 Q_D(QQuick3DQuaternionAnimation);
233 if (d->anglesTo.x() == f)
234 return;
235 d->anglesTo.setX(f);
236 setTo(QQuaternion::fromEulerAngles(d->anglesTo));
237 emit toXRotationChanged(f);
238}
239
240/*!
241 \qmlproperty real QtQuick3D::QuaternionAnimation::toYRotation
242
243 This property holds the ending value of the animation for the Y axis as
244 an euler angle in degrees.
245
246*/
247
248float QQuick3DQuaternionAnimation::toYRotation() const
249{
250 Q_D(const QQuick3DQuaternionAnimation);
251 return d->anglesTo.y();
252}
253
254void QQuick3DQuaternionAnimation::setToYRotation(float f)
255{
256 Q_D(QQuick3DQuaternionAnimation);
257 if (d->anglesTo.y() == f)
258 return;
259 d->anglesTo.setY(f);
260 setTo(QQuaternion::fromEulerAngles(d->anglesTo));
261 emit toYRotationChanged(f);
262}
263
264/*!
265 \qmlproperty real QtQuick3D::QuaternionAnimation::toZRotation
266
267 This property holds the ending value of the animation for the Z axis as
268 an euler angle in degrees.
269
270*/
271
272float QQuick3DQuaternionAnimation::toZRotation() const
273{
274 Q_D(const QQuick3DQuaternionAnimation);
275 return d->anglesTo.z();
276}
277
278void QQuick3DQuaternionAnimation::setToZRotation(float f)
279{
280 Q_D(QQuick3DQuaternionAnimation);
281 if (d->anglesTo.z() == f)
282 return;
283 d->anglesTo.setZ(f);
284 setTo(QQuaternion::fromEulerAngles(d->anglesTo));
285 emit toZRotationChanged(f);
286}
287
288QT_END_NAMESPACE
\qmltype QuaternionAnimation \inherits PropertyAnimation \inqmlmodule QtQuick3D
Combined button and popup list for selecting options.
QVariant q_quaternionInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress)
QVariant q_quaternionNlerpInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress)