particles start final size

This commit is contained in:
Henrique Santiago 2011-12-18 00:54:35 -02:00
parent 6973e1639a
commit e3e6770957
5 changed files with 23 additions and 19 deletions

View File

@ -20,7 +20,8 @@ ParticleSystem
particle-velocity: 32 particle-velocity: 32
particle-velocity-angle: 0 particle-velocity-angle: 0
particle-acceleration: 0 particle-acceleration: 0
particle-size: 32 32 particle-start-size: 4 4
particle-final-size: 48 48
particle-colors: #00ff00ff #ff0000ff #0000ffff #00ff00ff #00ff0000 particle-colors: #00ff00ff #ff0000ff #0000ffff #00ff00ff #00ff0000
particle-colors-stops: 3 6 9 12 particle-colors-stops: 3 6 9 12
particle-texture: circle2.png particle-texture: circle2.png

View File

@ -24,14 +24,14 @@
#include "graphics.h" #include "graphics.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>
Particle::Particle(const Point& pos, const Size& size, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture) Particle::Particle(const Point& pos, const Size& startSize, const Size& finalSize, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture)
{ {
m_colors = colors; m_colors = colors;
m_colorsStops = colorsStops; m_colorsStops = colorsStops;
m_rect = Rect(pos, size);
m_position = PointF(pos.x, pos.y); m_position = PointF(pos.x, pos.y);
m_size = size; m_startSize = startSize;
m_finalSize = finalSize;
m_velocity = velocity; m_velocity = velocity;
m_acceleration = acceleration; m_acceleration = acceleration;
@ -65,6 +65,9 @@ void Particle::update(double elapsedTime)
updateColor(); updateColor();
// update size
m_size = m_startSize + (m_finalSize - m_startSize) / m_duration * m_elapsedTime;
// update position // update position
if(m_ignorePhysicsAfter < 0 || m_elapsedTime < m_ignorePhysicsAfter ) { if(m_ignorePhysicsAfter < 0 || m_elapsedTime < m_ignorePhysicsAfter ) {
// update position // update position
@ -74,9 +77,10 @@ void Particle::update(double elapsedTime)
// update acceleration // update acceleration
m_velocity += m_acceleration * elapsedTime; m_velocity += m_acceleration * elapsedTime;
}
m_rect.moveTo((int)m_position.x - m_size.width() / 2, (int)m_position.y - m_size.height() / 2); m_rect.moveTo((int)m_position.x - m_size.width() / 2, (int)m_position.y - m_size.height() / 2);
} m_rect.resize(m_size);
m_elapsedTime += elapsedTime; m_elapsedTime += elapsedTime;
} }

View File

@ -28,7 +28,7 @@
class Particle { class Particle {
public: public:
Particle(const Point& pos, const Size& size, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture = nullptr); Particle(const Point& pos, const Size& startSize, const Size& finalSize, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture = nullptr);
void render(); void render();
void update(double elapsedTime); void update(double elapsedTime);
@ -51,7 +51,7 @@ private:
PointF m_position; PointF m_position;
PointF m_velocity; PointF m_velocity;
PointF m_acceleration; PointF m_acceleration;
Size m_size; Size m_size, m_startSize, m_finalSize;
Rect m_rect; Rect m_rect;
float m_duration, m_ignorePhysicsAfter; float m_duration, m_ignorePhysicsAfter;
double m_elapsedTime; double m_elapsedTime;

View File

@ -47,8 +47,8 @@ ParticleEmitter::ParticleEmitter(const ParticleSystemPtr& parent)
m_pMaxPositionRadius = 3; m_pMaxPositionRadius = 3;
m_pMinPositionAngle = 0; m_pMinPositionAngle = 0;
m_pMaxPositionAngle = 360; m_pMaxPositionAngle = 360;
m_pMinSize = Size(32, 32); m_pStartSize = Size(32, 32);
m_pMaxSize = Size(32, 32); m_pFinalSize = Size(32, 32);
m_pMinDuration = 0; m_pMinDuration = 0;
m_pMaxDuration = 10; m_pMaxDuration = 10;
m_pIgnorePhysicsAfter = -1; m_pIgnorePhysicsAfter = -1;
@ -145,13 +145,13 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
// visual // visual
else if(childNode->tag() == "particle-size") { else if(childNode->tag() == "particle-size") {
m_pMinSize = childNode->value<Size>(); m_pStartSize = childNode->value<Size>();
m_pMaxSize = childNode->value<Size>(); m_pFinalSize = childNode->value<Size>();
} }
else if(childNode->tag() == "particle-min-size") else if(childNode->tag() == "particle-start-size")
m_pMinSize = childNode->value<Size>(); m_pStartSize = childNode->value<Size>();
else if(childNode->tag() == "particle-max-size") else if(childNode->tag() == "particle-final-size")
m_pMaxSize = childNode->value<Size>(); m_pFinalSize = childNode->value<Size>();
else if(childNode->tag() == "particle-colors") else if(childNode->tag() == "particle-colors")
m_pColors = Fw::split<Color>(childNode->value()); m_pColors = Fw::split<Color>(childNode->value());
@ -196,7 +196,6 @@ void ParticleEmitter::update(double elapsedTime)
for(int p = 0; p < m_burstCount; ++p) { for(int p = 0; p < m_burstCount; ++p) {
Size pSize = Size(Fw::randomRange(m_pMinSize.width(), m_pMaxSize.width()), Fw::randomRange(m_pMinSize.height(), m_pMaxSize.height()));
float pDuration = Fw::randomRange(m_pMinDuration, m_pMaxDuration); float pDuration = Fw::randomRange(m_pMinDuration, m_pMaxDuration);
// particles initial velocity // particles initial velocity
@ -210,7 +209,7 @@ void ParticleEmitter::update(double elapsedTime)
PointF pAcceleration(pAccelerationAbs * cos(pAccelerationAngle), pAccelerationAbs * sin(pAccelerationAngle)); PointF pAcceleration(pAccelerationAbs * cos(pAccelerationAngle), pAccelerationAbs * sin(pAccelerationAngle));
ParticleSystemPtr particleSystem = m_parent.lock(); ParticleSystemPtr particleSystem = m_parent.lock();
particleSystem->addParticle(ParticlePtr(new Particle(pPosition, pSize, pVelocity, pAcceleration, pDuration, m_pIgnorePhysicsAfter, m_pColors, m_pColorsStops, m_pTexture))); particleSystem->addParticle(ParticlePtr(new Particle(pPosition, m_pStartSize, m_pFinalSize, pVelocity, pAcceleration, pDuration, m_pIgnorePhysicsAfter, m_pColors, m_pColorsStops, m_pTexture)));
} }
} }

View File

@ -52,7 +52,7 @@ private:
int m_currentBurst, m_burstCount; int m_currentBurst, m_burstCount;
// particles size // particles size
Size m_pMinSize, m_pMaxSize; Size m_pStartSize, m_pFinalSize;
// particles initial position related to emitter position // particles initial position related to emitter position
float m_pMinPositionRadius, m_pMaxPositionRadius; float m_pMinPositionRadius, m_pMaxPositionRadius;