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
star.cpp File Reference
#include "star.h"
#include "ani_texture.h"
#include <assert.h>
#include "vegastrike.h"
#include "vs_globals.h"
#include "gfx/camera.h"
#include "gfx/cockpit.h"
#include "config_xml.h"
#include "lin_time.h"
#include "galaxy_xml.h"
#include <GL/gl.h>

Go to the source code of this file.

Classes

class  StarIter
 

Namespaces

 StarSystemGent
 

Constant Groups

 StarSystemGent
 

Macros

#define SINX   1
 
#define SINY   2
 
#define SINZ   4
 

Functions

unsigned int NumStarsInGalaxy ()
 
static void saturate (float &r, float &g, float &b)
 
bool computeStarColor (float &r, float &g, float &b, Vector luminmax, float distance, float maxdistance)
 
GFXColor StarSystemGent::getStarColorFromRadius (float radius)
 
static GFXColorVertexAllocVerticesForSystem (std::string our_system_name, float spread, int *num, int repetition)
 
static void upd (double &a, double &b, double &c, double &d, double &e, double &f, double &g, double &h, double &i, const double cp, const float spread)
 
static Vector GetConstVertex (const GFXColorVertex &c)
 

Variables

bool isVista
 

Macro Definition Documentation

#define SINX   1

Definition at line 19 of file star.cpp.

#define SINY   2

Definition at line 20 of file star.cpp.

#define SINZ   4

Definition at line 21 of file star.cpp.

Function Documentation

static GFXColorVertex* AllocVerticesForSystem ( std::string  our_system_name,
float  spread,
int num,
int  repetition 
)
static

Definition at line 140 of file star.cpp.

References _Universe, GFXColorVertex::a, b, GFXColor::b, GFXColorVertex::b, computeStarColor(), StarIter::Done(), float, GFXColor::g, GFXColorVertex::g, g, StarIter::Get(), Universe::getGalaxyProperty(), StarSystemGent::getStarColorFromRadius(), VegaConfig::getVariable(), GFXColorVertex::i, i, j, GFXColorVertex::j, GFXColorVertex::k, NumStarsInGalaxy(), XMLSupport::parse_float(), GFXColor::r, GFXColorVertex::r, UniverseUtil::sqrt(), Vector, vs_config, VSFileSystem::vs_fprintf(), x, GFXColorVertex::x, y, GFXColorVertex::y, z, and GFXColorVertex::z.

Referenced by PointStarVlist::PointStarVlist(), and SpriteStarVlist::SpriteStarVlist().

