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
halo_system.cpp File Reference
#include <vector>
#include <string>
#include "vec.h"
#include "matrix.h"
#include "cmd/unit_generic.h"
#include "halo_system.h"
#include "universe.h"
#include <stdlib.h>
#include <stdio.h>
#include "vegastrike.h"
#include "mesh.h"
#include "vs_globals.h"
#include "xml_support.h"
#include "config_xml.h"
#include "gfx/particle.h"
#include "lin_time.h"
#include "animation.h"
#include "car_assist.h"
#include "cmd/collide2/CSopcodecollider.h"
#include "cmd/unit_collide.h"

Go to the source code of this file.

Macros

#define HALO_SMOOTHING_UP_FACTOR   (0.02)
 
#define HALO_SMOOTHING_DOWN_FACTOR   (0.01)
 
#define HALO_STEERING_UP_FACTOR   (0.00)
 
#define HALO_STEERING_DOWN_FACTOR   (0.01)
 
#define HALO_STABILIZATION_RANGE   (0.25)
 

Functions

static float ffmax (float a, float b)
 
void DoParticles (QVector pos, float percent, const Vector &velocity, float radial_size, float particle_size, int faction)
 
void LaunchOneParticle (const Matrix &mat, const Vector &vel, unsigned int seed, Unit *mush, float hull, int faction)
 
static float mymin (float a, float b)
 
static float mymax (float a, float b)
 
static float HaloAccelSmooth (float linaccel, float olinaccel, float maxlinaccel)
 

Macro Definition Documentation

#define HALO_SMOOTHING_DOWN_FACTOR   (0.01)

Definition at line 24 of file halo_system.cpp.

Referenced by HaloAccelSmooth().

#define HALO_SMOOTHING_UP_FACTOR   (0.02)

Definition at line 23 of file halo_system.cpp.

Referenced by HaloAccelSmooth().

#define HALO_STABILIZATION_RANGE   (0.25)

Definition at line 27 of file halo_system.cpp.

#define HALO_STEERING_DOWN_FACTOR   (0.01)

Definition at line 26 of file halo_system.cpp.

Referenced by HaloAccelSmooth().

#define HALO_STEERING_UP_FACTOR   (0.00)

Definition at line 25 of file halo_system.cpp.

Referenced by HaloAccelSmooth().

Function Documentation

void DoParticles ( QVector  pos,
float  percent,
const Vector velocity,
float  radial_size,
float  particle_size,
int  faction 
)

Definition at line 33 of file halo_system.cpp.

References GFXColor::a, ParticleTrail::AddParticle(), GFXColor::b, ParticlePoint::col, ffmax(), float, GFXColor::g, FactionUtil::GetSparkColor(), VegaConfig::getVariable(), i, ParticlePoint::loc, XMLSupport::parse_bool(), XMLSupport::parse_float(), particleTrail, QVector, GFXColor::r, UniverseUtil::sqrt(), and vs_config.

Referenced by HaloSystem::Draw(), and LaunchOneParticle().

34 {
35  percent = 1-percent;
36  int i = rand();
37  static float scale = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparklescale", "8" ) );
38  static float sspeed = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparklespeed", ".5" ) );
39  static float flare = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparkleflare", ".15" ) );
40  static float spread = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparklespread", ".04" ) );
41  static float absspeed = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparkleabsolutespeed", ".02" ) );
42  static bool fixed_size = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "sparklefixedsize", "0" ) );
43  if (i < RAND_MAX*percent*scale) {
44  ParticlePoint pp;
45  float r1 = rand()/( (float) RAND_MAX*.5 )-1;
46  float r2 = rand()/( (float) RAND_MAX*.5 )-1;
47  float r3 = rand()/( (float) RAND_MAX*.5 )-1;
48  QVector rand( r1, r2, r3 );
49  pp.loc = pos+rand*radial_size*flare;
50  const float *col = FactionUtil::GetSparkColor( faction );
51  pp.col.r = col[0];
52  pp.col.g = col[1];
53  pp.col.b = col[2];
54  pp.col.a = 1.0f;
55  static float sciz = XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparklesizeenginerelative", ".125" ) );
56  particleTrail.AddParticle( pp, rand*(ffmax(
57  velocity.Magnitude(),
58  absspeed )*spread+absspeed)+velocity*sspeed,
59  fixed_size ? sciz : (sqrt( particle_size )*sciz) );
60  }
61 }
static float ffmax ( float  a,
float  b 
)
static

