summaryrefslogtreecommitdiffstats
path: root/src/imports/particles/gravityaffector.h
blob: 0f555535a62adc3477dc6efc7c540a8eb1e4aab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef GRAVITYAFFECTOR_H
#define GRAVITYAFFECTOR_H
#include "particleaffector.h"

QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

QT_MODULE(Declarative)


class GravityAffector : public ParticleAffector
{
    Q_OBJECT
    Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
    Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
public:
    explicit GravityAffector(QSGItem *parent = 0);
    qreal acceleration() const
    {
        return m_acceleration;
    }

    qreal angle() const
    {
        return m_angle;
    }
protected:
    virtual bool affectParticle(ParticleData *d, qreal dt);
signals:

    void accelerationChanged(qreal arg);

    void angleChanged(qreal arg);

public slots:
void setAcceleration(qreal arg)
{
    if (m_acceleration != arg) {
        m_acceleration = arg;
        emit accelerationChanged(arg);
    }
}

void setAngle(qreal arg)
{
    if (m_angle != arg) {
        m_angle = arg;
        emit angleChanged(arg);
    }
}

private slots:
    void recalc();
private:
    qreal m_acceleration;
    qreal m_angle;

    qreal m_xAcc;
    qreal m_yAcc;
};

QT_END_NAMESPACE
QT_END_HEADER
#endif // GRAVITYAFFECTOR_H