summaryrefslogtreecommitdiffstats
path: root/src/imports/particles/gravityaffector.cpp
blob: c9fb670047d6562b1f89796a8394d742da95ac67 (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
#include "gravityaffector.h"
#include <cmath>
QT_BEGIN_NAMESPACE
const qreal CONV = 0.017453292520444443;
GravityAffector::GravityAffector(QSGItem *parent) :
    ParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0)
{
    connect(this, SIGNAL(accelerationChanged(qreal)),
            this, SLOT(recalc()));
    connect(this, SIGNAL(angleChanged(qreal)),
            this, SLOT(recalc()));
    recalc();
}

void GravityAffector::recalc()
{
    qreal theta = m_angle * CONV;
    m_xAcc = m_acceleration * cos(theta);
    m_yAcc = m_acceleration * sin(theta);
}

bool GravityAffector::affectParticle(ParticleData *d, qreal dt)
{
    Q_UNUSED(dt);
    bool changed = false;
    if(d->pv.ax != m_xAcc){
        d->setInstantaneousAX(m_xAcc);
        changed = true;
    }
    if(d->pv.ay != m_yAcc){
        d->setInstantaneousAY(m_yAcc);
        changed = true;
    }
    return changed;
}
QT_END_NAMESPACE