Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleTrail Class Reference

#include <particle.h>

Public Member Functions

 ParticleTrail (unsigned int max)
 
void DrawAndUpdate ()
 
void AddParticle (const ParticlePoint &, const Vector &, float size)
 
void ChangeMax (unsigned int max)
 

Detailed Description

Definition at line 18 of file particle.h.

Constructor & Destructor Documentation

ParticleTrail::ParticleTrail ( unsigned int  max)
inline

Definition at line 23 of file particle.h.

References ChangeMax().

23  : ParticleTrail( unsigned int max )
24  {
25  ChangeMax( max );
26  }

Member Function Documentation

void ParticleTrail::AddParticle ( const ParticlePoint P,
const Vector V,
float  size 
)

Definition at line 172 of file particle.cpp.

References ParticlePoint::size, size, and V.

Referenced by UniverseUtil::addParticle(), and DoParticles().

173 {
174  if (particle.size() > maxparticles) {
175  vector< Vector >::iterator vel = particleVel.begin();
176  vector< ParticlePoint >::iterator p = particle.begin();
177  size_t off = ( (size_t) rand() )%particle.size();
178  vel += off;
179  p += off;
180  *p = P;
181  (*p).size = size;
182  *vel = V;
183  } else {
184  particle.push_back( P );
185  particle.back().size = size;
186  particleVel.push_back( V );
187  }
188 }
void ParticleTrail::ChangeMax ( unsigned int  max)

Definition at line 12 of file particle.cpp.

References max().

Referenced by ParticleTrail().

13 {
14  this->maxparticles = max;
15 }
void ParticleTrail::DrawAndUpdate ( )

Definition at line 90 of file particle.cpp.

References _Universe, Universe::AccessCamera(), CULLFACE, DEPTHWRITE, GetElapsedTime(), Camera::GetPosition(), Camera::GetPQR(), VegaConfig::getVariable(), GFXBegin(), GFXBlendMode(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLoadIdentity(), GFXPOINT, GFXPointSize(), GFXQUAD, GFXTranslateModel(), gl_options, index, INVSRCALPHA, LIGHTING, Texture::MakeActive(), MODEL, ONE, XMLSupport::parse_bool(), XMLSupport::parse_float(), R, gl_options_t::smooth_points, SRCALPHA, BaseUtil::Texture(), TEXTURE0, TEXTURE1, v, Vector, vs_config, and ZERO.

Referenced by GameStarSystem::Draw().

91 {
92  static bool use_points = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "point_sparkles", "false" ) );
93  Vector P, Q;
94  {
95  Vector R;
96  _Universe->AccessCamera()->GetPQR( P, Q, R );
97  static float particlesize = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparksize", "1" ) );
98  P *= particlesize;
99  Q *= particlesize;
100  }
101 
102  vector< Vector >::iterator v = particleVel.begin();
103  vector< ParticlePoint >::iterator p = particle.begin();
104  if (use_points) {
105  GFXDisable( TEXTURE0 );
106  GFXDisable( CULLFACE );
107  static float psiz = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparkesize", "1.5" ) );
108 
109  GFXPointSize( psiz );
110 
111  static bool psmooth = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "sparkesmooth", "false" ) );
112  if (psmooth && gl_options.smooth_points)
113  glEnable( GL_POINT_SMOOTH );
114  } else {
115  GFXEnable( TEXTURE0 );
116  GFXDisable( TEXTURE1 );
118  GFXDisable( CULLFACE );
119  static string s = vs_config->getVariable( "graphics", "sparkletexture", "supernova.bmp" );
120  static Texture *t = new Texture( s.c_str() );
121 
122  t->MakeActive();
123  }
124  GFXDisable( LIGHTING );
127  static bool pblend = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "sparkeblend", "false" ) );
128  //GFXBlendMode(ONE,ZERO);
129  if (use_points) {
130  if (pblend)
132  else
133  GFXBlendMode( ONE, ZERO );
134  GFXBegin( GFXPOINT );
135  } else {
136  GFXBlendMode( ONE, ONE );
137  GFXBegin( GFXQUAD );
138  }
139  double mytime = GetElapsedTime();
140  while ( p != particle.end() ) {
141  if ( !(*p).Draw( *v, mytime, P, Q ) ) {
142  vector< Vector >::iterator vlast = particleVel.end();
143  vector< ParticlePoint >::iterator plast = particle.end();
144  --vlast;
145  --plast;
146  if (p != plast) {
147  *v = *vlast;
148  *p = *plast;
149  }
150  size_t index = p-particle.begin();
151  size_t indexv = v-particleVel.begin();
152  particle.pop_back();
153  particleVel.pop_back();
154  p = particle.begin()+index;
155  v = particleVel.begin()+indexv; //continue where we left off
156  } else {
157  ++p;
158  ++v;
159  }
160  }
161  GFXEnd();
162  if (use_points) {
163  glDisable( GL_POINT_SMOOTH );
164  GFXPointSize( 1 );
165  } else {
167  GFXDisable( CULLFACE );
168  }
170 }

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