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
HaloSystem Class Reference

#include <halo_system.h>

Public Member Functions

virtual ~HaloSystem ()
 
 HaloSystem ()
 
QVectorHaloLoc (unsigned int i)
 
unsigned int numhalo ()
 
unsigned int AddHalo (const char *filename, const QVector &loc, const Vector &size, const GFXColor &col, std::string halo_type, float activation_accel)
 
bool ShouldDraw (const Matrix &trans, const Vector &velocity, const Vector &accel, float maxaccel, float maxvelocity)
 
void Draw (const Matrix &trans, const Vector &scale, int halo_alpha, float nebdist, float hullpercentage, const Vector &velocity, const Vector &accel, float maxaccel, float maxvelocity, int faction)
 
void SetPosition (unsigned int which, const QVector &loc)
 
void SetSize (unsigned int which, const Vector &scale)
 
int NumHalos () const
 

Detailed Description

Definition at line 23 of file halo_system.h.

Constructor & Destructor Documentation

HaloSystem::~HaloSystem ( )
virtual

Definition at line 307 of file halo_system.cpp.

References i, and VSDESTRUCT2.

308 {
309 #ifdef CAR_SIM
310  for (unsigned int i = 0; i < ani.size(); i++)
311  delete ani[i];
312  ani.clear();
313 #endif
315  if (mesh)
316  delete mesh;
317 }
HaloSystem::HaloSystem ( )

Definition at line 99 of file halo_system.cpp.

References VSCONSTRUCT2.

100 {
101  VSCONSTRUCT2( 'h' )
102  mesh = NULL;
103  activation = 0;
104  oscale = 0;
105  sparkle_accum = 0;
106 }

Member Function Documentation

unsigned int HaloSystem::AddHalo ( const char *  filename,
const QVector loc,
const Vector size,
const GFXColor col,
std::string  halo_type,
float  activation_accel 
)

Definition at line 114 of file halo_system.cpp.

References FactionUtil::GetNeutralFaction(), VegaConfig::getVariable(), Mesh::LoadMesh(), MIPMAP, FactionUtil::neutralfac, XMLSupport::parse_float(), CAR::type_map(), Vector, and vs_config.

120 {
121 #ifdef CAR_SIM
122  ani.push_back( new Animation( "flare6.ani", 1, .1, MIPMAP, true, true, col ) );
123  ani.back()->SetDimensions( size.i, size.j );
124  ani.back()->SetPosition( loc );
125  halo_type.push_back( CAR::type_map.lookup( type ) ); //should default to headlights
126 #endif
127  if (mesh == NULL) {
129  mesh = Mesh::LoadMesh( ( string( filename ) ).c_str(), Vector( 1, 1, 1 ), neutralfac, NULL );
130  static float gs = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
131  activation = activation_accel*gs;
132  }
133  static float engine_scale = XMLSupport::parse_float( vs_config->getVariable( "graphics", "engine_radii_scale", ".4" ) );
134  static float engine_length = XMLSupport::parse_float( vs_config->getVariable( "graphics", "engine_length_scale", "1.25" ) );
135 
136  halo.push_back( MyIndHalo( loc, Vector( size.i*engine_scale, size.j*engine_scale, size.k*engine_length ) ) );
137  return halo.size()-1;
138 }
void HaloSystem::Draw ( const Matrix trans,
const Vector scale,
int  halo_alpha,
float  nebdist,
float  hullpercentage,
const Vector velocity,
const Vector accel,
float  maxaccel,
float  maxvelocity,
int  faction 
)

Definition at line 198 of file halo_system.cpp.

References CAR::BRAKE, DoParticles(), Mesh::Draw(), StarSystemGent::faction, CAR::FORWARD_BLINKEN, GetElapsedTime(), Matrix::getR(), VegaConfig::getVariable(), HaloAccelSmooth(), CAR::HEADLIGHTS, i, int, CAR::LEFT_BLINKEN, CAR::LEFTBLINK, CAR::ON_NO_BLINKEN, Matrix::p, XMLSupport::parse_bool(), XMLSupport::parse_float(), CAR::REVERSE, CAR::RIGHT_BLINKEN, CAR::RIGHTBLINK, Mesh::rSize(), CAR::RUNNINGLIGHTS, ScaleMatrix(), CAR::SIREN, CAR::SIREN_BLINKEN, UniverseUtil::sqrt(), test, Transform(), Vector, and vs_config.

