diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2011-06-15 18:52:26 +1000 |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2011-06-15 18:52:26 +1000 |
commit | fab0da3853efc5ef2f1a507f7d054b8a0dd3b9ac (patch) | |
tree | 56eeb5e2175c0abed7afb47821de0940ca7b2e52 /src/declarative/particles/qsgturbulence.cpp | |
parent | 7b22f02961a97c0fa07127ea3ff26b8435a617b8 (diff) |
Rewrite particle system to cope with changing particle counts
And might do it again...
Caught up in this massive change were the following smaller ones:
-Some custom particle examples
-delegate property on ItemParticle and an example with it
Diffstat (limited to 'src/declarative/particles/qsgturbulence.cpp')
-rw-r--r-- | src/declarative/particles/qsgturbulence.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/declarative/particles/qsgturbulence.cpp b/src/declarative/particles/qsgturbulence.cpp index 476db9c4b0..bb46b99f0d 100644 --- a/src/declarative/particles/qsgturbulence.cpp +++ b/src/declarative/particles/qsgturbulence.cpp @@ -128,30 +128,34 @@ void QSGTurbulenceAffector::affectSystem(qreal dt) m_lastT += period; } - foreach(QSGParticleData *d, m_system->m_data){ - if(!d || !activeGroup(d->group)) + foreach(QSGParticleGroupData *gd, m_system->m_groupData){ + if(!activeGroup(m_system->m_groupData.key(gd)))//TODO: Surely this can be done better return; - qreal fx = 0.0; - qreal fy = 0.0; - QPointF pos = QPointF(d->curX() - x(), d->curY() - y());//TODO: Offset - QPointF nodePos = QPointF(pos.x() / m_spacing.x(), pos.y() / m_spacing.y()); - QSet<QPair<int, int> > nodes; - nodes << qMakePair((int)ceil(nodePos.x()), (int)ceil(nodePos.y())); - nodes << qMakePair((int)ceil(nodePos.x()), (int)floor(nodePos.y())); - nodes << qMakePair((int)floor(nodePos.x()), (int)ceil(nodePos.y())); - nodes << qMakePair((int)floor(nodePos.x()), (int)floor(nodePos.y())); - typedef QPair<int, int> intPair; - foreach(const intPair &p, nodes){ - if(!QRect(0,0,m_gridSize-1,m_gridSize-1).contains(QPoint(p.first, p.second))) - continue; - qreal dist = magnitude(pos.x() - p.first*m_spacing.x(), pos.y() - p.second*m_spacing.y());//TODO: Mathematically valid - fx += m_field[p.first][p.second].x() * ((m_magSum - dist)/m_magSum);//Proportionally weight nodes - fy += m_field[p.first][p.second].y() * ((m_magSum - dist)/m_magSum); - } - if(fx || fy){ - d->setInstantaneousSX(d->curSX()+ fx * dt); - d->setInstantaneousSY(d->curSY()+ fy * dt); - m_system->m_needsReset << d; + foreach(QSGParticleData *d, gd->data){ + if(!d || !activeGroup(d->group)) + return; + qreal fx = 0.0; + qreal fy = 0.0; + QPointF pos = QPointF(d->curX() - x(), d->curY() - y());//TODO: Offset + QPointF nodePos = QPointF(pos.x() / m_spacing.x(), pos.y() / m_spacing.y()); + QSet<QPair<int, int> > nodes; + nodes << qMakePair((int)ceil(nodePos.x()), (int)ceil(nodePos.y())); + nodes << qMakePair((int)ceil(nodePos.x()), (int)floor(nodePos.y())); + nodes << qMakePair((int)floor(nodePos.x()), (int)ceil(nodePos.y())); + nodes << qMakePair((int)floor(nodePos.x()), (int)floor(nodePos.y())); + typedef QPair<int, int> intPair; + foreach(const intPair &p, nodes){ + if(!QRect(0,0,m_gridSize-1,m_gridSize-1).contains(QPoint(p.first, p.second))) + continue; + qreal dist = magnitude(pos.x() - p.first*m_spacing.x(), pos.y() - p.second*m_spacing.y());//TODO: Mathematically valid + fx += m_field[p.first][p.second].x() * ((m_magSum - dist)/m_magSum);//Proportionally weight nodes + fy += m_field[p.first][p.second].y() * ((m_magSum - dist)/m_magSum); + } + if(fx || fy){ + d->setInstantaneousSX(d->curSX()+ fx * dt); + d->setInstantaneousSY(d->curSY()+ fy * dt); + m_system->m_needsReset << d; + } } } } |