some changes to particles

master
Henrique Santiago 13 years ago
parent ad38dad227
commit 26eb3b42a6

@ -1,14 +1,14 @@
ParticleSystem ParticleSystem
GoToPointAffector AttractionAffector
destination: 150 150 destination: 150 150
Emitter Emitter
position: 100 100 position: 100 100
burstRate: 2 burstRate: 99
burstCount: 1 burstCount: 1
particle-duration: 1 particle-duration: 999
particle-position-radius: 0 particle-position-radius: 0
particle-velocity: 32 particle-velocity: 32
@ -20,3 +20,17 @@ ParticleSystem
particle-color: #ffff0044 particle-color: #ffff0044
particle-texture: circle2.png 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

@ -24,43 +24,52 @@
#include "particleaffector.h" #include "particleaffector.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>
void Gravity270Affector::update(const ParticlePtr& particle, double elapsedTime) #define DEG_TO_RAD (acos(-1)/180.0)
{
// earth gravity is 9.8 m/s². -> in tibia, 32 pixels are equal to 1 meter -> 32 pixels/m -> 9.8 * 32 is gravity constant
const float gravity = 9.8 * 32;
PointF velocity = particle->getVelocity(); bool GravityAffector::load(const OTMLNodePtr& node)
velocity += PointF(0, -gravity * elapsedTime); {
m_angle = 270 * DEG_TO_RAD;
m_gravity = 9.8;
particle->setVelocity(velocity); for(const OTMLNodePtr& childNode : node->children()) {
if(childNode->tag() == "angle")
m_angle = childNode->value<float>() * DEG_TO_RAD;
else if(childNode->tag() == "gravity")
m_gravity = childNode->value<float>();
}
return true;
} }
void Gravity315Affector::update(const ParticlePtr& particle, double elapsedTime) void GravityAffector::update(const ParticlePtr& particle, double elapsedTime)
{ {
// earth gravity is 9.8 m/s². -> in tibia, 32 pixels are equal to 1 meter -> 32 pixels/m -> 9.8 * 32 is gravity constant
const float gravity = 9.8 * 32;
PointF velocity = particle->getVelocity(); PointF velocity = particle->getVelocity();
velocity += PointF(gravity * elapsedTime * cos(7 * Fw::pi / 4), gravity * elapsedTime * sin(7 * Fw::pi / 4)); velocity += PointF(m_gravity * elapsedTime * cos(m_angle), m_gravity * elapsedTime * sin(m_angle));
particle->setVelocity(velocity); particle->setVelocity(velocity);
} }
bool GoToPointAffector::load(const OTMLNodePtr& node) bool AttractionAffector::load(const OTMLNodePtr& node)
{ {
m_acceleration = 32;
for(const OTMLNodePtr& childNode : node->children()) { for(const OTMLNodePtr& childNode : node->children()) {
if(childNode->tag() == "destination") if(childNode->tag() == "destination")
m_destination = childNode->value<Point>(); m_destination = childNode->value<Point>();
else if(childNode->tag() == "rotate-speed-percent") else if(childNode->tag() == "acceleration")
m_rotateSpeedPercent = childNode->value<float>(); m_acceleration = childNode->value<float>();
} }
return true; return true;
} }
void GoToPointAffector::update(const ParticlePtr& particle, double elapsedTime) void AttractionAffector::update(const ParticlePtr& particle, double elapsedTime)
{ {
// must change velocity angle, keeping modulus. // must change velocity angle, keeping modulus.
PointF pPosition = particle->getPosition();
PointF d = PointF(m_destination.x - pPosition.x, pPosition.y - m_destination.y);
if(d.length() == 0)
return;
PointF pVelocity = particle->getVelocity();
particle->setVelocity(pVelocity + (d / d.length()) * m_acceleration * elapsedTime);
} }

@ -32,24 +32,23 @@ public:
virtual void update(const ParticlePtr&, double) {} virtual void update(const ParticlePtr&, double) {}
}; };
class Gravity270Affector : public ParticleAffector { class GravityAffector : public ParticleAffector {
public: public:
bool load(const OTMLNodePtr& node);
void update(const ParticlePtr& particle, double elapsedTime); void update(const ParticlePtr& particle, double elapsedTime);
};
class Gravity315Affector : public ParticleAffector { private:
public: float m_angle, m_gravity;
void update(const ParticlePtr& particle, double elapsedTime);
}; };
class GoToPointAffector : public ParticleAffector { class AttractionAffector : public ParticleAffector {
public: public:
bool load(const OTMLNodePtr& node); bool load(const OTMLNodePtr& node);
void update(const ParticlePtr& particle, double elapsedTime); void update(const ParticlePtr& particle, double elapsedTime);
private: private:
Point m_destination; Point m_destination;
float m_rotateSpeedPercent; float m_acceleration;
}; };
#endif #endif

@ -41,12 +41,10 @@ bool ParticleSystem::load(const OTMLNodePtr& node)
else if(childNode->tag().find("Affector") != std::string::npos) { else if(childNode->tag().find("Affector") != std::string::npos) {
ParticleAffectorPtr affector; ParticleAffectorPtr affector;
if(childNode->tag() == "Gravity270Affector") if(childNode->tag() == "GravityAffector")
affector = ParticleAffectorPtr(new Gravity270Affector); affector = ParticleAffectorPtr(new GravityAffector);
else if(childNode->tag() == "Gravity315Affector") else if(childNode->tag() == "AttractionAffector")
affector = ParticleAffectorPtr(new Gravity315Affector); affector = ParticleAffectorPtr(new AttractionAffector);
else if(childNode->tag() == "GoToPointAffector")
affector = ParticleAffectorPtr(new GoToPointAffector);
if(affector) { if(affector) {
affector->load(childNode); affector->load(childNode);

@ -48,7 +48,7 @@ public:
TPoint<T>& operator-=(const TPoint<T>& other) { x-=other.x; y-=other.y; return *this; } TPoint<T>& operator-=(const TPoint<T>& other) { x-=other.x; y-=other.y; return *this; }
TPoint<T> operator*(const TPoint<T>& other) const { return TPoint<T>(x * other.x, y * other.y); } TPoint<T> operator*(const TPoint<T>& other) const { return TPoint<T>(x * other.x, y * other.y); }
TPoint<T>& operator*=(const TPoint<T>& other) { x*=other.x; y*=other.y; return *this; } TPoint<T>& operator*=(const TPoint<T>& other) { x*=other.x; y*=other.y; return *this; }
TPoint<T> operator*(const T v) const { return TPoint<T>(x * v, y * v); } TPoint<T> operator*(const T v) const { return TPoint<T>(x*v, y*v); }
TPoint<T>& operator*=(const T v) { x*=v; y*=v; return *this; } TPoint<T>& operator*=(const T v) { x*=v; y*=v; return *this; }
TPoint<T> operator/(const TPoint<T>& other) const { return TPoint<T>(x/other.x, y/other.y); } TPoint<T> operator/(const TPoint<T>& other) const { return TPoint<T>(x/other.x, y/other.y); }
TPoint<T>& operator/=(const TPoint<T>& other) { x/=other.x; y/=other.y; return *this; } TPoint<T>& operator/=(const TPoint<T>& other) { x/=other.x; y/=other.y; return *this; }

Loading…
Cancel
Save