diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2011-08-30 19:25:11 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-30 11:37:36 +0200 |
commit | a7923fa19f81ea145f3ce97123567970e88d9df3 (patch) | |
tree | 8377d18a5be9d7b0bd97ce0a90d43e0a579ef2e1 /src | |
parent | 1025fa7c5247405a3a7289d928addb740afbf95b (diff) |
Add more proportionality modes to PointAttractor
Inverse proportionality is now properly named, direct proportionality
is added, and constant as well (in case they all just draw towards a
point).
Change-Id: I6187c0df908fdf20e2bb0b0a1007ebcc38dd3ac2
Reviewed-on: http://codereview.qt.nokia.com/3868
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/particles/qsgpointattractor.cpp | 21 | ||||
-rw-r--r-- | src/declarative/particles/qsgpointattractor_p.h | 5 |
2 files changed, 19 insertions, 7 deletions
diff --git a/src/declarative/particles/qsgpointattractor.cpp b/src/declarative/particles/qsgpointattractor.cpp index 55b6cb67b7..21eaeaac12 100644 --- a/src/declarative/particles/qsgpointattractor.cpp +++ b/src/declarative/particles/qsgpointattractor.cpp @@ -65,19 +65,28 @@ bool QSGPointAttractorAffector::affectParticle(QSGParticleData *d, qreal dt) { if (m_strength == 0.0) return false; - qreal dx = m_y - d->curX(); - qreal dy = m_x - d->curY(); + qreal dx = m_x - d->curX(); + qreal dy = m_y - d->curY(); qreal r = sqrt((dx*dx) + (dy*dy)); qreal theta = atan2(dy,dx); qreal ds = 0; switch (m_proportionalToDistance){ + case InverseQuadratic: + ds = (m_strength / qMax<qreal>(1.,r*r)); + break; + case InverseLinear: + ds = (m_strength / qMax<qreal>(1.,r)); + break; case Quadratic: - ds = (m_strength / qMax<qreal>(1.,r*r)) * dt; + ds = (m_strength * qMax<qreal>(1.,r*r)); break; - case Linear://also default - default: - ds = (m_strength / qMax<qreal>(1.,r)) * dt; + case Linear: + ds = (m_strength * qMax<qreal>(1.,r)); + break; + default: //also Constant + ds = m_strength; } + ds *= dt; dx = ds * cos(theta); dy = ds * sin(theta); qreal vx,vy; diff --git a/src/declarative/particles/qsgpointattractor_p.h b/src/declarative/particles/qsgpointattractor_p.h index 95716483ed..298965a5c9 100644 --- a/src/declarative/particles/qsgpointattractor_p.h +++ b/src/declarative/particles/qsgpointattractor_p.h @@ -64,8 +64,11 @@ class QSGPointAttractorAffector : public QSGParticleAffector public: enum Proportion{ + Constant, Linear, - Quadratic + Quadratic, + InverseLinear, + InverseQuadratic }; enum PhysicsAffects { |