| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICK3DPARTICLEATTRACTOR_H |
| 5 | #define QQUICK3DPARTICLEATTRACTOR_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtQuick3DParticles/private/qquick3dparticleaffector_p.h> |
| 19 | #include <QtQuick3DParticles/private/qquick3dparticleshape_p.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | class Q_QUICK3DPARTICLES_EXPORT QQuick3DParticleAttractor : public QQuick3DParticleAffector |
| 24 | { |
| 25 | Q_OBJECT |
| 26 | Q_PROPERTY(QVector3D positionVariation READ positionVariation WRITE setPositionVariation NOTIFY positionVariationChanged) |
| 27 | Q_PROPERTY(QQuick3DParticleAbstractShape *shape READ shape WRITE setShape NOTIFY shapeChanged) |
| 28 | Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) |
| 29 | Q_PROPERTY(int durationVariation READ durationVariation WRITE setDurationVariation NOTIFY durationVariationChanged) |
| 30 | Q_PROPERTY(bool hideAtEnd READ hideAtEnd WRITE setHideAtEnd NOTIFY hideAtEndChanged) |
| 31 | Q_PROPERTY(bool useCachedPositions READ useCachedPositions WRITE setUseCachedPositions NOTIFY useCachedPositionsChanged) |
| 32 | Q_PROPERTY(int positionsAmount READ positionsAmount WRITE setPositionsAmount NOTIFY positionsAmountChanged) |
| 33 | QML_NAMED_ELEMENT(Attractor3D) |
| 34 | QML_ADDED_IN_VERSION(6, 2) |
| 35 | |
| 36 | public: |
| 37 | QQuick3DParticleAttractor(QQuick3DNode *parent = nullptr); |
| 38 | |
| 39 | QVector3D positionVariation() const; |
| 40 | QQuick3DParticleAbstractShape *shape() const; |
| 41 | int duration() const; |
| 42 | int durationVariation() const; |
| 43 | bool hideAtEnd() const; |
| 44 | bool useCachedPositions() const; |
| 45 | int positionsAmount() const; |
| 46 | |
| 47 | public Q_SLOTS: |
| 48 | void setPositionVariation(const QVector3D &positionVariation); |
| 49 | void setShape(QQuick3DParticleAbstractShape *shape); |
| 50 | void setDuration(int duration); |
| 51 | void setDurationVariation(int durationVariation); |
| 52 | void setHideAtEnd(bool hideAtEnd); |
| 53 | void setUseCachedPositions(bool useCachedPositions); |
| 54 | void setPositionsAmount(int positionsAmount); |
| 55 | |
| 56 | Q_SIGNALS: |
| 57 | void positionVariationChanged(); |
| 58 | void shapeChanged(); |
| 59 | void durationChanged(); |
| 60 | void durationVariationChanged(); |
| 61 | void hideAtEndChanged(); |
| 62 | void useCachedPositionsChanged(); |
| 63 | void positionsAmountChanged(); |
| 64 | |
| 65 | protected: |
| 66 | void prepareToAffect() override; |
| 67 | void affectParticle(const QQuick3DParticleData &sd, QQuick3DParticleDataCurrent *d, float time) override; |
| 68 | |
| 69 | private: |
| 70 | void updateShapePositions(); |
| 71 | |
| 72 | QQuick3DParticleAbstractShape *m_shape = nullptr; |
| 73 | QList<QVector3D> m_shapePositionList; |
| 74 | QVector3D m_centerPos; |
| 75 | QMatrix4x4 m_particleTransform; |
| 76 | bool m_shapeDirty = false; |
| 77 | int m_duration = -1; |
| 78 | int m_durationVariation = 0; |
| 79 | QVector3D m_positionVariation; |
| 80 | bool m_hideAtEnd = false; |
| 81 | bool m_useCachedPositions = true; |
| 82 | int m_positionsAmount = 0; |
| 83 | }; |
| 84 | |
| 85 | QT_END_NAMESPACE |
| 86 | |
| 87 | #endif // QQUICK3DPARTICLEATTRACTOR_H |
| 88 |
