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

#include <star.h>

Inheritance diagram for SpriteStarVlist:
StarVlist

Public Member Functions

 SpriteStarVlist (int num, float spread, std::string our_system_name, std::string texturename, float size)
 
 ~SpriteStarVlist ()
 
int NumTextures ()
 
bool BeginDrawState (const QVector &center, const Vector &vel, const Vector &angular_vel, bool rotate, bool yawpitch, int whichTexture)
 
void Draw (bool, int whichTexture)
 
void EndDrawState (bool, int whichTexture)
 
- Public Member Functions inherited from StarVlist
 StarVlist (float spread)
 
void UpdateGraphics ()
 
virtual ~StarVlist ()
 
void DrawAll (const QVector &center, const Vector &vel, const Vector &ang_vel, bool rot, bool yawpitch)
 

Additional Inherited Members

- Protected Attributes inherited from StarVlist
float spread
 
Vector newcamr
 
Vector newcamq
 
Vector camr
 
Vector camq
 
double lasttime
 

Detailed Description

Definition at line 67 of file star.h.

Constructor & Destructor Documentation

SpriteStarVlist::SpriteStarVlist ( int  num,
float  spread,
std::string  our_system_name,
std::string  texturename,
float  size 
)

Definition at line 590 of file star.cpp.

References GFXColorVertex::a, AllocVerticesForSystem(), GFXColorVertex::b, BILINEAR, Texture::Clone(), AnimatedTexture::framesPerSecond(), GFXColorVertex::g, GetConstVertex(), VegaConfig::getVariable(), GFXQUAD, i, NEAREST, NUM_ACTIVE_ANIMATIONS, AnimatedTexture::numFrames(), Orthogonize(), XMLSupport::parse_bool(), GFXColorVertex::r, GFXColorVertex::s, AnimatedTexture::setTime(), GFXColorVertex::SetVertex(), size, start, GFXColorVertex::t, BaseUtil::Texture(), Vector, and vs_config.

591  : StarVlist( spread )
592 {
593  int curtexture = 0;
594  vector< AnimatedTexture* >animations;
595  static bool near_stars_alpha = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "near_stars_alpha", "false" ) );
596  for (curtexture = 0; curtexture < NUM_ACTIVE_ANIMATIONS; ++curtexture) {
597  std::string::size_type where = texturenames.find( " " );
598  string texturename = texturenames.substr( 0, where );
599  if (where != string::npos)
600  texturenames = texturenames.substr( where+1 );
601  else texturenames = "";
602  if (texturename.find( ".ani" ) != string::npos) {
603  animations.push_back( new AnimatedTexture( texturename.c_str(), 0, near_stars_alpha ? NEAREST : BILINEAR ) );
604  decal[curtexture] = animations.back();
605  } else if (texturename.length() == 0) {
606  if (curtexture == 0) {
607  decal[curtexture] = new Texture( "white.bmp", 0, near_stars_alpha ? NEAREST : BILINEAR );
608  } else {
609  if ( animations.size() ) {
610  AnimatedTexture *tmp = static_cast< AnimatedTexture* > ( animations[curtexture%animations.size()]->Clone() );
611  int num = tmp->numFrames();
612  if (num) {
613  num = rand()%num;
614  tmp->setTime( num/tmp->framesPerSecond() );
615  }
616  decal[curtexture] = tmp;
617  } else {
618  decal[curtexture] = decal[rand()%curtexture]->Clone();
619  }
620  }
621  } else {
622  decal[curtexture] = new Texture( texturename.c_str() );
623  }
624  }
625  int numVerticesPer = near_stars_alpha ? 4 : 12;
626  GFXColorVertex *tmpvertex = AllocVerticesForSystem( sysnam, this->spread, &num, numVerticesPer );
627  for (int LC = 0; LC < num; LC += numVerticesPer) {
628  int LAST = LC+numVerticesPer-1;
629  for (int i = LC; i <= LAST; ++i) {
630  tmpvertex[i].r = tmpvertex[LAST].r;
631  tmpvertex[i].g = tmpvertex[LAST].g;
632  tmpvertex[i].b = tmpvertex[LAST].b;
633  tmpvertex[i].a = tmpvertex[LAST].a;
634  }
635  Vector I( rand()*2.0/RAND_MAX-1,
636  rand()*2.0/RAND_MAX-1,
637  rand()*2.0/RAND_MAX-1 );
638  Vector J( rand()*2.0/RAND_MAX-1,
639  rand()*2.0/RAND_MAX-1,
640  rand()*2.0/RAND_MAX-1 );
641  Vector K( rand()*2.0/RAND_MAX-1,
642  rand()*2.0/RAND_MAX-1,
643  rand()*2.0/RAND_MAX-1 );
644  if (I.MagnitudeSquared() < .00001)
645  I.i += .5;
646  if (J.MagnitudeSquared() < .00001)
647  J.j += .5;
648  if (K.MagnitudeSquared() < .00001)
649  K.k += .5;
650  Orthogonize( I, J, K );
651  I = I*size;
652  J = J*size;
653  K = K*size;
654  tmpvertex[LC+0].SetVertex( GetConstVertex( tmpvertex[LC+0] )-I+J );
655  tmpvertex[LC+0].s = 0.15625;
656  tmpvertex[LC+0].t = .984375;
657  tmpvertex[LC+1].SetVertex( GetConstVertex( tmpvertex[LC+1] )+I+J );
658  tmpvertex[LC+1].s = .984375;
659  tmpvertex[LC+1].t = .984375;
660  tmpvertex[LC+2].SetVertex( GetConstVertex( tmpvertex[LC+2] )+I-J );
661  tmpvertex[LC+2].s = .984375;
662  tmpvertex[LC+2].t = .015625;
663  tmpvertex[LC+3].SetVertex( GetConstVertex( tmpvertex[LC+3] )-I-J );
664  tmpvertex[LC+3].s = .015625;
665  tmpvertex[LC+3].t = .015625;
666  if (numVerticesPer > 4) {
667  tmpvertex[LC+4].SetVertex( GetConstVertex( tmpvertex[LC+4] )-I+K );
668  tmpvertex[LC+4].s = .015625;
669  tmpvertex[LC+4].t = .984375;
670  tmpvertex[LC+5].SetVertex( GetConstVertex( tmpvertex[LC+5] )+I+K );
671  tmpvertex[LC+5].s = .984375;
672  tmpvertex[LC+5].t = .984375;
673  tmpvertex[LC+6].SetVertex( GetConstVertex( tmpvertex[LC+6] )+I-K );
674  tmpvertex[LC+6].s = .984375;
675  tmpvertex[LC+6].t = .015625;
676  tmpvertex[LC+7].SetVertex( GetConstVertex( tmpvertex[LC+7] )-I-K );
677  tmpvertex[LC+7].s = .015625;
678  tmpvertex[LC+7].t = .015625;
679  }
680  if (numVerticesPer > 8) {
681  tmpvertex[LC+8].SetVertex( GetConstVertex( tmpvertex[LC+8] )-J+K );
682  tmpvertex[LC+8].s = .015625;
683  tmpvertex[LC+8].t = .984375;
684  tmpvertex[LC+9].SetVertex( GetConstVertex( tmpvertex[LC+9] )+J+K );
685  tmpvertex[LC+9].s = .984375;
686  tmpvertex[LC+9].t = .984375;
687  tmpvertex[LC+10].SetVertex( GetConstVertex( tmpvertex[LC+10] )+J-K );
688  tmpvertex[LC+10].s = .984375;
689  tmpvertex[LC+10].t = .015625;
690  tmpvertex[LC+11].SetVertex( GetConstVertex( tmpvertex[LC+11] )-J-K );
691  tmpvertex[LC+11].s = .015625;
692  tmpvertex[LC+11].t = .015625;
693  }
694  }
695  {
696  int start = 0;
697  int inc = num/NUM_ACTIVE_ANIMATIONS;
698  inc -= inc%numVerticesPer;
699  for (int i = 0; i < NUM_ACTIVE_ANIMATIONS; ++i, start += inc) {
700  int later = start+inc;
701  if (i == NUM_ACTIVE_ANIMATIONS-1)
702  later = num;
703  vlist[i] = new GFXVertexList( GFXQUAD, later-start, tmpvertex+start, later-start, true, 0 );
704  }
705  }
706  delete[] tmpvertex;
707 }
SpriteStarVlist::~SpriteStarVlist ( )

