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
qquick3dparticlepointrotator.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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
9
10/*!
11 \qmltype PointRotator3D
12 \inherits Affector3D
13 \inqmlmodule QtQuick3D.Particles3D
14 \brief Rotates particles around a pivot point.
15 \since 6.2
16
17 This element rotates particles around a \l pivotPoint towards the \l direction.
18*/
19
20QQuick3DParticlePointRotator::QQuick3DParticlePointRotator(QQuick3DNode *parent)
21 : QQuick3DParticleAffector(parent)
22{
23}
24
25/*!
26 \qmlproperty real PointRotator3D::magnitude
27
28 This property defines the magnitude in degrees per second. Negative magnitude
29 rotates to the opposite way from the \l {PointRotator3D::direction}{direction}.
30
31 The default value is \c 10.0.
32*/
33float QQuick3DParticlePointRotator::magnitude() const
34{
35 return m_magnitude;
36}
37
38void QQuick3DParticlePointRotator::setMagnitude(float magnitude)
39{
40 if (qFuzzyCompare(m_magnitude, magnitude))
41 return;
42
43 m_magnitude = magnitude;
44 Q_EMIT magnitudeChanged();
45 Q_EMIT update();
46}
47
48/*!
49 \qmlproperty vector3d PointRotator3D::direction
50
51 This property defines the direction for the rotation. Values will be
52 automatically normalized to a unit vector.
53
54 The default value is \c (0.0, 1.0, 0.0) (around the y-coordinate).
55*/
56QVector3D QQuick3DParticlePointRotator::direction() const
57{
58 return m_direction;
59}
60
61void QQuick3DParticlePointRotator::setDirection(const QVector3D &direction)
62{
63 if (m_direction == direction)
64 return;
65
66 m_direction = direction;
67 m_directionNormalized = m_direction.normalized();
68 Q_EMIT directionChanged();
69 Q_EMIT update();
70}
71
72/*!
73 \qmlproperty vector3d PointRotator3D::pivotPoint
74
75 This property defines the pivot point for the rotation. Particles are rotated
76 around this point.
77
78 The default value is \c (0, 0, 0) (the center of particle system).
79*/
80QVector3D QQuick3DParticlePointRotator::pivotPoint() const
81{
82 return m_pivotPoint;
83}
84
85void QQuick3DParticlePointRotator::setPivotPoint(const QVector3D &point)
86{
87 if (m_pivotPoint == point)
88 return;
89
90 m_pivotPoint = point;
91 Q_EMIT pivotPointChanged();
92 Q_EMIT update();
93}
94
95void QQuick3DParticlePointRotator::prepareToAffect()
96{
97 m_rotationMatrix.setToIdentity();
98 m_rotationMatrix.translate(m_pivotPoint);
99}
100
101void QQuick3DParticlePointRotator::affectParticle(const QQuick3DParticleData &sd, QQuick3DParticleDataCurrent *d, float time)
102{
103 // Rotate based on the current position
104 // Note that this means order of PointRotator element compared to other affectors matters
105 Q_UNUSED(sd);
106 if (!qFuzzyIsNull(m_magnitude)) {
107 QMatrix4x4 rot = m_rotationMatrix;
108 rot.rotate(time * m_magnitude, m_directionNormalized);
109 rot.translate(-m_pivotPoint);
110 d->position = rot.map(d->position);
111 }
112}
113
114QT_END_NAMESPACE
Combined button and popup list for selecting options.