Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Attributes
ParticleSystem Class Reference

#include <particle_system.hpp>

Inheritance diagram for ParticleSystem:
Inheritance graph
[legend]
Collaboration diagram for ParticleSystem:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ParticleSystem (int num, float _create_rate, int _turn_to_face, float sz, float bsphere_size)
virtual ~ParticleSystem ()
virtual void update (float t)
virtual void particle_create (int index, Particle *p)=0
virtual void particle_update (float deltaTime, int index, Particle *p)=0
virtual void particle_delete (int index, Particle *p)=0
void init (int initial_num)
void recalcBSphere ()
void setSize (float sz)
float getSize () const
void draw_geometry ()
void setCreationRate (float cr)
float getCreationRate () const
int getNumParticles () const
int getNumActiveParticles () const

Private Attributes

int m_num_particles
int m_num_verts
int m_turn_to_face
int m_num_active
Particlem_particles
float m_create_error
float m_create_rate
float m_size

Detailed Description

Definition at line 61 of file particle_system.hpp.


Constructor & Destructor Documentation

ParticleSystem::ParticleSystem ( int  num,
float  _create_rate,
int  _turn_to_face,
float  sz,
float  bsphere_size 
)

Definition at line 25 of file particle_system.cpp.

        : ssgVtxTable ( GL_QUADS,
            new ssgVertexArray   ( num * 4 /*, new sgVec3 [ num * 4 ]*/ ),
            new ssgNormalArray   ( num * 4 /*, new sgVec3 [ num * 4 ]*/ ),
            new ssgTexCoordArray ( num * 4 /*, new sgVec2 [ num * 4 ]*/ ),
            new ssgColourArray   ( num * 4 /*, new sgVec4 [ num * 4 ]*/ )
            )
{
    m_turn_to_face = _ttf ;
    m_create_error = 0 ;
    m_create_rate = _create_rate ;

    m_size = sz ;

    bsphere . setRadius ( bsphere_size ) ;
    bsphere . setCenter ( 0, 0, 0 ) ;

    m_num_particles = num ;
    m_num_verts     = num * 4 ;

    m_particles = new Particle [ num ] ;

    int i ;

    for ( i = 0 ; i < m_num_verts ; i++ )
    {
        sgSetVec3  ( getNormal ( i ), 0, -1, 0 ) ;
        sgSetVec4  ( getColour ( i ), 1, 1, 1, 1 ) ;
        sgZeroVec3 ( getVertex ( i ) ) ;
    }

    for ( i = 0 ; i < m_num_particles ; i++ )
    {
        sgSetVec2 ( getTexCoord ( i*4+0 ), 0, 0 ) ;
        sgSetVec2 ( getTexCoord ( i*4+1 ), 1, 0 ) ;
        sgSetVec2 ( getTexCoord ( i*4+2 ), 1, 1 ) ;
        sgSetVec2 ( getTexCoord ( i*4+3 ), 0, 1 ) ;
    }

    m_num_active = 0 ;
}

Definition at line 156 of file particle_system.cpp.

{
    // TODO we should call particle_delete here, but that's not possible, because
    // the functions are virtual (illegal in destructor)

    delete[] m_particles ;
}

Member Function Documentation

Definition at line 85 of file particle_system.cpp.

{
    sgVec3 nxny, xxny, xxyy, nxyy ;

    float SZ = m_size / 2.0f ;

    if ( m_turn_to_face )
    {
        sgMat4 mat ;

        glGetFloatv ( GL_MODELVIEW_MATRIX, (float *) mat ) ;

        sgVec3 xx, yy ;

        sgSetVec3 ( xx, mat[0][0] * SZ, mat[1][0] * SZ, mat[2][0] * SZ ) ;
        sgSetVec3 ( yy, mat[0][1] * SZ, mat[1][1] * SZ, mat[2][1] * SZ ) ;

        sgSetVec3 ( nxny, -xx[0]-yy[0], -xx[1]-yy[1], -xx[2]-yy[2] ) ;
        sgSetVec3 ( nxyy, -xx[0]+yy[0], -xx[1]+yy[1], -xx[2]+yy[2] ) ;
        sgSetVec3 ( xxny,  xx[0]-yy[0],  xx[1]-yy[1],  xx[2]-yy[2] ) ;
        sgSetVec3 ( xxyy,  xx[0]+yy[0],  xx[1]+yy[1],  xx[2]+yy[2] ) ;
    }
    else
    {
        sgSetVec3 ( xxny ,  SZ, 0, -SZ ) ;
        sgSetVec3 ( nxny , -SZ, 0, -SZ ) ;
        sgSetVec3 ( nxyy , -SZ, 0,  SZ ) ;
        sgSetVec3 ( xxyy,   SZ, 0,  SZ ) ;
    }

    int j = 0 ;

    for ( int i = 0 ; i < m_num_particles ; i++ )
    {
        /* Make them disappear if not needed */

        if ( m_particles[i].m_time_to_live <= 0.0f )
            continue ;

        sgCopyVec4 ( getColour ( j + 0 ), m_particles[i].m_col ) ;
        sgCopyVec4 ( getColour ( j + 1 ), m_particles[i].m_col ) ;
        sgCopyVec4 ( getColour ( j + 2 ), m_particles[i].m_col ) ;
        sgCopyVec4 ( getColour ( j + 3 ), m_particles[i].m_col ) ;

        sgAddScaledVec3 ( getVertex ( j + 0 ), m_particles[i].m_pos,
                          nxny, m_particles[i].m_size ) ;
        sgAddScaledVec3 ( getVertex ( j + 1 ), m_particles[i].m_pos,
                          xxny, m_particles[i].m_size ) ;
        sgAddScaledVec3 ( getVertex ( j + 2 ), m_particles[i].m_pos,
                          xxyy, m_particles[i].m_size ) ;
        sgAddScaledVec3 ( getVertex ( j + 3 ), m_particles[i].m_pos,
                          nxyy, m_particles[i].m_size ) ;

        j += 4 ;
    }

    rawSetNumVertices ( j ) ; /* Avoid drawing more than 'j' vertices. */

    if ( j > 0 )
    {
        glDisable   ( GL_CULL_FACE ) ;
        glDepthMask ( 0 ) ;

        ssgVtxTable::draw_geometry () ;

        glDepthMask ( 1 ) ;
        glEnable ( GL_CULL_FACE ) ;
    }
}
float ParticleSystem::getCreationRate ( ) const [inline]

