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.cpp
Go to the documentation of this file.
1 #include "cmd/unit_generic.h"
2 #include "halo.h"
3 #include "gfxlib.h"
4 #include "vegastrike.h"
5 #include "vs_globals.h"
6 #include "aux_texture.h"
7 #include "decalqueue.h"
8 #include "config_xml.h"
9 #include "xml_support.h"
10 #include "point_to_cam.h"
12 static vector< GFXQuadList* >halodrawqueue;
13 
14 Halo::Halo( const char *texture, const GFXColor &col, const QVector &pos, float sizx, float sizy )
15 {
16  string texname( texture );
17  position = pos;
18  sizex = sizx;
19  sizey = sizy;
20  decal = halodecal.AddTexture( texture, MIPMAP );
21  if ( ( (unsigned int) decal ) >= halodrawqueue.size() )
22  halodrawqueue.push_back( new GFXQuadList( GFXTRUE ) );
23  GFXColorVertex coltmp[4];
24  coltmp[0].SetColor( col );
25  coltmp[1].SetColor( col );
26  coltmp[2].SetColor( col );
27  coltmp[3].SetColor( col );
28 
29  quadnum = halodrawqueue[decal]->AddQuad( NULL, coltmp );
30 }
31 
33 {
34  halodrawqueue[decal]->DelQuad( quadnum );
35  if ( halodecal.DelTexture( decal ) ) {
36  delete halodrawqueue[decal]; //deletes the quad
37  halodrawqueue[decal] = NULL;
38  }
39 }
40 
41 void Halo::Draw( const Transformation &quat, const Matrix &m, float alpha )
42 {
43  Vector p, q, r;
44  QVector pos;
45  static float HaloOffset = XMLSupport::parse_float( vs_config->getVariable( "graphics", "HaloOffset", ".1" ) );
46  pos = position.Transform( m );
47  float wid = sizex;
48  float hei = sizey;
49  static bool far_shine =
50  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_star_glow_halo",
51  "false" ) ) || XMLSupport::parse_bool(
52  vs_config->getVariable( "graphics", "HaloFarDraw", "false" ) );
53  CalculateOrientation( pos, p, q, r, wid, hei, HaloOffset, far_shine, NULL );
54  p = p*wid;
55  r = -r;
56  q = q*hei;
57  //offset = r*(sizex>sizey?sizex:sizey); //screws up cus of perspective
58  GFXVertex tmp[4] = {
59  GFXVertex( pos-(p+q).Cast(), r, 0, 1 ),
60  GFXVertex( pos+(p-q).Cast(), r, 1, 1 ),
61  GFXVertex( pos+(p+q).Cast(), r, 1, 0 ),
62  GFXVertex( pos-(p-q).Cast(), r, 0, 0 )
63  };
64  halodrawqueue[decal]->ModQuad( quadnum, tmp, alpha );
65 }
66 void Halo::SetColor( const GFXColor &col )
67 {
68  GFXColorVertex coltmp[4];
69  coltmp[0].SetColor( col );
70  coltmp[1].SetColor( col );
71  coltmp[2].SetColor( col );
72  coltmp[3].SetColor( col );
73 
74  halodrawqueue[decal]->ModQuad( quadnum, coltmp );
75 }
76 
78 {
82  GFXBlendMode( ONE, ONE );
86  for (unsigned int decal = 0; decal < halodrawqueue.size(); decal++)
87  if ( halodecal.GetTexture( decal ) ) {
88  halodecal.GetTexture( decal )->MakeActive();
89  halodrawqueue[decal]->Draw();
90  }
95 }
96