aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/declarative/particles/asteroid/blackhole.qml2
-rw-r--r--examples/declarative/particles/spaceexplorer/spaceexplorer.qml6
-rw-r--r--src/declarative/particles/qsgpointattractor.cpp21
-rw-r--r--src/declarative/particles/qsgpointattractor_p.h5
4 files changed, 23 insertions, 11 deletions
diff --git a/examples/declarative/particles/asteroid/blackhole.qml b/examples/declarative/particles/asteroid/blackhole.qml
index 4a7ce02538..441f4c38d6 100644
--- a/examples/declarative/particles/asteroid/blackhole.qml
+++ b/examples/declarative/particles/asteroid/blackhole.qml
@@ -149,7 +149,7 @@ Rectangle{
id: gs; x: root.width/2; y: root.height/2; strength: 4000000;
system: particles
physics: PointAttractor.Acceleration
- proportionalToDistance: PointAttractor.Quadratic
+ proportionalToDistance: PointAttractor.InverseQuadratic
}
Kill{
system: particles
diff --git a/examples/declarative/particles/spaceexplorer/spaceexplorer.qml b/examples/declarative/particles/spaceexplorer/spaceexplorer.qml
index 1bb3cdae02..727d711053 100644
--- a/examples/declarative/particles/spaceexplorer/spaceexplorer.qml
+++ b/examples/declarative/particles/spaceexplorer/spaceexplorer.qml
@@ -276,7 +276,7 @@ Rectangle{
}
PointAttractor{
id: gs1; x: vorteX; y: vorteY; strength: 800000;
- proportionalToDistance: PointAttractor.Quadratic;
+ proportionalToDistance: PointAttractor.InverseQuadratic;
system: foreground
}
Kill{
@@ -289,7 +289,7 @@ Rectangle{
PointAttractor{
id: gs2; x: vorteX2; y: vorteY2; strength: 800000;
- proportionalToDistance: PointAttractor.Quadratic;
+ proportionalToDistance: PointAttractor.InverseQuadratic;
system: foreground
}
Kill{
@@ -302,7 +302,7 @@ Rectangle{
PointAttractor{
id: gs3; x: vorteX3; y: vorteY3; strength: 800000;
- proportionalToDistance: PointAttractor.Quadratic;
+ proportionalToDistance: PointAttractor.InverseQuadratic;
system: foreground
}
Kill{
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 {