208 {
209 #ifdef CAR_SIM
210  for (unsigned int i = 0; i < ani.size(); ++i) {
211  int bitwise = scale.j;
212  int typ = 0;
213 #ifdef CAR_SIM
214  typ = halo_type[i];
215 #endif
216  bool drawnow = (typ == CAR::RUNNINGLIGHTS);
217  if ( (typ == CAR::BRAKE && scale.k < .01 && scale.k > -.01) )
218  drawnow = true;
219  if ( (typ == CAR::REVERSE && scale.k <= -.01) )
220  drawnow = true;
221  if (typ == CAR::HEADLIGHTS)
222  if ( scale.j >= CAR::ON_NO_BLINKEN
223  || ( bitwise < CAR::ON_NO_BLINKEN && bitwise > 0 && (bitwise&CAR::FORWARD_BLINKEN) ) )
224  drawnow = true;
225  if (typ == CAR::SIREN)
226  if ( (bitwise > 0) && ( (bitwise >= CAR::ON_NO_BLINKEN) || (bitwise&CAR::SIREN_BLINKEN) ) )
227  drawnow = true;
228  float blink_prob = .8;
229  if (typ == CAR::RIGHTBLINK)
230  if ( (bitwise > 0) && (bitwise < CAR::ON_NO_BLINKEN) && (bitwise&CAR::RIGHT_BLINKEN) )
231  if (rand() < RAND_MAX*blink_prob)
232  drawnow = true;
233  if (typ == CAR::LEFTBLINK)
234  if ( (bitwise > 0) && (bitwise < CAR::ON_NO_BLINKEN) && (bitwise&CAR::LEFT_BLINKEN) )
235  if (rand() < RAND_MAX*blink_prob)
236  drawnow = true;
237  if (drawnow) {
238  ani[i]->SetPosition( Transform( trans, halo[i].loc ) );
239  ani[i]->SetDimensions( scale.i, scale.i );
240  ani[i]->Draw();
241  }
242  }
243 #else
244  if (halo_alpha >= 0) {
245  halo_alpha /= 2;
246  if ( (halo_alpha&0x1) == 0 )
247  halo_alpha += 1;
248  }
249  static bool halos_by_velocity = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "halos_by_velocity", "false" ) );
250 
251  Vector thrustvector = trans.getR().Normalize();
252  if (maxaccel <= 0) maxaccel = 1;
253  if (maxvelocity <= 0) maxvelocity = 1;
254  float value, maxvalue, minvalue;
255  if (halos_by_velocity) {
256  value = velocity.Dot( thrustvector );
257  maxvalue = sqrt( maxvelocity );
258  minvalue = activation;
259  } else {
260  oscale = HaloAccelSmooth( accel.Dot( thrustvector )/maxaccel, oscale, 1.0f );
261  value = oscale;
262  maxvalue = 1.0f;
263  minvalue = activation/maxaccel;
264  }
265  if ( (value > minvalue) && (scale.k > 0) ) {
266  vector< MyIndHalo >::iterator i = halo.begin();
267  for (; i != halo.end(); ++i) {
268  Matrix m = trans;
269  ScaleMatrix( m, Vector( scale.i*i->size.i, scale.j*i->size.j, scale.k*i->size.k*value/maxvalue ) );
270  m.p = Transform( trans, i->loc );
271  static float percentColorChange=XMLSupport::parse_float(vs_config->getVariable("graphics","percent_afterburner_color_change",".5"));
272  static float abRedness=XMLSupport::parse_float(vs_config->getVariable("graphics","afterburner_color_red","1.0"));
273  static float abGreenness=XMLSupport::parse_float(vs_config->getVariable("graphics","afterburner_color_green","0.0"));
274  static float abBlueness=XMLSupport::parse_float(vs_config->getVariable("graphics","afterburner_color_blue","0.0"));
275  static float percentRedness=XMLSupport::parse_float(vs_config->getVariable("graphics","engine_color_red","1.0"));
276  static float percentGreenness=XMLSupport::parse_float(vs_config->getVariable("graphics","engine_color_green","1.0"));
277  static float percentBlueness=XMLSupport::parse_float(vs_config->getVariable("graphics","engine_color_blue","1.0"));
278  GFXColor blend=GFXColor(percentRedness,percentGreenness,percentBlueness,1);
279 
280  if (value>maxvalue*percentColorChange) {
281  float test=value-maxvalue*percentColorChange;
282  test/=maxvalue*percentColorChange;
283  if (!(test<1.0)) test=1.0;
284  blend=GFXColor(abRedness*test+percentRedness*(1.0-test),abGreenness*test+percentGreenness*(1.0-test),abBlueness*test+percentBlueness*(1.0-test),1.0);
285 
286  }
287  MeshFX xtraFX=MeshFX(1.0,1.0,
288  true,
289  GFXColor(1,1,1,1),
290  GFXColor(1,1,1,1),
291  GFXColor(1,1,1,1),
292  blend);
293 
294  mesh->Draw( 50000000000000.0, m, 1, halo_alpha, nebdist, 0,false,&xtraFX );
295  if (hullpercent < .99) {
296  static float sparklerate = XMLSupport::parse_float( vs_config->getVariable( "graphics", "halosparklerate", "20" ) );
297  sparkle_accum += GetElapsedTime()*sparklerate;
298  int spawn = (int) (sparkle_accum);
299  sparkle_accum -= spawn;
300  while (spawn-- > 0)
301  DoParticles( m.p, hullpercent, velocity, mesh->rSize()*scale.i, mesh->rSize()*scale.i, faction );
302  }
303  }
304  }
305 #endif
306 }
QVector& HaloSystem::HaloLoc ( unsigned int  i)
inline

