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
beam.cpp
Go to the documentation of this file.
1 #include "vegastrike.h"
2 #include <vector>
3 #include "beam.h"
4 #include "unit_generic.h"
5 #include "gfx/aux_texture.h"
6 #include "gfx/decalqueue.h"
7 using std::vector;
8 #include "audiolib.h"
9 #include "configxml.h"
10 #include "images.h"
11 
13 {
18  BeamDrawContext( const Matrix &a, GFXVertexList *vl, Beam *b ) : m( a )
19  , vlist( vl )
20  , beam( b ) {}
21 };
22 
24 static vector< vector< BeamDrawContext > >beamdrawqueue;
25 
26 Beam::Beam( const Transformation &trans, const weapon_info &clne, void *own, Unit *firer, int sound ) : vlist( NULL )
27  , Col( clne.r, clne.g, clne.b, clne.a )
28 {
29  VSCONSTRUCT2( 'B' )
30  listen_to_owner = false; //warning this line of code is also present in beam_server.cpp change one, change ALL
31 #ifdef PERBOLTSOUND
32  sound = AUDCreateSound( clne.sound, true );
33 #else
34  this->sound = sound;
35 #endif
36  decal = beamdecals.AddTexture( clne.file.c_str(), TRILINEAR );
37  if ( decal >= beamdrawqueue.size() )
38  beamdrawqueue.push_back( vector< BeamDrawContext > () );
39  Init( trans, clne, own, firer );
40  impact = UNSTABLE;
41 }
42 
44 {
46 #ifdef PERBOLTSOUND
47  AUDDeleteSound( sound );
48 #endif
49 #ifdef BEAMCOLQ
50  RemoveFromSystem( true );
51 #endif
52  //DO NOT DELETE - shared vlist
53  //delete vlist;
54  beamdecals.DelTexture( decal );
55 }
56 
57 extern void AdjustMatrixToTrackTarget( Matrix &mat, const Vector &vel, Unit *target, float speed, bool lead, float cone );
58 
59 void Beam::Draw( const Transformation &trans, const Matrix &m, Unit *targ, float tracking_cone )
60 {
61  //hope that the correct transformation is on teh stack
62  if (curthick == 0)
63  return;
64  Matrix cumulative_transformation_matrix;
65  local_transformation.to_matrix( cumulative_transformation_matrix );
66  Transformation cumulative_transformation = local_transformation;
67  cumulative_transformation.Compose( trans, m );
68  cumulative_transformation.to_matrix( cumulative_transformation_matrix );
69  AdjustMatrixToTrackTarget( cumulative_transformation_matrix, Vector( 0, 0, 0 ), targ, speed, false, tracking_cone );
70 #ifdef PERFRAMESOUND
71  AUDAdjustSound( sound, cumulative_transformation.position, speed
72  *Vector( cumulative_transformation_matrix[8], cumulative_transformation_matrix[9],
73  cumulative_transformation_matrix[10] ) );
74 #endif
75  AUDSoundGain( sound, curthick*curthick/(thickness*thickness) );
76 
77  beamdrawqueue[decal].push_back( BeamDrawContext( cumulative_transformation_matrix, vlist, this ) );
78 }
79 
81 {
83  GFXDisable( CULLFACE ); //don't want lighting on this baby
86  static bool blendbeams = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "BlendGuns", "true" ) );
87  GFXBlendMode( ONE, blendbeams ? ONE : ZERO );
88 
92  for (unsigned int decal = 0; decal < beamdrawqueue.size(); decal++) {
93  Texture *tex = beamdecals.GetTexture( decal );
94  if (tex) {
95  tex->MakeActive( 0 );
97  GFXToggleTexture( true, 0 );
98  if ( beamdrawqueue[decal].size() ) {
99  while ( beamdrawqueue[decal].size() ) {
100  c = beamdrawqueue[decal].back();
101  beamdrawqueue[decal].pop_back();
102 
103  c.beam->RecalculateVertices( c.m );
104  GFXLoadMatrixModel( c.m );
105  c.vlist->DrawOnce();
106  }
107  }
108  }
109  }
111  GFXEnable( CULLFACE );
112  GFXDisable( LIGHTING );
113  GFXPopBlendMode();
114 }
115