From bf28a92e3165bc75a6487d0d258c641923e6ace5 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Fri, 16 Dec 2011 04:24:04 -0200 Subject: [PATCH] affectors attract --- modules/particle.otpa | 35 +++++++-------------- src/framework/graphics/particleaffector.cpp | 7 +++-- src/framework/graphics/particleaffector.h | 2 +- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/modules/particle.otpa b/modules/particle.otpa index 66ef7410..44ca84d3 100644 --- a/modules/particle.otpa +++ b/modules/particle.otpa @@ -1,36 +1,25 @@ ParticleSystem AttractionAffector - destination: 150 150 + destination: 200 200 + acceleration: 128 + velocity-reduction-percent: 10 Emitter - position: 100 100 - burstRate: 99 - burstCount: 1 + position: 200 200 + burstRate: 1 + burstCount: 128 - particle-duration: 999 + particle-duration: 2 particle-position-radius: 0 - particle-velocity: 32 - particle-velocity-angle: 0 + particle-velocity: 128 + particle-min-velocity-angle: 0 + particle-max-velocity-angle: 360 particle-acceleration: 0 - particle-size: 24 24 - particle-color: #ffff0044 + particle-size: 32 32 + particle-color: #33ff3344 particle-texture: circle2.png - - Emitter - position: 150 150 - burstRate: 99 - burstCount: 1 - - particle-duration: 999 - particle-position-radius: 0 - - particle-velocity: 0 - particle-acceleration: 0 - particle-size: 24 24 - particle-color: #ffff0044 - particle-texture: circle2.png diff --git a/src/framework/graphics/particleaffector.cpp b/src/framework/graphics/particleaffector.cpp index 460cb5a1..d04f25da 100644 --- a/src/framework/graphics/particleaffector.cpp +++ b/src/framework/graphics/particleaffector.cpp @@ -56,6 +56,8 @@ bool AttractionAffector::load(const OTMLNodePtr& node) m_destination = childNode->value(); else if(childNode->tag() == "acceleration") m_acceleration = childNode->value(); + else if(childNode->tag() == "velocity-reduction-percent") + m_reduction = childNode->value(); } return true; } @@ -70,6 +72,7 @@ void AttractionAffector::update(const ParticlePtr& particle, double elapsedTime) if(d.length() == 0) return; - PointF pVelocity = particle->getVelocity(); - particle->setVelocity(pVelocity + (d / d.length()) * m_acceleration * elapsedTime); + PointF pVelocity = particle->getVelocity() + (d / d.length() * m_acceleration * elapsedTime); + + particle->setVelocity(pVelocity - pVelocity * m_reduction/100.0 * elapsedTime); } diff --git a/src/framework/graphics/particleaffector.h b/src/framework/graphics/particleaffector.h index 284dc7df..6f0b5fbb 100644 --- a/src/framework/graphics/particleaffector.h +++ b/src/framework/graphics/particleaffector.h @@ -48,7 +48,7 @@ public: private: Point m_destination; - float m_acceleration; + float m_acceleration, m_reduction; }; #endif