141 {
142  static float staroverlap = XMLSupport::parse_float( vs_config->getVariable( "graphics", "star_overlap", "1" ) );
143  float xyzspread = spread*2*staroverlap;
144  static string allowedSectors = vs_config->getVariable( "graphics", "star_allowable_sectors", "Vega Sol" );
145  if (our_system_name.size() > 0) {
146  string lumi = _Universe->getGalaxyProperty( our_system_name, "luminosity" );
147  if (lumi.length() == 0 || strtod( lumi.c_str(), NULL ) == 0) {
148  our_system_name = "";
149  } else {
150  string::size_type slash = our_system_name.find( "/" );
151  if (slash != string::npos) {
152  string sec = our_system_name.substr( 0, slash );
153  if (allowedSectors.find( sec ) == string::npos)
154  our_system_name = "";
155  } else {
156  our_system_name = "";
157  }
158  }
159  }
160  if ( !our_system_name.empty() )
161  *num = NumStarsInGalaxy();
162  GFXColorVertex *tmpvertex = new GFXColorVertex[(*num)*repetition];
163  memset( tmpvertex, 0, sizeof (GFXVertex)*(*num)*repetition );
164  StarIter si;
165  int starcount = 0;
166  int j = 0;
167  float xcent = 0;
168  float ycent = 0;
169  float zcent = 0;
170  Vector starmin( 0, 0, 0 );
171  Vector starmax( 0, 0, 0 );
172  float minlumin = 1;
173  float maxlumin = 1;
174  float maxdistance = -1;
175  float mindistance = -1;
176  if (our_system_name.size() > 0) {
177  sscanf( _Universe->getGalaxyProperty( our_system_name, "xyz" ).c_str(),
178  "%f %f %f",
179  &xcent,
180  &ycent,
181  &zcent );
182  for (StarIter i; !i.Done(); ++i) {
183  float xx, yy, zz;
184  if ( 3 == sscanf( ( *i.Get() )["xyz"].c_str(), "%f %f %f", &xx, &yy, &zz ) ) {
185  xx -= xcent;
186  yy -= ycent;
187  zz -= zcent;
188  if (xx < starmin.i)
189  starmin.i = xx;
190  if (yy < starmin.j)
191  starmin.j = yy;
192  if (zz < starmin.k)
193  starmin.k = zz;
194  if (xx > starmax.i)
195  starmax.i = xx;
196  if (yy > starmax.j)
197  starmax.j = yy;
198  if (zz > starmax.k)
199  starmax.k = zz;
200  float magsqr = xx*xx+yy*yy+zz*zz;
201  if ( (maxdistance < 0) || (maxdistance < magsqr) ) maxdistance = magsqr;
202  if ( (mindistance < 0) || (mindistance > magsqr) ) mindistance = magsqr;
203  float lumin;
204  if ( 1 == sscanf( ( *i.Get() )["luminosity"].c_str(), "%f", &lumin ) ) {
205  if (lumin > maxlumin)
206  maxlumin = lumin;
207  if (lumin < minlumin)
208  if (lumin > 0)
209  minlumin = lumin;
210  }
211  }
212  }
213  }
214  if (maxdistance < 0) maxdistance = 0;
215  if (mindistance < 0) mindistance = 0;
216  maxdistance = sqrt( maxdistance );
217  mindistance = sqrt( mindistance );
218  VSFileSystem::vs_fprintf( stderr, "Min (%f, %f, %f) Max(%f, %f, %f) MinLumin %f, MaxLumin %f",
219  starmin.i, starmin.j, starmin.k, starmax.i, starmax.j, starmax.k, minlumin, maxlumin );
220  for (int y = 0; y < *num; ++y) {
221  tmpvertex[j+repetition-1].x = -.5*xyzspread+rand()*( (float) xyzspread/RAND_MAX );
222  tmpvertex[j+repetition-1].y = -.5*xyzspread+rand()*( (float) xyzspread/RAND_MAX );
223  tmpvertex[j+repetition-1].z = -.5*xyzspread+rand()*( (float) xyzspread/RAND_MAX );
224  float brightness = .1+.9*( (float) rand() )/RAND_MAX;
225  tmpvertex[j+repetition-1].r = brightness;
226  tmpvertex[j+repetition-1].g = brightness;
227  tmpvertex[j+repetition-1].b = brightness;
228  tmpvertex[j+repetition-1].a = 1;
229  tmpvertex[j+repetition-1].i = .57735;
230  tmpvertex[j+repetition-1].j = .57735;
231  tmpvertex[j+repetition-1].k = .57735;
232  int incj = repetition;
233  if ( our_system_name.size() > 0 && !si.Done() ) {
234  starcount++;
235  float xorig, yorig, zorig;
236  if ( 3 == sscanf( ( *si.Get() )["xyz"].c_str(),
237  "%f %f %f",
238  &xorig,
239  &yorig,
240  &zorig ) ) {
241  if (xcent != xorig)
242  tmpvertex[j+repetition-1].x = xorig-xcent;
243  if (ycent != yorig)
244  tmpvertex[j+repetition-1].y = yorig-ycent;
245  if (zcent != zorig)
246  tmpvertex[j+repetition-1].z = zorig-zcent;
247  }
248  std::string radstr = ( *si.Get() )["sun_radius"];
249  if ( radstr.size() ) {
250  float rad = XMLSupport::parse_float( radstr );
252  tmpvertex[j+repetition-1].r = suncolor.r;
253  tmpvertex[j+repetition-1].g = suncolor.g;
254  tmpvertex[j+repetition-1].b = suncolor.b;
255  }
256  float lumin = 1;
257  sscanf( ( *si.Get() )["luminosity"].c_str(), "%f", &lumin );
258 
259  float distance = Vector( tmpvertex[j+repetition-1].x,
260  tmpvertex[j+repetition-1].y,
261  tmpvertex[j+repetition-1].z ).Magnitude();
262  if ( !computeStarColor( tmpvertex[j+repetition-1].r,
263  tmpvertex[j+repetition-1].g,
264  tmpvertex[j+repetition-1].b,
265  Vector( lumin, minlumin, maxlumin ),
266  distance, maxdistance ) )
267  incj = 0;
268  ++si;
269  }
270  for (int LC = repetition-2; LC >= 0; --LC) {
271  tmpvertex[j+LC].i = tmpvertex[j+repetition-1].i;
272  tmpvertex[j+LC].j = tmpvertex[j+repetition-1].j;
273  tmpvertex[j+LC].k = tmpvertex[j+repetition-1].k;
274  tmpvertex[j+LC].x = tmpvertex[j+repetition-1].x; //+spread*.01;
275  tmpvertex[j+LC].y = tmpvertex[j+repetition-1].y; //;+spread*.01;
276  tmpvertex[j+LC].z = tmpvertex[j+repetition-1].z;
277  tmpvertex[j+LC].r = 0;
278  tmpvertex[j+LC].g = 0;
279  tmpvertex[j+LC].b = 0;
280  tmpvertex[j+LC].a = 0;
281  }
282  if (incj) {
283  //printf ("%f %f %f\n",tmpvertex[j+repetition-1].r,tmpvertex[j+repetition-1].g,tmpvertex[j+repetition-1].b);
284  }
285  j += incj;
286  }
287  VSFileSystem::vs_fprintf( stderr, "Read In Star Count %d used: %d\n", starcount, j/2 );
288  *num = j;
289  return tmpvertex;
290 }
bool computeStarColor ( float r,
float g,
float b,
Vector  luminmax,
float  distance,
float  maxdistance 
)

