Test with two smoke trails. Easily undoable (not mixed the right and left
parts yet, so erase _r part and mass replace s/_l//g). If this stays, better find the common parts and mix the rest so any change is done for both sides. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3582 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
96805cfc71
commit
f84a77cf59
@ -27,29 +27,53 @@
|
||||
#include "utils/constants.hpp"
|
||||
|
||||
Smoke::Smoke(Kart* kart) : m_kart(kart)
|
||||
{
|
||||
m_node = irr_driver->addParticleNode();
|
||||
m_node->setParent(m_kart->getNode());
|
||||
{
|
||||
const float particle_size = 0.5f;
|
||||
m_node->setPosition(core::vector3df(0, particle_size*0.5f, -m_kart->getKartLength()*0.5f));
|
||||
Material *m= material_manager->getMaterial("smoke.png");
|
||||
m->setMaterialProperties(&(m_node->getMaterial(0)));
|
||||
m_node->setMaterialTexture(0, m->getTexture());
|
||||
// Left wheel
|
||||
m_node_l = irr_driver->addParticleNode();
|
||||
m_node_l->setParent(m_kart->getNode());
|
||||
m_node_l->setPosition(core::vector3df(-m_kart->getKartWidth()*0.35f, particle_size*0.5f, -m_kart->getKartLength()*0.5f)); // Should use (behind) wheel pos
|
||||
Material *ml= material_manager->getMaterial("smoke.png");
|
||||
ml->setMaterialProperties(&(m_node_l->getMaterial(0)));
|
||||
m_node_l->setMaterialTexture(0, ml->getTexture());
|
||||
|
||||
m_emitter = m_node->createPointEmitter(core::vector3df(0, 0, 0), // velocity in m/ms
|
||||
m_emitter_l = m_node_l->createPointEmitter(core::vector3df(0, 0, 0), // velocity in m/ms
|
||||
5, 10,
|
||||
video::SColor(255,0,0,0),
|
||||
video::SColor(255,255,255,255),
|
||||
400, 400,
|
||||
20 // max angle
|
||||
);
|
||||
m_emitter->setMinStartSize(core::dimension2df(particle_size, particle_size));
|
||||
m_emitter->setMaxStartSize(core::dimension2df(particle_size, particle_size));
|
||||
m_node->setEmitter(m_emitter); // this grabs the emitter
|
||||
m_emitter_l->setMinStartSize(core::dimension2df(particle_size, particle_size));
|
||||
m_emitter_l->setMaxStartSize(core::dimension2df(particle_size, particle_size));
|
||||
m_node_l->setEmitter(m_emitter_l); // this grabs the emitter
|
||||
|
||||
scene::IParticleAffector *af = m_node->createFadeOutParticleAffector();
|
||||
m_node->addAffector(af);
|
||||
af->drop();
|
||||
scene::IParticleAffector *afl = m_node_l->createFadeOutParticleAffector();
|
||||
m_node_l->addAffector(afl);
|
||||
afl->drop();
|
||||
|
||||
// Right wheel
|
||||
m_node_r = irr_driver->addParticleNode();
|
||||
m_node_r->setParent(m_kart->getNode());
|
||||
m_node_r->setPosition(core::vector3df(m_kart->getKartWidth()*0.35f, particle_size*0.5f, -m_kart->getKartLength()*0.5f)); // Should use (behind) wheel pos
|
||||
Material *mr= material_manager->getMaterial("smoke.png");
|
||||
mr->setMaterialProperties(&(m_node_r->getMaterial(0)));
|
||||
m_node_r->setMaterialTexture(0, mr->getTexture());
|
||||
|
||||
m_emitter_r = m_node_r->createPointEmitter(core::vector3df(0, 0, 0), // velocity in m/ms
|
||||
5, 10,
|
||||
video::SColor(255,0,0,0),
|
||||
video::SColor(255,255,255,255),
|
||||
400, 400,
|
||||
20 // max angle
|
||||
);
|
||||
m_emitter_r->setMinStartSize(core::dimension2df(particle_size, particle_size));
|
||||
m_emitter_r->setMaxStartSize(core::dimension2df(particle_size, particle_size));
|
||||
m_node_r->setEmitter(m_emitter_r); // this grabs the emitter
|
||||
|
||||
scene::IParticleAffector *afr = m_node_r->createFadeOutParticleAffector();
|
||||
m_node_r->addAffector(afr);
|
||||
afr->drop();
|
||||
} // KartParticleSystem
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -57,26 +81,33 @@ Smoke::Smoke(Kart* kart) : m_kart(kart)
|
||||
*/
|
||||
Smoke::~Smoke()
|
||||
{
|
||||
irr_driver->removeNode(m_node);
|
||||
irr_driver->removeNode(m_node_l);
|
||||
irr_driver->removeNode(m_node_r);
|
||||
} // ~Smoke
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Smoke::update(float t)
|
||||
{
|
||||
// No particles to emit, no need to change the speed
|
||||
if(m_emitter->getMinParticlesPerSecond()==0)
|
||||
if(m_emitter_l->getMinParticlesPerSecond()==0)
|
||||
return;
|
||||
// There seems to be no way to randomise the velocity for particles,
|
||||
// so we have to do this manually, by changing the default velocity.
|
||||
// Irrlicht expects velocity (called 'direction') in m/ms!!
|
||||
Vec3 dir(cos(DEGREE_TO_RAD(rand()%180))*0.001f,
|
||||
sin(DEGREE_TO_RAD(rand()%180))*0.001f,
|
||||
sin(DEGREE_TO_RAD(rand()%100))*0.001f);
|
||||
m_emitter->setDirection(dir.toIrrVector());
|
||||
Vec3 dirl(cos(DEGREE_TO_RAD(rand()%180))*0.002f,
|
||||
sin(DEGREE_TO_RAD(rand()%180))*0.002f,
|
||||
sin(DEGREE_TO_RAD(rand()%100))*0.002f);
|
||||
m_emitter_l->setDirection(dirl.toIrrVector());
|
||||
Vec3 dirr(cos(DEGREE_TO_RAD(rand()%180))*0.002f,
|
||||
sin(DEGREE_TO_RAD(rand()%180))*0.002f,
|
||||
sin(DEGREE_TO_RAD(rand()%100))*0.002f);
|
||||
m_emitter_r->setDirection(dirr.toIrrVector());
|
||||
} // update
|
||||
//-----------------------------------------------------------------------------
|
||||
void Smoke::setCreationRate(float f)
|
||||
{
|
||||
m_emitter->setMinParticlesPerSecond(int(f));
|
||||
m_emitter->setMaxParticlesPerSecond(int(f));
|
||||
m_emitter_l->setMinParticlesPerSecond(int(f));
|
||||
m_emitter_l->setMaxParticlesPerSecond(int(f));
|
||||
m_emitter_r->setMinParticlesPerSecond(int(f));
|
||||
m_emitter_r->setMaxParticlesPerSecond(int(f));
|
||||
} // setCreationRate
|
||||
|
@ -30,11 +30,13 @@ class Smoke
|
||||
private:
|
||||
/** The kart to which this smoke belongs. */
|
||||
const Kart *m_kart;
|
||||
/** Irrlicht's particle system. */
|
||||
scene::IParticleSystemSceneNode *m_node;
|
||||
/** The emitter. Access to this is needed to adjust the number of
|
||||
/** Irrlicht's particle systems. */
|
||||
scene::IParticleSystemSceneNode *m_node_l; /* left wheel */
|
||||
scene::IParticleSystemSceneNode *m_node_r; /* right wheel */
|
||||
/** The emitters. Access to these is needed to adjust the number of
|
||||
* particles per second. */
|
||||
scene::IParticleEmitter *m_emitter;
|
||||
scene::IParticleEmitter *m_emitter_l;
|
||||
scene::IParticleEmitter *m_emitter_r;
|
||||
public:
|
||||
Smoke (Kart* kart);
|
||||
virtual ~Smoke ();
|
||||
|
Loading…
Reference in New Issue
Block a user