affectors attract

This commit is contained in:
Henrique Santiago
2011-12-16 04:24:04 -02:00
parent 26eb3b42a6
commit bf28a92e31
3 changed files with 18 additions and 26 deletions

View File

@@ -56,6 +56,8 @@ bool AttractionAffector::load(const OTMLNodePtr& node)
m_destination = childNode->value<Point>();
else if(childNode->tag() == "acceleration")
m_acceleration = childNode->value<float>();
else if(childNode->tag() == "velocity-reduction-percent")
m_reduction = childNode->value<float>();
}
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);
}

View File

@@ -48,7 +48,7 @@ public:
private:
Point m_destination;
float m_acceleration;
float m_acceleration, m_reduction;
};
#endif