Add more proportionality modes to PointAttractor
authorAlan Alpert <alan.alpert@nokia.com>
Tue, 30 Aug 2011 09:25:11 +0000 (19:25 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 30 Aug 2011 09:37:36 +0000 (11:37 +0200)
Inverse proportionality is now properly named, direct proportionality
is added, and constant as well (in case they all just draw towards a
point).

Change-Id: I6187c0df908fdf20e2bb0b0a1007ebcc38dd3ac2
Reviewed-on: http://codereview.qt.nokia.com/3868
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>

examples/declarative/particles/asteroid/blackhole.qml
examples/declarative/particles/spaceexplorer/spaceexplorer.qml
src/declarative/particles/qsgpointattractor.cpp
src/declarative/particles/qsgpointattractor_p.h

index 4a7ce02..441f4c3 100644 (file)
@@ -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
index 1bb3cda..727d711 100644 (file)
@@ -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{
index 55b6cb6..21eaeaa 100644 (file)
@@ -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;
index 9571648..298965a 100644 (file)
@@ -64,8 +64,11 @@ class QSGPointAttractorAffector : public QSGParticleAffector
 
 public:
     enum Proportion{
+        Constant,
         Linear,
-        Quadratic
+        Quadratic,
+        InverseLinear,
+        InverseQuadratic
     };
 
     enum PhysicsAffects {