particle system with exori flam

This commit is contained in:
Henrique Santiago 2011-12-19 01:24:35 -02:00
parent ab9efe5a95
commit 56a392f681
11 changed files with 84 additions and 43 deletions

View File

@ -1,11 +1,17 @@
ParticleSystem ParticleSystem
AttractionAffector
position: 320 180
acceleration: 500
repelish: true
delay: 0.5
// Fire // Fire
Emitter Emitter
position: 295 180 position: 295 180
duration: 0.5 duration: 0.5
burstRate: 0.0166 burstRate: 0.0166
burstCount: 6 burstCount: 3
delay: 0 delay: 0
particle-min-duration: 0.3 particle-min-duration: 0.3
@ -15,24 +21,25 @@ ParticleSystem
particle-min-velocity: 200 particle-min-velocity: 200
particle-max-velocity: 240 particle-max-velocity: 240
particle-min-velocity-angle: -5 particle-min-velocity-angle: -10
particle-max-velocity-angle: 10 particle-max-velocity-angle: 10
particle-acceleration: 0 particle-acceleration: 0
particle-start-size: 8 8 particle-start-size: 16 16
particle-final-size: 64 64 particle-final-size: 64 64
particle-colors: #ff8c00ff #e6660080 #1e1e1e00 particle-colors: #ffcc0050 #ffff0025 #ff000000
particle-colors-stops: 0 0.15 0.3 particle-colors-stops: 0 0.15 0.3
particle-composition-mode: addition
particle-texture: circle2.png particle-texture: circle2.png
// Fire ball // Fire ball
Emitter Emitter
position: 200 200 position: 295 180
duration: 0.7 duration: 0
burstRate: 0.0166 burstRate: 0.0166
burstCount: 3 burstCount: 3
delay: 0 delay: 0
@ -50,38 +57,46 @@ ParticleSystem
particle-acceleration: 0 particle-acceleration: 0
particle-start-size: 16 16 particle-start-size: 16 16
particle-final-size: 64 64 particle-final-size: 32 32
particle-composition-mode: addition
particle-colors: #19191980 #0f0f0f80 #00000000 particle-colors: #19191980 #0f0f0f80 #00000000
particle-colors-stops: 0 0.45 0.9 particle-colors-stops: 0 0.45 0.9
particle-texture: circle2.png particle-texture: circle2.png
ParticleSystem
AttractionAffector
position: 320 180
acceleration: 30
repelish: true
// Smoke // Smoke
Emitter Emitter
position: 200 200 position: 295 180
duration: 0.1 duration: 0.7
burstRate: 0.0166 burstRate: 0.0166
burstCount: 3 burstCount: 3
delay: 0 delay: 0.4
particle-min-duration: 0.1 particle-min-duration: 0.9
particle-max-duration: 0.45 particle-max-duration: 0.9
particle-position-radius: 0 particle-position-radius: 0
particle-min-velocity: 60 particle-min-velocity: 60
particle-max-velocity: 80 particle-max-velocity: 85
particle-min-velocity-angle: -5 particle-min-velocity-angle: -20
particle-max-velocity-angle: 10 particle-max-velocity-angle: 20
particle-acceleration: 0 particle-acceleration: 0
particle-start-size: 8 8 particle-start-size: 8 8
particle-final-size: 64 64 particle-final-size: 64 64
particle-colors: #555555ff #55555580 #55555500 particle-colors: #66666610 #00000000
particle-colors-stops: 0 0.225 0.45 particle-colors-stops: 0 0.9
particle-texture: circle2.png particle-texture: circle2.png

View File

@ -34,7 +34,7 @@ void Painter::init()
{ {
setColor(Fw::white); setColor(Fw::white);
setOpacity(255); setOpacity(255);
setCompositionMode(CompositionMode_SourceOver); setCompositionMode(CompositionMode_Normal);
m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram); m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram);
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader); m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
@ -154,13 +154,13 @@ void Painter::setCustomProgram(PainterShaderProgramPtr program)
void Painter::setCompositionMode(Painter::CompositionMode compositionMode) void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
{ {
switch(compositionMode) { switch(compositionMode) {
case CompositionMode_SourceOver: case CompositionMode_Normal:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
break; break;
case CompositionMode_ColorizeSource: case CompositionMode_Multiply:
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
break; break;
case CompositionMode_AdditiveSource: case CompositionMode_Addition:
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
break; break;
} }

View File

@ -32,9 +32,9 @@ class Painter
{ {
public: public:
enum CompositionMode { enum CompositionMode {
CompositionMode_SourceOver, CompositionMode_Normal,
CompositionMode_ColorizeSource, CompositionMode_Multiply,
CompositionMode_AdditiveSource CompositionMode_Addition
}; };
void init(); void init();

View File

@ -24,7 +24,7 @@
#include "graphics.h" #include "graphics.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>
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) 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, Painter::CompositionMode compositionMode, TexturePtr texture)
{ {
m_colors = colors; m_colors = colors;
m_colorsStops = colorsStops; m_colorsStops = colorsStops;
@ -35,6 +35,7 @@ Particle::Particle(const Point& pos, const Size& startSize, const Size& finalSiz
m_velocity = velocity; m_velocity = velocity;
m_acceleration = acceleration; m_acceleration = acceleration;
m_compositionMode = compositionMode;
m_texture = texture; m_texture = texture;
m_duration = duration; m_duration = duration;
m_ignorePhysicsAfter = ignorePhysicsAfter; m_ignorePhysicsAfter = ignorePhysicsAfter;
@ -49,9 +50,9 @@ void Particle::render()
if(!m_texture) if(!m_texture)
g_painter.drawFilledRect(m_rect); g_painter.drawFilledRect(m_rect);
else { else {
g_painter.setCompositionMode(Painter::CompositionMode_AdditiveSource); g_painter.setCompositionMode(m_compositionMode);
g_painter.drawTexturedRect(m_rect, m_texture); g_painter.drawTexturedRect(m_rect, m_texture);
g_painter.setCompositionMode(Painter::CompositionMode_SourceOver); g_painter.setCompositionMode(Painter::CompositionMode_Normal);
} }
} }

View File

@ -24,11 +24,12 @@
#define PARTICLE_H #define PARTICLE_H
#include "declarations.h" #include "declarations.h"
#include "painter.h"
#include <framework/global.h> #include <framework/global.h>
class Particle { class Particle {
public: public:
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); 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, Painter::CompositionMode compositionMode = Painter::CompositionMode_Normal, TexturePtr texture = nullptr);
void render(); void render();
void update(double elapsedTime); void update(double elapsedTime);
@ -53,6 +54,7 @@ private:
PointF m_acceleration; PointF m_acceleration;
Size m_size, m_startSize, m_finalSize; Size m_size, m_startSize, m_finalSize;
Rect m_rect; Rect m_rect;
Painter::CompositionMode m_compositionMode;
float m_duration, m_ignorePhysicsAfter; float m_duration, m_ignorePhysicsAfter;
double m_elapsedTime; double m_elapsedTime;
bool m_finished; bool m_finished;

View File

@ -112,6 +112,8 @@ bool AttractionAffector::load(const OTMLNodePtr& node)
return false; return false;
m_acceleration = 32; m_acceleration = 32;
m_reduction = 0;
m_repelish = false;
for(const OTMLNodePtr& childNode : node->children()) { for(const OTMLNodePtr& childNode : node->children()) {
if(childNode->tag() == "position") if(childNode->tag() == "position")
@ -120,6 +122,8 @@ bool AttractionAffector::load(const OTMLNodePtr& node)
m_acceleration = childNode->value<float>(); m_acceleration = childNode->value<float>();
else if(childNode->tag() == "velocity-reduction-percent") else if(childNode->tag() == "velocity-reduction-percent")
m_reduction = childNode->value<float>(); m_reduction = childNode->value<float>();
else if(childNode->tag() == "repelish")
m_repelish = childNode->value<bool>();
} }
return true; return true;
} }
@ -134,6 +138,10 @@ void AttractionAffector::updateParticle(const ParticlePtr& particle, double elap
if(d.length() == 0) if(d.length() == 0)
return; return;
PointF pVelocity = particle->getVelocity() + (d / d.length() * m_acceleration * elapsedTime); PointF direction = PointF(1, 1);
if(m_repelish)
direction = PointF(-1, -1);
PointF pVelocity = particle->getVelocity() + (d / d.length() * m_acceleration * elapsedTime) * direction;
particle->setVelocity(pVelocity - pVelocity * m_reduction/100.0 * elapsedTime); particle->setVelocity(pVelocity - pVelocity * m_reduction/100.0 * elapsedTime);
} }

