aboutsummaryrefslogtreecommitdiffstats
path: root/src/particles/qquickcustomaffector.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2012-05-31 16:45:45 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-06 07:50:44 +0200
commit7b181d599f87f628f7e019aa451ff670fdb29d9f (patch)
tree50fbb8cc707217b3cbb8a8ee7485d2a1553f1d64 /src/particles/qquickcustomaffector.cpp
parent9fdf7be30568e2298cdc7a911cbbfbed0453d31f (diff)
Fix affected signal and docs
Signal wasn't being called in its primary usecase, which was to interact without altering the particles. Docs have been updated to clarify the usecase as well. This also updates the position properties of custom affector to more accurately specify if they caused changes. Change-Id: Ia411d9e81002443a56ed8bab9232f1aad49a4c5e Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'src/particles/qquickcustomaffector.cpp')
-rw-r--r--src/particles/qquickcustomaffector.cpp46
1 files changed, 34 insertions, 12 deletions
diff --git a/src/particles/qquickcustomaffector.cpp b/src/particles/qquickcustomaffector.cpp
index 788e2446b4..72b1536c54 100644
--- a/src/particles/qquickcustomaffector.cpp
+++ b/src/particles/qquickcustomaffector.cpp
@@ -108,7 +108,12 @@ bool QQuickCustomAffector::isAffectConnected()
void QQuickCustomAffector::affectSystem(qreal dt)
{
- if (!isAffectConnected()) {
+ //Acts a bit differently, just emits affected for everyone it might affect, when the only thing is connecting to affected(x,y)
+ bool justAffected = (m_acceleration == &m_nullVector
+ && m_speed == &m_nullVector
+ && m_position == &m_nullVector
+ && isAffectedConnected());
+ if (!isAffectConnected() && !justAffected) {
QQuickParticleAffector::affectSystem(dt);
return;
}
@@ -126,6 +131,15 @@ void QQuickCustomAffector::affectSystem(qreal dt)
if (toAffect.isEmpty())
return;
+ if (justAffected) {
+ foreach (QQuickParticleData* d, toAffect) {//Not postAffect to avoid saying the particle changed
+ if (m_onceOff)
+ m_onceOffed << qMakePair(d->group, d->index);
+ emit affected(d->curX(), d->curY());
+ }
+ return;
+ }
+
if (m_onceOff)
dt = 1.0;
@@ -167,24 +181,30 @@ bool QQuickCustomAffector::affectParticle(QQuickParticleData *d, qreal dt)
if (m_acceleration != &m_nullVector){
QPointF pos = m_acceleration->sample(curPos);
+ QPointF curAcc = QPointF(d->curAX(), d->curAY());
if (m_relative) {
pos *= dt;
- pos += QPointF(d->curAX(), d->curAY());
+ pos += curAcc;
+ }
+ if (pos != curAcc) {
+ d->setInstantaneousAX(pos.x());
+ d->setInstantaneousAY(pos.y());
+ changed = true;
}
- d->setInstantaneousAX(pos.x());
- d->setInstantaneousAY(pos.y());
- changed = true;
}
if (m_speed != &m_nullVector){
QPointF pos = m_speed->sample(curPos);
+ QPointF curVel = QPointF(d->curVX(), d->curVY());
if (m_relative) {
pos *= dt;
- pos += QPointF(d->curVX(), d->curVY());
+ pos += curVel;
+ }
+ if (pos != curVel) {
+ d->setInstantaneousVX(pos.x());
+ d->setInstantaneousVY(pos.y());
+ changed = true;
}
- d->setInstantaneousVX(pos.x());
- d->setInstantaneousVY(pos.y());
- changed = true;
}
if (m_position != &m_nullVector){
@@ -193,9 +213,11 @@ bool QQuickCustomAffector::affectParticle(QQuickParticleData *d, qreal dt)
pos *= dt;
pos += curPos;
}
- d->setInstantaneousX(pos.x());
- d->setInstantaneousY(pos.y());
- changed = true;
+ if (pos != curPos) {
+ d->setInstantaneousX(pos.x());
+ d->setInstantaneousY(pos.y());
+ changed = true;
+ }
}
return changed;