18
17
// along with this program; if not, write to the Free Software
19
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include "material_manager.hpp"
20
#include "graphics/smoke.hpp"
22
#include "graphics/material_manager.hpp"
23
#include "graphics/irr_driver.hpp"
24
#include "io/file_manager.hpp"
23
25
#include "karts/kart.hpp"
24
26
#include "physics/btKart.hpp"
25
27
#include "utils/constants.hpp"
27
Smoke::Smoke(Kart* kart)
28
: ParticleSystem(200, 0.0f, true, 0.75f),
29
Smoke::Smoke(Kart* kart) : m_kart(kart), m_particle_size(0.33f)
31
m_node = irr_driver->addParticleNode();
33
std::string debug_name = m_kart->getIdent()+" (smoke)";
34
m_node->setName(debug_name.c_str());
34
bsphere.setCenter(0, 0, 0);
35
bsphere.setRadius(1000.0f);
38
m_smokepuff = new ssgSimpleState ();
39
m_smokepuff->setTexture(material_manager->getMaterial("smoke.rgb")->getState()->getTexture());
40
m_smokepuff -> setTranslucent () ;
41
m_smokepuff -> enable ( GL_TEXTURE_2D ) ;
42
m_smokepuff -> setShadeModel ( GL_SMOOTH ) ;
43
m_smokepuff -> disable ( GL_CULL_FACE ) ;
44
m_smokepuff -> enable ( GL_BLEND ) ;
45
m_smokepuff -> disable ( GL_ALPHA_TEST ) ;
46
m_smokepuff -> enable ( GL_LIGHTING ) ;
47
m_smokepuff -> setColourMaterial ( GL_EMISSION ) ;
48
m_smokepuff -> setMaterial ( GL_AMBIENT, 0, 0, 0, 1 ) ;
49
m_smokepuff -> setMaterial ( GL_DIFFUSE, 0, 0, 0, 1 ) ;
50
m_smokepuff -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ) ;
51
m_smokepuff -> setShininess ( 0 ) ;
54
setState(m_smokepuff);
36
// Note: the smoke system is NOT child of the kart, since bullet
37
// gives the position of the wheels on the ground in world coordinates.
38
// So it's easier not to move the particle system with the kart, and set
39
// the position directly from the wheel coordinates.
40
m_node->setPosition(core::vector3df(-m_kart->getKartWidth()*0.35f,
41
m_particle_size*0.25f,
42
-m_kart->getKartLength()*0.5f));
43
Material *m= material_manager->getMaterial("smoke.png");
44
m->setMaterialProperties(&(m_node->getMaterial(0)));
45
m_node->setMaterialTexture(0, m->getTexture());
47
m_emitter = m_node->createPointEmitter(core::vector3df(0, 0, 0), // velocity in m/ms
49
video::SColor(255,0,0,0),
50
video::SColor(255,255,255,255),
54
m_emitter->setMinStartSize(core::dimension2df(m_particle_size/1.5f, m_particle_size/1.5f));
55
m_emitter->setMaxStartSize(core::dimension2df(m_particle_size*1.5f, m_particle_size*1.5f));
56
m_node->setEmitter(m_emitter); // this grabs the emitter
57
m_emitter->drop(); // so we can drop our references
59
scene::IParticleFadeOutAffector *af = m_node->createFadeOutParticleAffector(video::SColor(0, 255, 0, 0), 500);
60
m_node->addAffector(af);
56
63
} // KartParticleSystem
58
65
//-----------------------------------------------------------------------------
66
/** Destructor, removes
61
ssgDeRefDelete(m_smokepuff);
70
irr_driver->removeNode(m_node);
63
73
//-----------------------------------------------------------------------------
64
74
void Smoke::update(float t)
66
ParticleSystem::update(t);
76
// No particles to emit, no need to change the speed
77
if(m_emitter->getMinParticlesPerSecond()==0)
81
const btWheelInfo &wi = m_kart->getVehicle()->getWheelInfo(2+left);
82
Vec3 c=wi.m_raycastInfo.m_contactPointWS;
84
// FIXME: the X position is not yet always accurate.
85
m_node->setPosition(core::vector3df(c.getX()+m_particle_size*0.25f * (left?+1:-1),
87
c.getZ()+m_particle_size*0.25f));
89
// There seems to be no way to randomise the velocity for particles,
90
// so we have to do this manually, by changing the default velocity.
91
// Irrlicht expects velocity (called 'direction') in m/ms!!
92
Vec3 dir(cos(DEGREE_TO_RAD*(rand()%180))*0.002f,
93
sin(DEGREE_TO_RAD*(rand()%100))*0.002f,
94
sin(DEGREE_TO_RAD*(rand()%180))*0.002f);
95
m_emitter->setDirection(dir.toIrrVector());
69
98
//-----------------------------------------------------------------------------
70
void Smoke::particle_create(int, Particle *p)
72
sgSetVec4(p->m_col, 1, 1, 1, 1 ); /* initially white */
73
sgSetVec3(p->m_vel, 0, 0, 0 );
74
sgSetVec3(p->m_acc, 0, 0, 2.0f ); /* Gravity */
76
p->m_time_to_live = 0.4f;
78
// Change from left to right wheel and back for each new particle
79
static int wheel_number = 2;
80
wheel_number = 5 - wheel_number;
81
Vec3 xyz=m_kart->getVehicle()->getWheelInfo(wheel_number).m_raycastInfo.m_contactPointWS;
83
sgCopyVec3 (p->m_pos, xyz.toFloat());
84
p->m_vel[0] += cos(DEGREE_TO_RAD(rand()%180));
85
p->m_vel[1] += sin(DEGREE_TO_RAD(rand()%180));
86
p->m_vel[2] += sin(DEGREE_TO_RAD(rand()%100));
88
bsphere.setCenter ( xyz.getX(), xyz.getY(), xyz.getZ() ) ;
91
//-----------------------------------------------------------------------------
92
void Smoke::particle_update(float delta, int,
95
particle->m_size -= delta*.2f;
96
particle->m_col[3] -= delta * 2.0f;
99
void Smoke::setCreationRate(float f)
101
m_emitter->setMinParticlesPerSecond(int(f));
102
m_emitter->setMaxParticlesPerSecond(int(f));