View File

@ -60,6 +60,7 @@ public:
private: private:
Point m_position; Point m_position;
float m_acceleration, m_reduction; float m_acceleration, m_reduction;
bool m_repelish;
}; };
#endif #endif

View File

@ -159,6 +159,14 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
m_pColorsStops = Fw::split<float>(childNode->value()); m_pColorsStops = Fw::split<float>(childNode->value());
else if(childNode->tag() == "particle-texture") else if(childNode->tag() == "particle-texture")
m_pTexture = g_textures.getTexture(childNode->value()); m_pTexture = g_textures.getTexture(childNode->value());
else if(childNode->tag() == "particle-composition-mode") {
if(childNode->value() == "normal")
m_pCompositionMode = Painter::CompositionMode_Normal;
else if(childNode->value() == "multiply")
m_pCompositionMode = Painter::CompositionMode_Multiply;
else if(childNode->value() == "addition")
m_pCompositionMode = Painter::CompositionMode_Addition;
}
} }
if(m_pColors.empty()) if(m_pColors.empty())
@ -210,7 +218,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, m_pStartSize, m_pFinalSize, 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_pCompositionMode, m_pTexture)));
} }
} }

View File

@ -24,6 +24,7 @@
#define PARTICLEEMITTER_H #define PARTICLEEMITTER_H
#include "declarations.h" #include "declarations.h"
#include "painter.h"
#include <framework/global.h> #include <framework/global.h>
#include <framework/graphics/texture.h> #include <framework/graphics/texture.h>
#include <framework/otml/otml.h> #include <framework/otml/otml.h>
@ -73,6 +74,7 @@ private:
std::vector<Color> m_pColors; std::vector<Color> m_pColors;
std::vector<float> m_pColorsStops; std::vector<float> m_pColorsStops;
TexturePtr m_pTexture; TexturePtr m_pTexture;
Painter::CompositionMode m_pCompositionMode;
}; };
#endif #endif

View File

@ -522,15 +522,17 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg)
{ {
Position pos = parsePosition(msg); Position pos = parsePosition(msg);
int effectId = msg.getU8(); int effectId = msg.getU8();
EffectPtr effect = EffectPtr(new Effect());
effect->setId(effectId);
effect->startAnimation();
TilePtr tile = g_map.getTile(pos); if(effectId != 37) {
tile->addEffect(effect); EffectPtr effect = EffectPtr(new Effect());
effect->setId(effectId);
effect->startAnimation();
// TODO: check if particles effect exists, if not, play standard sprite effect. TilePtr tile = g_map.getTile(pos);
//g_particleManager.load("particle.otpa"); tile->addEffect(effect);
}
else
g_particleManager.load("particle.otpa");
} }
void ProtocolGame::parseAnimatedText(InputMessage& msg) void ProtocolGame::parseAnimatedText(InputMessage& msg)
@ -546,10 +548,12 @@ void ProtocolGame::parseDistanceMissile(InputMessage& msg)
Position toPos = parsePosition(msg); Position toPos = parsePosition(msg);
int shotId = msg.getU8(); int shotId = msg.getU8();
MissilePtr shot = MissilePtr(new Missile()); if(shotId != 4) {
shot->setId(shotId); MissilePtr shot = MissilePtr(new Missile());
shot->setPath(fromPos, toPos); shot->setId(shotId);
g_map.addThing(shot, fromPos); shot->setPath(fromPos, toPos);
g_map.addThing(shot, fromPos);
}
} }
void ProtocolGame::parseCreatureSquare(InputMessage& msg) void ProtocolGame::parseCreatureSquare(InputMessage& msg)

View File

@ -83,7 +83,7 @@ bool UIGame::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifier
return true; return true;
} else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) { } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
g_game.turn(Otc::East); g_game.turn(Otc::East);
g_particleManager.load("particle.otpa"); //g_particleManager.load("particle.otpa");
return true; return true;
} else if(keyCode == Fw::KeyDown || keyCode == Fw::KeyNumpad2) { } else if(keyCode == Fw::KeyDown || keyCode == Fw::KeyNumpad2) {
g_game.turn(Otc::South); g_game.turn(Otc::South);