Definition at line 29 of file halo_system.cpp.

References b.

Referenced by DoParticles().

30 {
31  return a > b ? a : b;
32 }
static float HaloAccelSmooth ( float  linaccel,
float  olinaccel,
float  maxlinaccel 
)
static

Definition at line 162 of file halo_system.cpp.

References GetElapsedTime(), HALO_SMOOTHING_DOWN_FACTOR, HALO_SMOOTHING_UP_FACTOR, HALO_STEERING_DOWN_FACTOR, HALO_STEERING_UP_FACTOR, mymax(), and mymin.

Referenced by HaloSystem::Draw(), and HaloSystem::ShouldDraw().

163 {
164  linaccel = mymax( 0, mymin( maxlinaccel, linaccel ) ); //Clamp input, somehow, sometimes it's not clamped
165  float phase = pow( ( (linaccel > olinaccel) ? HALO_SMOOTHING_UP_FACTOR : HALO_SMOOTHING_DOWN_FACTOR ), GetElapsedTime() );
166  float olinaccel2;
167  if (linaccel > olinaccel)
168  olinaccel2 = mymin( linaccel, olinaccel+maxlinaccel*HALO_STEERING_UP_FACTOR );
169 
170  else
171  olinaccel2 = mymax( linaccel, olinaccel-maxlinaccel*HALO_STEERING_DOWN_FACTOR );
172  linaccel = (1-phase)*linaccel+phase*olinaccel2;
173  linaccel = mymax( 0, mymin( maxlinaccel, linaccel ) );
174  return linaccel;
175 }
void LaunchOneParticle ( const Matrix mat,
const Vector vel,
unsigned int  seed,
Unit mush,
float  hull,
int  faction 
)

Definition at line 63 of file halo_system.cpp.

References Unit::colTrees, done, DoParticles(), StarSystemGent::faction, csOPCODECollider::getNumVertex(), VegaConfig::getVariable(), csOPCODECollider::getVertex(), int, XMLSupport::parse_float(), QVector, collideTrees::rapidColliders, Unit::rSize(), Transform(), collideTrees::usingColTree(), v, and vs_config.

Referenced by GameUnit< UnitType >::Draw().

64 {
65  static float sciz =
66  XMLSupport::parse_float( vs_config->getVariable( "graphics", "sparkleenginesizerelativetoship", "0.1875" ) );
67  if (mush) {
68  bool done = false;
69  collideTrees *colTrees = mush->colTrees;
70  if (colTrees) {
71  if ( colTrees->usingColTree() ) {
72  csOPCODECollider *colTree = colTrees->rapidColliders[0];
73  unsigned int numvert = colTree->getNumVertex();
74  if (numvert) {
75  unsigned int whichvert = seed%numvert;
76  QVector v( colTree->getVertex( whichvert ).Cast() );
77  v = Transform( mat, v );
78  DoParticles( v, hull, vel, 0, mush->rSize()*sciz, faction );
79  done = true;
80  }
81  }
82  }
83  if (!done) {
84  // maybe ray collision?
85  }
86  if (!done) {
87  unsigned int siz = (unsigned int) ( 2*mush->rSize() );
88  if (siz != 0) {
89  QVector v( (seed%siz)-siz/2,
90  (seed%siz)-siz/2,
91  (seed%siz)-siz/2 );
92  DoParticles( v, hull, vel, 0, mush->rSize()*sciz, faction );
93  done = true;
94  }
95  }
96  }
97 }
static float mymax ( float  a,
float  b 
)
static

Definition at line 158 of file halo_system.cpp.

References b.

159 {
160  return a > b ? a : b;
161 }
static float mymin ( float  a,
float  b 
)
static

Definition at line 154 of file halo_system.cpp.

References a.

155 {
156  return a > b ? b : a;
157 }