1 /* 2 PLIB - A Suite of Portable Game Libraries 3 Copyright (C) 1998,2002 Steve Baker 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 For further information visit http://plib.sourceforge.net */ 20 21 22 23 class ssgaParticle 24 { 25 public: 26 27 sgVec4 col ; 28 sgVec3 pos ; 29 sgVec3 vel ; 30 sgVec3 acc ; 31 32 float size ; 33 34 float time_to_live ; 35 void *userData ; 36 update(float dt)37 void update ( float dt ) 38 { 39 sgAddScaledVec3 ( vel, acc, dt ) ; 40 sgAddScaledVec3 ( pos, vel, dt ) ; 41 time_to_live -= dt ; 42 } 43 ssgaParticle()44 ssgaParticle () 45 { 46 sgSetVec4 ( col, 1, 1, 1, 1 ) ; 47 sgZeroVec3 ( pos ) ; 48 sgZeroVec3 ( vel ) ; 49 sgZeroVec3 ( acc ) ; 50 time_to_live = 0 ; 51 userData = NULL ; 52 size = 1.0f ; 53 } 54 55 } ; 56 57 58 class ssgaParticleSystem ; 59 60 61 typedef void (* ssgaParticleCreateFunc) ( ssgaParticleSystem *ps, 62 int index, 63 ssgaParticle *p ) ; 64 65 typedef void (* ssgaParticleUpdateFunc) ( float deltaTime, 66 ssgaParticleSystem *ps, 67 int index, 68 ssgaParticle *p ) ; 69 70 typedef void (* ssgaParticleDeleteFunc) ( ssgaParticleSystem *ps, 71 int index, 72 ssgaParticle *p ) ; 73 74 class ssgaParticleSystem : public ssgVtxTable 75 { 76 int num_particles ; 77 int num_verts ; 78 int turn_to_face ; 79 int num_active ; 80 ssgaParticle *particle ; 81 82 float create_error ; 83 float create_rate ; 84 85 float size ; 86 87 ssgaParticleCreateFunc particle_create ; 88 ssgaParticleUpdateFunc particle_update ; 89 ssgaParticleDeleteFunc particle_delete ; 90 91 public: 92 93 ssgaParticleSystem ( int num, int initial_num, 94 float _create_rate, int _turn_to_face, 95 float sz, float bsphere_size, 96 ssgaParticleCreateFunc _particle_create, 97 ssgaParticleUpdateFunc _particle_update = NULL, 98 ssgaParticleDeleteFunc _particle_delete = NULL ) ; 99 100 virtual ~ssgaParticleSystem () ; 101 virtual void update ( float t ) ; 102 setSize(float sz)103 void setSize ( float sz ) { size = sz ; } getSize()104 float getSize () { return size ; } 105 106 void draw_geometry () ; 107 setCreationRate(float cr)108 void setCreationRate ( float cr ) { create_rate = cr ; } getCreationRate()109 float getCreationRate () { return create_rate ; } 110 getNumParticles()111 int getNumParticles () { return num_particles ; } getNumActiveParticles()112 int getNumActiveParticles () { return num_active ; } 113 } ; 114 115 116