Definition at line 38 of file halo_system.h.

39  {
40  return halo[i].loc;
41  }
unsigned int HaloSystem::numhalo ( )
inline

Definition at line 42 of file halo_system.h.

43  {
44  return halo.size();
45  }
int HaloSystem::NumHalos ( ) const
inline

Definition at line 67 of file halo_system.h.

68  {
69  return halo.size();
70  }
void HaloSystem::SetPosition ( unsigned int  which,
const QVector loc 
)

Definition at line 147 of file halo_system.cpp.

148 {
149  halo[which].loc = loc;
150 #ifdef CAR_SIM
151  ani[which]->SetPosition( loc );
152 #endif
153 }
void HaloSystem::SetSize ( unsigned int  which,
const Vector scale 
)

Definition at line 140 of file halo_system.cpp.

References size.

141 {
142  halo[which].size = size;
143 #ifdef CAR_SIM
144  ani[which]->SetDimensions( size.i, size.j );
145 #endif
146 }
bool HaloSystem::ShouldDraw ( const Matrix trans,
const Vector velocity,
const Vector accel,
float  maxaccel,
float  maxvelocity 
)

Definition at line 177 of file halo_system.cpp.

References Matrix::getR(), VegaConfig::getVariable(), HaloAccelSmooth(), XMLSupport::parse_bool(), Vector, and vs_config.

182 {
183  static bool halos_by_velocity = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "halos_by_velocity", "false" ) );
184  if (halo.size() == 0)
185  return false; //Any doubt?
186 
187  Vector thrustvector = trans.getR().Normalize();
188  if (halos_by_velocity) {
189  float linvel = velocity.Dot( thrustvector );
190  return linvel > activation;
191  } else {
192  if (maxaccel <= 0) maxaccel = 1;
193  if (maxvelocity <= 0) maxvelocity = 1;
194  float linaccel = HaloAccelSmooth( accel.Dot( thrustvector )/maxaccel, oscale, 1.0f );
195  return linaccel > activation*maxaccel;
196  }
197 }

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