Back to index

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

#include <smoke.hpp>

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

List of all members.

Public Member Functions

 Smoke (Kart *kart, int num, float _create_rate, int _turn_to_face, float sz, float bsphere_size)
virtual void update (float t)
virtual void particle_create (int index, Particle *p)
virtual void particle_update (float deltaTime, int index, Particle *p)
virtual void particle_delete (int index, Particle *p)
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

Kartm_kart

Detailed Description

Definition at line 28 of file smoke.hpp.


Constructor & Destructor Documentation

Smoke::Smoke ( Kart kart,
int  num,
float  _create_rate,
int  _turn_to_face,
float  sz,
float  bsphere_size 
)

Definition at line 24 of file smoke.cpp.

        : ParticleSystem (num, _create_rate, _ttf, sz, bsphere_size),
        m_kart(kart_)
{
    getBSphere () -> setCenter ( 0, 0, 0 ) ;
    getBSphere () -> setRadius ( 1000.0f ) ;
    dirtyBSphere();
}   // KartParticleSystem

Member Function Documentation

void ParticleSystem::draw_geometry ( ) [inherited]

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, inherited]

Definition at line 94 of file particle_system.hpp.

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

Definition at line 97 of file particle_system.hpp.

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

Definition at line 96 of file particle_system.hpp.

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

Definition at line 89 of file particle_system.hpp.

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

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:

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

Implements ParticleSystem.

Definition at line 51 of file smoke.cpp.

{
    sgSetVec4 ( p -> m_col, 1, 1, 1, 1 ) ; /* initially white */
    sgSetVec3 ( p -> m_pos, 0, 0, 0 ) ;    /* start off on the ground */
    sgSetVec3 ( p -> m_vel, 0, 0, 0 ) ;
    sgSetVec3 ( p -> m_acc, 0, 0, 2.0f ) ; /* Gravity */
    p -> m_size = .5f;
    p -> m_time_to_live = 0.5 ;            /* Droplets evaporate after 5 seconds */

    const sgCoord* POS = m_kart->getCoord();
    const btVector3 VEL = m_kart->getVelocity();

    const float X_DIRECTION = sgCos (POS->hpr[0] - 90.0f); // Point at the rear
    const float Y_DIRECTION = sgSin (POS->hpr[0] - 90.0f); // Point at the rear

    sgCopyVec3 (p->m_pos, POS->xyz);

    p->m_pos[0] += X_DIRECTION * 0.7f;
    p->m_pos[1] += Y_DIRECTION * 0.7f;

    const float ABS_VEL = sqrt((VEL.getX() * VEL.getX()) + (VEL.getY() * VEL.getY()));

    p->m_vel[0] = X_DIRECTION * -ABS_VEL/2;
    p->m_vel[1] = Y_DIRECTION * -ABS_VEL/2;

    p->m_vel[0] += sgCos ((float)(rand()%180));
    p->m_vel[1] += sgSin ((float)(rand()%180));
    p->m_vel[2] += sgSin ((float)(rand()%100));

    getBSphere () -> setCenter ( POS->xyz[0], POS->xyz[1], POS->xyz[2] ) ;
}   // particle_create

Here is the call graph for this function:

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

Implements ParticleSystem.

Definition at line 96 of file smoke.cpp.

{}   // particle_delete
void Smoke::particle_update ( float  deltaTime,
int  index,
Particle p 
) [virtual]

Implements ParticleSystem.

Definition at line 84 of file smoke.cpp.

{
    particle->m_size    += delta*2.0f;
    particle->m_col[3]  -= delta * 2.0f;

    particle->m_pos[0] += particle->m_vel[0] * delta;
    particle->m_pos[1] += particle->m_vel[1] * delta;
    particle->m_pos[2] += particle->m_vel[2] * delta;
}  // particle_update
void ParticleSystem::recalcBSphere ( ) [inherited]

Definition at line 78 of file particle_system.cpp.

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

Definition at line 93 of file particle_system.hpp.

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

Definition at line 88 of file particle_system.hpp.

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

Reimplemented from ParticleSystem.

Definition at line 36 of file smoke.cpp.

{
#if 0
    std::cout << "BSphere: r:" << getBSphere()->radius
    << " ("  << getBSphere()->center[0]
    << ", "  << getBSphere()->center[1]
    << ", "  << getBSphere()->center[2]
    << ")"
    << std::endl;
#endif
    getBSphere () -> setRadius ( 1000.0f ) ;
    ParticleSystem::update(t);
}   // update

Here is the caller graph for this function:


Member Data Documentation

Kart* Smoke::m_kart [private]

Definition at line 31 of file smoke.hpp.


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