Definition at line 101 of file star.cpp.

References VegaConfig::getVariable(), UniverseUtil::log(), XMLSupport::parse_float(), saturate(), and vs_config.

Referenced by AllocVerticesForSystem().

102 {
103  saturate( r, g, b );
104  static float luminscale = XMLSupport::parse_float( vs_config->getVariable( "graphics", "starluminscale", ".001" ) );
105  static float starcoloraverage = XMLSupport::parse_float( vs_config->getVariable( "graphics", "starcoloraverage", ".6" ) );
106  static float starcolorincrement = XMLSupport::parse_float( vs_config->getVariable( "graphics", "starcolorincrement", "100" ) );
107  float dissqr = distance*distance/(maxdistance*maxdistance);
108  float lum = 100*luminmax.i/(luminmax.k*dissqr);
109  lum = log( (double) luminmax.i*10./(double) luminmax.j )*luminscale/dissqr;
110 //VSFileSystem::vs_fprintf (stderr,"luminmax %f lumnow %f\n",luminmax.i/(luminmax.k*dissqr),lum);
111  float clamp = starcoloraverage+lum/starcolorincrement;
112  if (clamp > 1)
113  clamp = 1;
114  if (lum > clamp)
115  lum = clamp;
116  r *= lum;
117  g *= lum;
118  b *= lum;
119  static float starcolorcutoff = XMLSupport::parse_float( vs_config->getVariable( "graphics", "starcolorcutoff", ".1" ) );
120  if (lum > starcolorcutoff) {
121  //printf ("lum %f",lum);
122  }
123  return lum > starcolorcutoff;
124 }
static Vector GetConstVertex ( const GFXColorVertex c)
static

Definition at line 585 of file star.cpp.

References Vector, GFXColorVertex::x, GFXColorVertex::y, and GFXColorVertex::z.

Referenced by SpriteStarVlist::SpriteStarVlist().

586 {
587  return Vector( c.x, c.y, c.z );
588 }
unsigned int NumStarsInGalaxy ( )

Definition at line 23 of file star.cpp.

References _Universe, e, Universe::getGalaxy(), GalaxyXML::SGalaxy::getHeirarchy(), and i.

Referenced by AllocVerticesForSystem().

24 {
25  unsigned int count = 0;
26  vsUMap< std::string, GalaxyXML::SGalaxy >::iterator i = _Universe->getGalaxy()->getHeirarchy().begin();
27  vsUMap< std::string, GalaxyXML::SGalaxy >::iterator e = _Universe->getGalaxy()->getHeirarchy().end();
28  for (; i != e; ++i)
29  count += (*i).second.getHeirarchy().size();
30  return count;
31 }
static void saturate ( float r,
float g,
float b 
)
static

Definition at line 86 of file star.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_float(), and vs_config.

Referenced by computeStarColor(), and GFXSetOptimalIntensity().

87 {
88  static float conemin = XMLSupport::parse_float( vs_config->getVariable( "graphics", "starmincolorval", ".3" ) );
89  static float colorpower = XMLSupport::parse_float( vs_config->getVariable( "graphics", "starcolorpower", ".25" ) );
90  if (r < conemin)
91  r += conemin;
92  if (g < conemin)
93  g += conemin;
94  if (b < conemin)
95  b += conemin;
96  r = pow( r, colorpower );
97  g = pow( g, colorpower );
98  b = pow( b, colorpower );
99 }
static void upd ( double &  a,
double &  b,
double &  c,
double &  d,
double &  e,
double &  f,
double &  g,
double &  h,
double &  i,
const double  cp,
const float  spread 
)
static

Definition at line 512 of file star.cpp.

References FINITE.

523 {
524  //assert (a==b&&b==c&&c==d&&d==e&&e==f);
525  if ( a != b || a != c || a != d || a != e || a != f || !FINITE( a ) )
526  a = b = c = d = e = f = 0;
527  while (a-cp > 1.5*spread) {
528  a -= 3*spread;
529  b -= 3*spread;
530  c -= 3*spread;
531  d -= 3*spread;
532  e -= 3*spread;
533  f -= 3*spread;
534  g -= 3*spread;
535  h -= 3*spread;
536  i -= 3*spread;
537  }
538  while (a-cp < -1.5*spread) {
539  a += 3*spread;
540  b += 3*spread;
541  c += 3*spread;
542  d += 3*spread;
543  e += 3*spread;
544  f += 3*spread;
545  g += 3*spread;
546  h += 3*spread;
547  i += 3*spread;
548  }
549 }

Variable Documentation

bool isVista

Definition at line 240 of file main.cpp.

Referenced by main().