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()
36 QQuaternion::fastSlerp() QQuaternion::nlerp()
37*/
38
52
53
54QVariant q_quaternionInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress)
55{
56 return QVariant::fromValue(QQuaternion::fastSlerp(from, to, progress));
57}
58
59QVariant q_quaternionNlerpInterpolator(const QQuaternion &from, const QQuaternion &to, qreal progress)
60{
61 return QVariant::fromValue(QQuaternion::nlerp(from, to, progress));
62}
63
64QQuick3DQuaternionAnimation::QQuick3DQuaternionAnimation(QObject *parent)
65 : QQuickPropertyAnimation(*(new QQuick3DQuaternionAnimationPrivate), parent)
66{
67 Q_D(QQuick3DQuaternionAnimation);
68 d->interpolatorType = qMetaTypeId<QQuaternion>();
69 d->defaultToInterpolatorType = true;
70 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
71}
72
73/*!
74 \qmlproperty quaternion QtQuick3D::QuaternionAnimation::from
75
76 This property holds the starting value for the animation.
77
78*/
79
80QQuaternion QQuick3DQuaternionAnimation::from() const
81{
82 Q_D(const QQuick3DQuaternionAnimation);
83 return d->from.value<QQuaternion>();
84}
85
86void QQuick3DQuaternionAnimation::setFrom(const QQuaternion &f)
87{
88 QQuickPropertyAnimation::setFrom(QVariant::fromValue(f));
89}
90
91/*!
92 \qmlproperty quaternion QtQuick3D::QuaternionAnimation::to
93
94 This property holds the ending value for the animation.
95
96*/
97
98QQuaternion QQuick3DQuaternionAnimation::to() const
99{
100 Q_D(const QQuick3DQuaternionAnimation);
101 return d->to.value<QQuaternion>();
102}
103
104void QQuick3DQuaternionAnimation::setTo(const QQuaternion &t)
105{
106 QQuickPropertyAnimation::setTo(QVariant::fromValue(t));
107}
108
109/*!
110 \qmlproperty enumeration QtQuick3D::QuaternionAnimation::type
111
112 This property defines the interpolation mode.
113
114 \value QuaternionAnimation.Slerp Spherical linear interpolation.
115 \value QuaternionAnimation.Nlerp Normalized linear interpolation.
116
117*/
118
119QQuick3DQuaternionAnimation::Type QQuick3DQuaternionAnimation::type() const
120{
121 Q_D(const QQuick3DQuaternionAnimation);
122 return d->type;
123}
124
125void QQuick3DQuaternionAnimation::setType(Type type)
126{
127 Q_D(QQuick3DQuaternionAnimation);
128 if (d->type == type)
129 return;
130
131 d->type = type;
132 switch (type) {
133 case Nlerp:
134 d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void(*)()>(&q_quaternionNlerpInterpolator));
135 break;
136 case Slerp:
137 default:
138 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
139 break;
140 }
141
142 emit typeChanged(type);
143}
144
145/*!
146 \qmlproperty real QtQuick3D::QuaternionAnimation::fromXRotation
147
148 This property holds the starting value of the animation for the X axis as
149 an euler angle in degrees.
150
151*/
152
153float QQuick3DQuaternionAnimation::fromXRotation() const
154{
155 Q_D(const QQuick3DQuaternionAnimation);
156 return d->anglesFrom.x();
157}
158
159void QQuick3DQuaternionAnimation::setFromXRotation(float f)
160{
161 Q_D(QQuick3DQuaternionAnimation);
162 if (d->anglesFrom.x() == f)
163 return;
164 d->anglesFrom.setX(f);
165 setFrom(QQuaternion::fromEulerAngles(d->anglesFrom));
166 emit fromXRotationChanged(f);
167}
168
169/*!
170 \qmlproperty real QtQuick3D::QuaternionAnimation::fromYRotation
171
172 This property holds the starting value of the animation for the Y axis as
173 an euler angle in degrees.
174
175*/
176
177float QQuick3DQuaternionAnimation::fromYRotation() const
178{
179 Q_D(const QQuick3DQuaternionAnimation);
180 return d->anglesFrom.y();
181}
182
183void QQuick3DQuaternionAnimation::setFromYRotation(float f)
184{
185 Q_D(QQuick3DQuaternionAnimation);
186 if (d->anglesFrom.y() == f)
187 return;
188 d->anglesFrom.setY(f);
189 setFrom(QQuaternion::fromEulerAngles(d->anglesFrom));
190 emit fromYRotationChanged(f);
191}
192
193/*!
194 \qmlproperty real QtQuick3D::QuaternionAnimation::fromZRotation
195
196 This property holds the starting value of the animation for the Z axis as
197 an euler angle in degrees.
198
199*/
200
201float QQuick3DQuaternionAnimation::fromZRotation() const
202{
203 Q_D(const QQuick3DQuaternionAnimation);
204 return d->anglesFrom.z();
205}
206
207void QQuick3DQuaternionAnimation::setFromZRotation(float f)
208{
209 Q_D(QQuick3DQuaternionAnimation);
210 if (d->anglesFrom.z() == f)
211 return;
212 d->anglesFrom.setZ(f);
213 setFrom(QQuaternion::fromEulerAngles(d->anglesFrom));
214 emit fromZRotationChanged(f);
215}
216
217/*!
218 \qmlproperty real QtQuick3D::QuaternionAnimation::toXRotation
219
220 This property holds the ending value of the animation for the X axis as
221 an euler angle in degrees.
222
223*/
224
225float QQuick3DQuaternionAnimation::toXRotation() const
226{
227 Q_D(const QQuick3DQuaternionAnimation);
228 return d->anglesTo.x();
229}
230
231void QQuick3DQuaternionAnimation::setToXRotation(float f)
232{
233 Q_D(QQuick3DQuaternionAnimation);
234 if (d->anglesTo.x() == f)
235 return;
236 d->anglesTo.setX(f);
237 setTo(QQuaternion::fromEulerAngles(d->anglesTo));
238 emit toXRotationChanged(f);
239}
240
241/*!
242 \qmlproperty real QtQuick3D::QuaternionAnimation::toYRotation
243
244 This property holds the ending value of the animation for the Y axis as
245 an euler angle in degrees.
246
247*/
248
249float QQuick3DQuaternionAnimation::toYRotation() const
250{
251 Q_D(const QQuick3DQuaternionAnimation);
252 return d->anglesTo.y();
253}
254
255void QQuick3DQuaternionAnimation::setToYRotation(float f)
256{
257 Q_D(QQuick3DQuaternionAnimation);
258 if (d->anglesTo.y() == f)
259 return;
260 d->anglesTo.setY(f);
261 setTo(QQuaternion::fromEulerAngles(d->anglesTo));
262 emit toYRotationChanged(f);
263}
264
265/*!
266 \qmlproperty real QtQuick3D::QuaternionAnimation::toZRotation
267
268 This property holds the ending value of the animation for the Z axis as
269 an euler angle in degrees.
270
271*/
272
273float QQuick3DQuaternionAnimation::toZRotation() const
274{
275 Q_D(const QQuick3DQuaternionAnimation);
276 return d->anglesTo.z();
277}
278
279void QQuick3DQuaternionAnimation::setToZRotation(float f)
280{
281 Q_D(QQuick3DQuaternionAnimation);
282 if (d->anglesTo.z() == f)
283 return;
284 d->anglesTo.setZ(f);
285 setTo(QQuaternion::fromEulerAngles(d->anglesTo));
286 emit toZRotationChanged(f);
287}
288
289QT_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)