aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/particles/qsgturbulence.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-07-04 18:15:28 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-06 10:09:09 +0200
commit29c4b643272a43022081cce063394bac823ab529 (patch)
tree10e4fe15bdf68dec90edac0d67b949a92d9204d5 /src/declarative/particles/qsgturbulence.cpp
parent87822d24df32311a50dc87ded55ad4d17e8226f0 (diff)
Squashed Particle System Stateful Rewrite
Add TargetAffector Fix for ParticlePainter offsets Adds a particleStates property to ParticleSystem Augment SpriteGoal to change system states as well Also add 'collidingParticles' list to affector. Particle Stochastic States Now actually working, and you can put emitters, affectors and painters inside their targeted state. Fireworks example uses states instead of delegates. Replaced the delegate example with a text thing. The examples launcher now also contains all the custom examples. Adds CumulativeDirection and working null Affector (for affected signal). Add spaces after all flow control keywords. Change-Id: I77b7e3044a9800dbfff6db833914d63127602cf5 Reviewed-on: http://codereview.qt.nokia.com/968 Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Diffstat (limited to 'src/declarative/particles/qsgturbulence.cpp')
-rw-r--r--src/declarative/particles/qsgturbulence.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/declarative/particles/qsgturbulence.cpp b/src/declarative/particles/qsgturbulence.cpp
index bb46b99f0d..941cf16c77 100644
--- a/src/declarative/particles/qsgturbulence.cpp
+++ b/src/declarative/particles/qsgturbulence.cpp
@@ -56,7 +56,7 @@ QSGTurbulenceAffector::QSGTurbulenceAffector(QSGItem *parent) :
QSGTurbulenceAffector::~QSGTurbulenceAffector()
{
if (m_field) {
- for(int i=0; i<m_gridSize; i++)
+ for (int i=0; i<m_gridSize; i++)
free(m_field[i]);
free(m_field);
}
@@ -70,8 +70,8 @@ static qreal magnitude(qreal x, qreal y)
void QSGTurbulenceAffector::setSize(int arg)
{
if (m_gridSize != arg) {
- if(m_field){ //deallocate and then reallocate grid
- for(int i=0; i<m_gridSize; i++)
+ if (m_field){ //deallocate and then reallocate grid
+ for (int i=0; i<m_gridSize; i++)
free(m_field[i]);
free(m_field);
m_system = 0;
@@ -83,14 +83,14 @@ void QSGTurbulenceAffector::setSize(int arg)
void QSGTurbulenceAffector::ensureInit()
{
- if(m_inited)
+ if (m_inited)
return;
m_inited = true;
m_field = (QPointF**)malloc(m_gridSize * sizeof(QPointF*));
- for(int i=0; i<m_gridSize; i++)
+ for (int i=0; i<m_gridSize; i++)
m_field[i] = (QPointF*)malloc(m_gridSize * sizeof(QPointF));
- for(int i=0; i<m_gridSize; i++)
- for(int j=0; j<m_gridSize; j++)
+ for (int i=0; i<m_gridSize; i++)
+ for (int j=0; j<m_gridSize; j++)
m_field[i][j] = QPointF();
m_spacing = QPointF(width()/m_gridSize, height()/m_gridSize);
m_magSum = magnitude(m_spacing.x(), m_spacing.y())*2;
@@ -101,11 +101,11 @@ void QSGTurbulenceAffector::mapUpdate()
QPoint pos(rand() % m_gridSize, rand() % m_gridSize);
QPointF vector(m_strength - (((qreal)rand() / RAND_MAX) * m_strength*2),
m_strength - (((qreal)rand() / RAND_MAX) * m_strength*2));
- for(int i = 0; i < m_gridSize; i++){
- for(int j = 0; j < m_gridSize; j++){
+ for (int i = 0; i < m_gridSize; i++){
+ for (int j = 0; j < m_gridSize; j++){
qreal dist = magnitude(i-pos.x(), j-pos.y());
m_field[i][j] += vector/(dist + 1);
- if(magnitude(m_field[i][j].x(), m_field[i][j].y()) > m_strength){
+ if (magnitude(m_field[i][j].x(), m_field[i][j].y()) > m_strength){
//Speed limit
qreal theta = atan2(m_field[i][j].y(), m_field[i][j].x());
m_field[i][j].setX(m_strength * cos(theta));
@@ -118,21 +118,21 @@ void QSGTurbulenceAffector::mapUpdate()
void QSGTurbulenceAffector::affectSystem(qreal dt)
{
- if(!m_system || !m_active)
+ if (!m_system || !m_active)
return;
ensureInit();
qreal period = 1.0/m_frequency;
qreal time = m_system->m_timeInt / 1000.0;
- while( m_lastT < time ){
+ while ( m_lastT < time ){
mapUpdate();
m_lastT += period;
}
- foreach(QSGParticleGroupData *gd, m_system->m_groupData){
- if(!activeGroup(m_system->m_groupData.key(gd)))//TODO: Surely this can be done better
+ foreach (QSGParticleGroupData *gd, m_system->m_groupData){
+ if (!activeGroup(m_system->m_groupData.key(gd)))//TODO: Surely this can be done better
return;
- foreach(QSGParticleData *d, gd->data){
- if(!d || !activeGroup(d->group))
+ foreach (QSGParticleData *d, gd->data){
+ if (!d || !activeGroup(d->group))
return;
qreal fx = 0.0;
qreal fy = 0.0;
@@ -144,14 +144,14 @@ void QSGTurbulenceAffector::affectSystem(qreal dt)
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)))
+ 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){
+ if (fx || fy){
d->setInstantaneousSX(d->curSX()+ fx * dt);
d->setInstantaneousSY(d->curSY()+ fy * dt);
m_system->m_needsReset << d;