Back to index

supertuxkart  0.5+dfsg1
smoke.cpp
Go to the documentation of this file.
00001 
00002 //  $Id: dust_cloud.cpp 1681 2008-04-09 13:52:48Z hikerstk $
00003 //
00004 //  SuperTuxKart - a fun racing game with go-kart
00005 //  Copyright (C) 2006 SuperTuxKart-Team
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 2
00010 //  of the License, or (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 #include "smoke.hpp"
00022 #include "kart.hpp"
00023 
00024 Smoke::Smoke(Kart* kart_,
00025                                        int num, float _create_rate, int _ttf,
00026                                        float sz, float bsphere_size)
00027         : ParticleSystem (num, _create_rate, _ttf, sz, bsphere_size),
00028         m_kart(kart_)
00029 {
00030     getBSphere () -> setCenter ( 0, 0, 0 ) ;
00031     getBSphere () -> setRadius ( 1000.0f ) ;
00032     dirtyBSphere();
00033 }   // KartParticleSystem
00034 
00035 //-----------------------------------------------------------------------------
00036 void Smoke::update ( float t )
00037 {
00038 #if 0
00039     std::cout << "BSphere: r:" << getBSphere()->radius
00040     << " ("  << getBSphere()->center[0]
00041     << ", "  << getBSphere()->center[1]
00042     << ", "  << getBSphere()->center[2]
00043     << ")"
00044     << std::endl;
00045 #endif
00046     getBSphere () -> setRadius ( 1000.0f ) ;
00047     ParticleSystem::update(t);
00048 }   // update
00049 
00050 //-----------------------------------------------------------------------------
00051 void Smoke::particle_create(int, Particle *p)
00052 {
00053     sgSetVec4 ( p -> m_col, 1, 1, 1, 1 ) ; /* initially white */
00054     sgSetVec3 ( p -> m_pos, 0, 0, 0 ) ;    /* start off on the ground */
00055     sgSetVec3 ( p -> m_vel, 0, 0, 0 ) ;
00056     sgSetVec3 ( p -> m_acc, 0, 0, 2.0f ) ; /* Gravity */
00057     p -> m_size = .5f;
00058     p -> m_time_to_live = 0.5 ;            /* Droplets evaporate after 5 seconds */
00059 
00060     const sgCoord* POS = m_kart->getCoord();
00061     const btVector3 VEL = m_kart->getVelocity();
00062 
00063     const float X_DIRECTION = sgCos (POS->hpr[0] - 90.0f); // Point at the rear
00064     const float Y_DIRECTION = sgSin (POS->hpr[0] - 90.0f); // Point at the rear
00065 
00066     sgCopyVec3 (p->m_pos, POS->xyz);
00067 
00068     p->m_pos[0] += X_DIRECTION * 0.7f;
00069     p->m_pos[1] += Y_DIRECTION * 0.7f;
00070 
00071     const float ABS_VEL = sqrt((VEL.getX() * VEL.getX()) + (VEL.getY() * VEL.getY()));
00072 
00073     p->m_vel[0] = X_DIRECTION * -ABS_VEL/2;
00074     p->m_vel[1] = Y_DIRECTION * -ABS_VEL/2;
00075 
00076     p->m_vel[0] += sgCos ((float)(rand()%180));
00077     p->m_vel[1] += sgSin ((float)(rand()%180));
00078     p->m_vel[2] += sgSin ((float)(rand()%100));
00079 
00080     getBSphere () -> setCenter ( POS->xyz[0], POS->xyz[1], POS->xyz[2] ) ;
00081 }   // particle_create
00082 
00083 //-----------------------------------------------------------------------------
00084 void Smoke::particle_update (float delta, int,
00085         Particle * particle)
00086 {
00087     particle->m_size    += delta*2.0f;
00088     particle->m_col[3]  -= delta * 2.0f;
00089 
00090     particle->m_pos[0] += particle->m_vel[0] * delta;
00091     particle->m_pos[1] += particle->m_vel[1] * delta;
00092     particle->m_pos[2] += particle->m_vel[2] * delta;
00093 }  // particle_update
00094 
00095 //-----------------------------------------------------------------------------
00096 void Smoke::particle_delete (int , Particle* )
00097 {}   // particle_delete
00098