Definition at line 94 of file particle_system.hpp.

{ return m_create_rate ; }
int ParticleSystem::getNumActiveParticles ( ) const [inline]

Definition at line 97 of file particle_system.hpp.

{ return m_num_active    ; }
int ParticleSystem::getNumParticles ( ) const [inline]

Definition at line 96 of file particle_system.hpp.

{ return m_num_particles ; }
float ParticleSystem::getSize ( ) const [inline]

Definition at line 89 of file particle_system.hpp.

{ return m_size ; }
void ParticleSystem::init ( int  initial_num)

Definition at line 70 of file particle_system.cpp.

{
    for ( int i = 0 ; i < initial_num ; i++ )
        particle_create(i, & m_particles [ i ] ) ;
}

Here is the call graph for this function:

virtual void ParticleSystem::particle_create ( int  index,
Particle p 
) [pure virtual]

Implemented in Smoke.

Here is the caller graph for this function:

virtual void ParticleSystem::particle_delete ( int  index,
Particle p 
) [pure virtual]

Implemented in Smoke.

Here is the caller graph for this function:

virtual void ParticleSystem::particle_update ( float  deltaTime,
int  index,
Particle p 
) [pure virtual]

Implemented in Smoke.

Here is the caller graph for this function:

Definition at line 78 of file particle_system.cpp.

{
    bsphere . setRadius ( 1000.0f ) ;
    bsphere . setCenter ( 0, 0, 0 ) ;
}
void ParticleSystem::setCreationRate ( float  cr) [inline]

Definition at line 93 of file particle_system.hpp.

{ m_create_rate = cr ; }
void ParticleSystem::setSize ( float  sz) [inline]

Definition at line 88 of file particle_system.hpp.

{ m_size = sz ; }
void ParticleSystem::update ( float  t) [virtual]

Reimplemented in Smoke.

Definition at line 165 of file particle_system.cpp.

{
    int i ;

    m_create_error += m_create_rate * t ;

    m_num_active = 0 ;

    /* Call the update routine for all the particles */
    for ( i = 0 ; i < m_num_particles ; i++ )
        if ( m_particles [ i ] . m_time_to_live > 0.0f )
        {
            m_particles [ i ] . update ( t ) ;
            particle_update( t, i, & m_particles [ i ] ) ;
        }

    /* Check for death of particles */
    for ( i = 0 ; i < m_num_particles ; i++ )
        if ( m_particles [ i ] . m_time_to_live <= 0.0 )
        {
            particle_delete ( i, & m_particles [ i ] ) ;

            m_particles [ i ] . m_pos [ 2 ] = -1000000.0f ;

            if ( m_create_error >= 1.0f )
            {
                particle_create( i, & m_particles [ i ] ) ;
                m_create_error -= 1.0f ;
            }
        }
        else
        {
            m_num_active++ ;
        }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 69 of file particle_system.hpp.

Definition at line 70 of file particle_system.hpp.

Definition at line 66 of file particle_system.hpp.

Definition at line 63 of file particle_system.hpp.

Definition at line 64 of file particle_system.hpp.

Definition at line 67 of file particle_system.hpp.

float ParticleSystem::m_size [private]

Definition at line 72 of file particle_system.hpp.

Definition at line 65 of file particle_system.hpp.


The documentation for this class was generated from the following files: