summaryrefslogtreecommitdiff
path: root/src/declarative/particles/qquickgravity.cpp
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2011-11-14 10:35:51 +1000
committerCharles Yin <charles.yin@nokia.com>2011-11-14 10:35:51 +1000
commitfc54db69809a16f613f65a2761fab55d5911b02c (patch)
treea00d9284eb13f81f5b195f8a4c6cfee03edb4f17 /src/declarative/particles/qquickgravity.cpp
parent35275892ca8a7046451b8e943985dd779fee4794 (diff)
parent2557ff5a940242b398dee65c3c79cec088164e32 (diff)
downloadqtdeclarative-fc54db69809a16f613f65a2761fab55d5911b02c.tar.gz
Merge branch 'master' into animation-refactor
Conflicts: tools/qmlviewer/qdeclarativetester.cpp tools/qmlviewer/qmlruntime.cpp Change-Id: I48f0eb02df27e4b524f45927939b4c257452b0aa
Diffstat (limited to 'src/declarative/particles/qquickgravity.cpp')
-rw-r--r--src/declarative/particles/qquickgravity.cpp49
1 files changed, 21 insertions, 28 deletions
diff --git a/src/declarative/particles/qquickgravity.cpp b/src/declarative/particles/qquickgravity.cpp
index 010fcb8d44..fd2fb92a53 100644
--- a/src/declarative/particles/qquickgravity.cpp
+++ b/src/declarative/particles/qquickgravity.cpp
@@ -47,11 +47,11 @@ const qreal CONV = 0.017453292520444443;
\qmlclass Gravity QQuickGravityAffector
\inqmlmodule QtQuick.Particles 2
\inherits Affector
- \brief The Gravity element allows you to set a constant accleration in an angle
+ \brief The Gravity element allows you to set an accleration in an angle
- This element will set the acceleration of all affected particles to a vector of
- the specified magnitude in the specified angle. If the angle or acceleration is
- not varying, it is more efficient to set the specified acceleration on the Emitter.
+ This element will accelerate all affected particles to a vector of
+ the specified magnitude in the specified angle. If the angle and acceleration do
+ not vary, it is more efficient to set the specified acceleration on the Emitter.
This element models the gravity of a massive object whose center of
gravity is far away (and thus the gravitational pull is effectively constant
@@ -60,45 +60,38 @@ const qreal CONV = 0.017453292520444443;
*/
/*!
- \qmlproperty real QtQuick.Particles2::Gravity::acceleration
+ \qmlproperty real QtQuick.Particles2::Gravity::magnitude
Pixels per second that objects will be accelerated by.
*/
/*!
+ \qmlproperty real QtQuick.Particles2::Gravity::acceleration
+
+ Name changed to magnitude, will be removed soon.
+*/
+/*!
\qmlproperty real QtQuick.Particles2::Gravity::angle
Angle of acceleration.
*/
QQuickGravityAffector::QQuickGravityAffector(QQuickItem *parent) :
- QQuickParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0)
+ QQuickParticleAffector(parent), m_magnitude(-10), m_angle(90), m_needRecalc(true)
{
- connect(this, SIGNAL(accelerationChanged(qreal)),
- this, SLOT(recalc()));
- connect(this, SIGNAL(angleChanged(qreal)),
- this, SLOT(recalc()));
- recalc();
-}
-
-void QQuickGravityAffector::recalc()
-{
- qreal theta = m_angle * CONV;
- m_xAcc = m_acceleration * cos(theta);
- m_yAcc = m_acceleration * sin(theta);
}
bool QQuickGravityAffector::affectParticle(QQuickParticleData *d, qreal dt)
{
- Q_UNUSED(dt);
- bool changed = false;
- if (d->ax != m_xAcc){
- d->setInstantaneousAX(m_xAcc);
- changed = true;
+ if (!m_magnitude)
+ return false;
+ if (m_needRecalc) {
+ m_needRecalc = false;
+ m_dx = m_magnitude * cos(m_angle * CONV);
+ m_dy = m_magnitude * sin(m_angle * CONV);
}
- if (d->ay != m_yAcc){
- d->setInstantaneousAY(m_yAcc);
- changed = true;
- }
- return changed;
+
+ d->setInstantaneousVX(d->curVX() + m_dx*dt);
+ d->setInstantaneousVY(d->curVY() + m_dy*dt);
+ return true;
}
QT_END_NAMESPACE