some changes to particles
This commit is contained in:
parent
ad38dad227
commit
26eb3b42a6
|
@ -1,14 +1,14 @@
|
|||
ParticleSystem
|
||||
|
||||
GoToPointAffector
|
||||
|
||||
AttractionAffector
|
||||
destination: 150 150
|
||||
|
||||
Emitter
|
||||
position: 100 100
|
||||
burstRate: 2
|
||||
burstRate: 99
|
||||
burstCount: 1
|
||||
|
||||
particle-duration: 1
|
||||
particle-duration: 999
|
||||
particle-position-radius: 0
|
||||
|
||||
particle-velocity: 32
|
||||
|
@ -20,3 +20,17 @@ ParticleSystem
|
|||
particle-color: #ffff0044
|
||||
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 <framework/core/clock.h>
|
||||
|
||||
void Gravity270Affector::update(const ParticlePtr& particle, double elapsedTime)
|
||||
#define DEG_TO_RAD (acos(-1)/180.0)
|
||||
|
||||
bool GravityAffector::load(const OTMLNodePtr& node)
|
||||
{
|
||||
// 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;
|
||||
m_angle = 270 * DEG_TO_RAD;
|
||||
m_gravity = 9.8;
|
||||
|
||||
PointF velocity = particle->getVelocity();
|
||||
velocity += PointF(0, -gravity * elapsedTime);
|
||||
|
||||
particle->setVelocity(velocity);
|
||||
}
|
||||
|
||||
void Gravity315Affector::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();
|
||||
velocity += PointF(gravity * elapsedTime * cos(7 * Fw::pi / 4), gravity * elapsedTime * sin(7 * Fw::pi / 4));
|
||||
|
||||
particle->setVelocity(velocity);
|
||||
}
|
||||
|
||||
bool GoToPointAffector::load(const OTMLNodePtr& node)
|
||||
{
|
||||
for(const OTMLNodePtr& childNode : node->children()) {
|
||||
if(childNode->tag() == "destination")
|
||||
m_destination = childNode->value<Point>();
|
||||
else if(childNode->tag() == "rotate-speed-percent")
|
||||
m_rotateSpeedPercent = childNode->value<float>();
|
||||
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 GoToPointAffector::update(const ParticlePtr& particle, double elapsedTime)
|
||||
void GravityAffector::update(const ParticlePtr& particle, double elapsedTime)
|
||||
{
|
||||
PointF velocity = particle->getVelocity();
|
||||
velocity += PointF(m_gravity * elapsedTime * cos(m_angle), m_gravity * elapsedTime * sin(m_angle));
|
||||
particle->setVelocity(velocity);
|
||||
}
|
||||
|
||||
bool AttractionAffector::load(const OTMLNodePtr& node)
|
||||
{
|
||||
m_acceleration = 32;
|
||||
|
||||
for(const OTMLNodePtr& childNode : node->children()) {
|
||||
if(childNode->tag() == "destination")
|
||||
m_destination = childNode->value<Point>();
|
||||
else if(childNode->tag() == "acceleration")
|
||||
m_acceleration = childNode->value<float>();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AttractionAffector::update(const ParticlePtr& particle, double elapsedTime)
|
||||
{
|
||||
// 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) {}
|
||||
};
|
||||
|
||||
class Gravity270Affector : public ParticleAffector {
|
||||
class GravityAffector : public ParticleAffector {
|
||||
public:
|
||||
bool load(const OTMLNodePtr& node);
|
||||
void update(const ParticlePtr& particle, double elapsedTime);
|
||||
|
||||
private:
|
||||
float m_angle, m_gravity;
|
||||
};
|
||||
|
||||
class Gravity315Affector : public ParticleAffector {
|
||||
public:
|
||||
void update(const ParticlePtr& particle, double elapsedTime);
|
||||
};
|
||||
|
||||
class GoToPointAffector : public ParticleAffector {
|
||||
class AttractionAffector : public ParticleAffector {
|
||||
public:
|
||||
bool load(const OTMLNodePtr& node);
|
||||
void update(const ParticlePtr& particle, double elapsedTime);
|
||||
|
||||
private:
|
||||
Point m_destination;
|
||||
float m_rotateSpeedPercent;
|
||||
float m_acceleration;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,12 +41,10 @@ bool ParticleSystem::load(const OTMLNodePtr& node)
|
|||
else if(childNode->tag().find("Affector") != std::string::npos) {
|
||||
ParticleAffectorPtr affector;
|
||||
|
||||
if(childNode->tag() == "Gravity270Affector")
|
||||
affector = ParticleAffectorPtr(new Gravity270Affector);
|
||||
else if(childNode->tag() == "Gravity315Affector")
|
||||
affector = ParticleAffectorPtr(new Gravity315Affector);
|
||||
else if(childNode->tag() == "GoToPointAffector")
|
||||
affector = ParticleAffectorPtr(new GoToPointAffector);
|
||||
if(childNode->tag() == "GravityAffector")
|
||||
affector = ParticleAffectorPtr(new GravityAffector);
|
||||
else if(childNode->tag() == "AttractionAffector")
|
||||
affector = ParticleAffectorPtr(new AttractionAffector);
|
||||
|
||||
if(affector) {
|
||||
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) 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 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 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; }
|
||||
|
|
Loading…
Reference in New Issue