Definition at line 748 of file star.cpp.

References i, j, and NUM_ACTIVE_ANIMATIONS.

749 {
750  for (int i = 0; i < NUM_ACTIVE_ANIMATIONS; ++i)
751  if (decal[i])
752  delete decal[i];
753  for (int j = 0; j < NUM_ACTIVE_ANIMATIONS; ++j)
754  if (vlist[j])
755  delete vlist[j];
756 }

Member Function Documentation

bool SpriteStarVlist::BeginDrawState ( const QVector center,
const Vector vel,
const Vector angular_vel,
bool  rotate,
bool  yawpitch,
int  whichTexture 
)
virtual

Reimplemented from StarVlist.

Definition at line 714 of file star.cpp.

References AMBIENT, GFXVertexList::BeginDrawState(), CULLFACE, DIFFUSE, GFXColorMaterial(), GFXDisable(), GFXEnable(), GFXVertexList::LoadDrawState(), Texture::MakeActive(), TEXTURE0, and StarVlist::UpdateGraphics().

720 {
721  UpdateGraphics();
722  GFXEnable( TEXTURE0 );
723  decal[whichTex]->MakeActive();
724  GFXDisable( CULLFACE );
726  vlist[whichTex]->LoadDrawState();
727  vlist[whichTex]->BeginDrawState();
728  return false;
729 }
void SpriteStarVlist::Draw ( bool  strertch,
int  whichTexture 
)
virtual

Reimplemented from StarVlist.

Definition at line 741 of file star.cpp.

References GFXVertexList::Draw(), VegaConfig::getVariable(), XMLSupport::parse_bool(), and vs_config.

742 {
743  static bool force_draw = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "vista_draw_stars", "false" ) );
744  if (force_draw || !isVista)
745  vlist[whichTexture]->Draw();
746 }
void SpriteStarVlist::EndDrawState ( bool  stretch,
int  whichTexture 
)
virtual

Reimplemented from StarVlist.

Definition at line 731 of file star.cpp.

References CULLFACE, GFXVertexList::EndDrawState(), GFXColorMaterial(), GFXDisable(), GFXEnable(), and TEXTURE0.

732 {
733  vlist[whichTex]->EndDrawState();
734  GFXDisable( TEXTURE0 );
735  GFXEnable( CULLFACE );
736  GFXColorMaterial( 0 );
737 }
int SpriteStarVlist::NumTextures ( )
virtual

Reimplemented from StarVlist.

Definition at line 709 of file star.cpp.

References NUM_ACTIVE_ANIMATIONS.

710 {
711  return NUM_ACTIVE_ANIMATIONS;
712 }

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