2009-01-09 15:40:07 -05:00
// $Id: dust_cloud.cpp 1681 2008-04-09 13:52:48Z hikerstk $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# include "smoke.hpp"
2009-06-02 08:06:35 -04:00
2009-06-02 20:39:20 -04:00
# include "graphics/material_manager.hpp"
2009-06-02 08:06:35 -04:00
# include "graphics/irr_driver.hpp"
# include "io/file_manager.hpp"
2009-01-09 15:40:07 -05:00
# include "karts/kart.hpp"
2009-06-02 20:39:20 -04:00
# include "utils/constants.hpp"
2009-01-09 15:40:07 -05:00
2009-06-02 08:06:35 -04:00
Smoke : : Smoke ( Kart * kart ) : m_kart ( kart )
2009-06-02 21:49:57 -04:00
{
2009-06-04 16:16:38 -04:00
const float particle_size = 0.33f ;
2009-06-02 21:49:57 -04:00
// Left wheel
m_node_l = irr_driver - > addParticleNode ( ) ;
m_node_l - > setParent ( m_kart - > getNode ( ) ) ;
2009-06-03 19:00:16 -04:00
m_node_l - > setPosition ( core : : vector3df ( - m_kart - > getKartWidth ( ) * 0.35f , particle_size * 0.25f , - m_kart - > getKartLength ( ) * 0.5f ) ) ; // Should use (behind) wheel pos
2009-06-02 21:49:57 -04:00
Material * ml = material_manager - > getMaterial ( " smoke.png " ) ;
ml - > setMaterialProperties ( & ( m_node_l - > getMaterial ( 0 ) ) ) ;
m_node_l - > setMaterialTexture ( 0 , ml - > getTexture ( ) ) ;
2009-06-02 08:06:35 -04:00
2009-06-02 21:49:57 -04:00
m_emitter_l = m_node_l - > createPointEmitter ( core : : vector3df ( 0 , 0 , 0 ) , // velocity in m/ms
2009-06-02 20:39:20 -04:00
5 , 10 ,
video : : SColor ( 255 , 0 , 0 , 0 ) ,
video : : SColor ( 255 , 255 , 255 , 255 ) ,
2009-06-04 16:16:38 -04:00
300 , 500 ,
2009-06-02 20:39:20 -04:00
20 // max angle
2009-06-02 08:06:35 -04:00
) ;
2009-06-03 19:00:16 -04:00
m_emitter_l - > setMinStartSize ( core : : dimension2df ( particle_size / 1.5f , particle_size / 1.5f ) ) ;
m_emitter_l - > setMaxStartSize ( core : : dimension2df ( particle_size * 1.5f , particle_size * 1.5f ) ) ;
2009-06-02 21:49:57 -04:00
m_node_l - > setEmitter ( m_emitter_l ) ; // this grabs the emitter
2009-06-04 16:16:38 -04:00
scene : : IParticleFadeOutAffector * afl = m_node_l - > createFadeOutParticleAffector ( video : : SColor ( 0 , 255 , 0 , 0 ) , 500 ) ;
2009-06-02 21:49:57 -04:00
m_node_l - > addAffector ( afl ) ;
afl - > drop ( ) ;
// Right wheel
m_node_r = irr_driver - > addParticleNode ( ) ;
m_node_r - > setParent ( m_kart - > getNode ( ) ) ;
2009-06-03 19:00:16 -04:00
m_node_r - > setPosition ( core : : vector3df ( m_kart - > getKartWidth ( ) * 0.35f , particle_size * 0.25f , - m_kart - > getKartLength ( ) * 0.5f ) ) ; // Should use (behind) wheel pos
2009-06-02 21:49:57 -04:00
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
2009-06-04 16:16:38 -04:00
5 , 10 ,
2009-06-02 21:49:57 -04:00
video : : SColor ( 255 , 0 , 0 , 0 ) ,
video : : SColor ( 255 , 255 , 255 , 255 ) ,
2009-06-04 16:16:38 -04:00
300 , 500 ,
2009-06-02 21:49:57 -04:00
20 // max angle
2009-06-04 16:16:38 -04:00
) ;
2009-06-03 19:00:16 -04:00
m_emitter_r - > setMinStartSize ( core : : dimension2df ( particle_size / 1.5f , particle_size / 1.5f ) ) ;
m_emitter_r - > setMaxStartSize ( core : : dimension2df ( particle_size * 1.5f , particle_size * 1.5f ) ) ;
2009-06-02 21:49:57 -04:00
m_node_r - > setEmitter ( m_emitter_r ) ; // this grabs the emitter
2009-01-09 15:40:07 -05:00
2009-06-04 16:16:38 -04:00
scene : : IParticleFadeOutAffector * afr = m_node_r - > createFadeOutParticleAffector ( video : : SColor ( 255 , 255 , 0 , 0 ) , 500 ) ;
2009-06-02 21:49:57 -04:00
m_node_r - > addAffector ( afr ) ;
afr - > drop ( ) ;
2009-01-09 15:40:07 -05:00
} // KartParticleSystem
//-----------------------------------------------------------------------------
2009-06-02 08:06:35 -04:00
/** Destructor, removes
*/
2009-01-09 15:40:07 -05:00
Smoke : : ~ Smoke ( )
{
2009-06-02 21:49:57 -04:00
irr_driver - > removeNode ( m_node_l ) ;
irr_driver - > removeNode ( m_node_r ) ;
2009-01-09 15:40:07 -05:00
} // ~Smoke
2009-06-02 08:06:35 -04:00
2009-01-09 15:40:07 -05:00
//-----------------------------------------------------------------------------
void Smoke : : update ( float t )
{
2009-06-02 20:39:20 -04:00
// No particles to emit, no need to change the speed
2009-06-02 21:49:57 -04:00
if ( m_emitter_l - > getMinParticlesPerSecond ( ) = = 0 )
2009-06-02 20:39:20 -04:00
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!!
2009-06-02 21:49:57 -04:00
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 ( ) ) ;
2009-01-09 15:40:07 -05:00
} // update
//-----------------------------------------------------------------------------
2009-06-02 08:06:35 -04:00
void Smoke : : setCreationRate ( float f )
2009-01-09 15:40:07 -05:00
{
2009-06-02 21:49:57 -04:00
m_emitter_l - > setMinParticlesPerSecond ( int ( f ) ) ;
m_emitter_l - > setMaxParticlesPerSecond ( int ( f ) ) ;
m_emitter_r - > setMinParticlesPerSecond ( int ( f ) ) ;
m_emitter_r - > setMaxParticlesPerSecond ( int ( f ) ) ;
2009-06-02 08:06:35 -04:00
} // setCreationRate