Back to index

supertuxkart  0.5+dfsg1
particle_system.hpp
Go to the documentation of this file.
00001 /*
00002      $Id: particle_system.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00003      PLIB - A Suite of Portable Game Libraries
00004      Copyright (C) 1998,2002  Steve Baker
00005 
00006      This library is free software; you can redistribute it and/or
00007      modify it under the terms of the GNU Library General Public
00008      License as published by the Free Software Foundation; either
00009      version 2 of the License, or (at your option) any later version.
00010 
00011      This library is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014      Library General Public License for more details.
00015 
00016      You should have received a copy of the GNU Library General Public
00017      License along with this library; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 
00020      For further information visit http://plib.sourceforge.net                  */
00021 
00022 #include <plib/ssg.h>
00023 
00024 class Particle
00025 {
00026 public:
00027 
00028     sgVec4 m_col ;
00029     sgVec3 m_pos ;
00030     sgVec3 m_vel ;
00031     sgVec3 m_acc ;
00032 
00033     float m_size ;
00034 
00035     float m_time_to_live ;
00036     void *m_user_data ;
00037 
00038     void update ( float dt )
00039     {
00040         sgAddScaledVec3 ( m_vel, m_acc, dt ) ;
00041         sgAddScaledVec3 ( m_pos, m_vel, dt ) ;
00042         m_time_to_live -= dt ;
00043     }
00044 
00045     Particle ()
00046     {
00047         sgSetVec4 ( m_col, 1, 1, 1, 1 ) ;
00048         sgZeroVec3 ( m_pos ) ;
00049         sgZeroVec3 ( m_vel ) ;
00050         sgZeroVec3 ( m_acc ) ;
00051         m_time_to_live = 0 ;
00052         m_user_data = 0 ;
00053         m_size = 1.0f ;
00054     }
00055 
00056 } ;
00057 
00058 
00059 class ParticleSystem ;
00060 
00061 class ParticleSystem : public ssgVtxTable
00062 {
00063     int m_num_particles  ;
00064     int m_num_verts      ;
00065     int m_turn_to_face   ;
00066     int m_num_active     ;
00067     Particle* m_particles ;
00068 
00069     float m_create_error ;
00070     float m_create_rate ;
00071 
00072     float m_size ;
00073 
00074 public:
00075 
00076     ParticleSystem ( int num, float _create_rate, int _turn_to_face,
00077                      float sz, float bsphere_size);
00078     virtual ~ParticleSystem () ;
00079     virtual void update ( float t ) ;
00080 
00081     virtual void particle_create( int index, Particle *p ) = 0;
00082     virtual void particle_update( float deltaTime, int index, Particle *p ) = 0;
00083     virtual void particle_delete( int index, Particle* p ) = 0;
00084 
00085     void init(int initial_num);
00086     void recalcBSphere();
00087 
00088     void setSize ( float sz ) { m_size = sz ; }
00089     float getSize () const { return m_size ; }
00090 
00091     void draw_geometry () ;
00092 
00093     void  setCreationRate ( float cr ) { m_create_rate = cr ; }
00094     float getCreationRate () const { return m_create_rate ; }
00095 
00096     int getNumParticles       () const { return m_num_particles ; }
00097     int getNumActiveParticles () const { return m_num_active    ; }
00098 } ;
00099 
00100 /* EOF */