12 #if defined (__APPLE__) || defined (MACOSX)
13 #include <OpenGL/gl.h>
25 unsigned int count = 0;
29 count += (*i).second.getHeirarchy().size();
35 vsUMap< std::string, GalaxyXML::SGalaxy >::iterator sector;
36 vsUMap< std::string, GalaxyXML::SGalaxy >::iterator system;
46 system = (*sector).second.getHeirarchy().begin();
47 if ( system == (*sector).second.getHeirarchy().end() )
54 if ( system != (*sector).second.getHeirarchy().end() )
56 while ( !
Done() && system == (*sector).second.getHeirarchy().end() ) {
59 system = (*sector).second.getHeirarchy().begin();
65 return &(*system).second;
72 return (*system).first;
79 return (*sector).first;
86 static void saturate(
float &r,
float &g,
float &
b )
96 r = pow( r, colorpower );
97 g = pow( g, colorpower );
98 b = pow( b, colorpower );
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;
111 float clamp = starcoloraverage+lum/starcolorincrement;
120 if (lum > starcolorcutoff) {
123 return lum > starcolorcutoff;
126 namespace StarSystemGent
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) {
147 if (lumi.length() == 0 || strtod( lumi.c_str(), NULL ) == 0) {
148 our_system_name =
"";
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 =
"";
156 our_system_name =
"";
160 if ( !our_system_name.empty() )
163 memset( tmpvertex, 0,
sizeof (
GFXVertex)*(*num)*repetition );
170 Vector starmin( 0, 0, 0 );
171 Vector starmax( 0, 0, 0 );
174 float maxdistance = -1;
175 float mindistance = -1;
176 if (our_system_name.size() > 0) {
184 if ( 3 == sscanf( ( *
i.Get() )[
"xyz"].c_str(),
"%f %f %f", &xx, &yy, &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;
204 if ( 1 == sscanf( ( *
i.Get() )[
"luminosity"].c_str(),
"%f", &lumin ) ) {
205 if (lumin > maxlumin)
207 if (lumin < minlumin)
214 if (maxdistance < 0) maxdistance = 0;
215 if (mindistance < 0) mindistance = 0;
216 maxdistance =
sqrt( maxdistance );
217 mindistance =
sqrt( mindistance );
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() ) {
235 float xorig, yorig, zorig;
236 if ( 3 == sscanf( ( *si.
Get() )[
"xyz"].c_str(),
242 tmpvertex[j+repetition-1].
x = xorig-xcent;
244 tmpvertex[j+repetition-1].
y = yorig-ycent;
246 tmpvertex[j+repetition-1].
z = zorig-zcent;
248 std::string radstr = ( *si.
Get() )[
"sun_radius"];
249 if ( radstr.size() ) {
252 tmpvertex[j+repetition-1].
r = suncolor.
r;
253 tmpvertex[j+repetition-1].
g = suncolor.
g;
254 tmpvertex[j+repetition-1].
b = suncolor.
b;
257 sscanf( ( *si.
Get() )[
"luminosity"].c_str(),
"%f", &lumin );
259 float distance =
Vector( tmpvertex[j+repetition-1].
x,
260 tmpvertex[j+repetition-1].
y,
261 tmpvertex[j+repetition-1].
z ).Magnitude();
263 tmpvertex[j+repetition-1].
g,
264 tmpvertex[j+repetition-1].
b,
265 Vector( lumin, minlumin, maxlumin ),
266 distance, maxdistance ) )
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;
275 tmpvertex[j+LC].
y = tmpvertex[j+repetition-1].
y;
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;
300 for (
int i = 0,
j = 1;
i < num/2; ++
i,
j += 2)
301 tmpvertex[
i] = tmpvertex[j];
332 static float velstreakscale =
335 static float fov_smoothing =
338 Vector vel( -velocity*velstreakscale );
339 float speed = vel.Magnitude();
340 if ( (smoothstreak >= minstreak || vel.MagnitudeSquared() >= minstreak*minstreak) && (speed > 1.0
e-7) ) {
343 speed = fov_smoot*speed+(1-fov_smoot)*smoothstreak;
344 if (speed < minstreak) speed = minstreak;
345 static float streakcap =
347 if (speed > streakcap)
350 smoothstreak =
speed;
354 static float torquestreakscale =
356 for (
int j = 0;
j < numvertices-1;
j += 2) {
360 Vector vpoint( v[i+1].
x, v[i+1].
y, v[i+1].
z );
361 Vector recenter = ( vpoint-center.Cast() );
363 RotateAxisAngle( rollMatrix, torque, torque.Magnitude()*torquestreakscale*.003 );
364 vpoint =
Transform( rollMatrix, recenter )+center.Cast();
366 v[i].
x = vpoint.i-vel.i;
367 v[i].
y = vpoint.j-vel.j;
368 v[i].
z = vpoint.k-vel.k;
392 nonstretchvlist->
Draw();
408 delete nonstretchvlist;
414 static string starspritetextures =
vs_config->
getVariable(
"graphics",
"near_stars_sprite_texture",
"" );
415 static float starspritesize =
417 if (starspritetextures.length() == 0)
422 ResetPosition(
QVector( 0, 0, 0 ) );
434 if (stars_dont_move)
return;
436 UpdatePosition( cp );
444 static bool near_stars_alpha =
446 static bool near_stars_alpha_blend =
448 static float AlphaTestingCutoff =
450 if (near_stars_alpha) {
452 if (!near_stars_alpha_blend)
466 static float star_spread_attenuation =
473 GFXColor( .01, 0, 1/(star_spread_attenuation*star_spread_attenuation*spread*spread) ) );
481 for (LC = 0; LC < LN; ++LC) {
491 vlist->
Draw( stretch, LC );
496 if (near_stars_alpha)
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) {
538 while (a-cp < -1.5*spread) {
551 void Stars::ResetPosition(
const QVector ¢ )
553 for (
int i = 0;
i < 3;
i++)
554 for (
int j = 0;
j < 3;
j++)
555 for (
int k = 0;
k < 3;
k++) {
556 pos[
i*9+
j*3+
k].Set( (i-1)*spread, (j-1)*spread, (k-1)*spread );
557 pos[
i*9+
j*3+
k] += cent;
561 void Stars::UpdatePosition(
const QVector &cp )
563 if (fabs( pos[0].i-cp.i ) > 3*spread || fabs( pos[0].j-cp.j ) > 3*spread || fabs( pos[0].k-cp.k ) > 3*spread) {
567 upd( pos[0].i, pos[1].i, pos[2].i, pos[3].i, pos[4].i, pos[5].i, pos[6].i, pos[7].i, pos[8].i, cp.i, spread );
568 upd( pos[9].i, pos[10].i, pos[11].i, pos[12].i, pos[13].i, pos[14].i, pos[15].i, pos[16].i, pos[17].i, cp.i, spread );
569 upd( pos[18].i, pos[19].i, pos[20].i, pos[21].i, pos[22].i, pos[23].i, pos[24].i, pos[25].i, pos[26].i, cp.i, spread );
571 upd( pos[0].j, pos[1].j, pos[2].j, pos[9].j, pos[10].j, pos[11].j, pos[18].j, pos[19].j, pos[20].j, cp.j, spread );
572 upd( pos[3].j, pos[4].j, pos[5].j, pos[12].j, pos[13].j, pos[14].j, pos[21].j, pos[22].j, pos[23].j, cp.j, spread );
573 upd( pos[6].j, pos[7].j, pos[8].j, pos[15].j, pos[16].j, pos[17].j, pos[24].j, pos[25].j, pos[26].j, cp.j, spread );
575 upd( pos[0].k, pos[3].k, pos[6].k, pos[9].k, pos[12].k, pos[15].k, pos[18].k, pos[21].k, pos[24].k, cp.k, spread );
576 upd( pos[1].k, pos[4].k, pos[7].k, pos[10].k, pos[13].k, pos[16].k, pos[19].k, pos[22].k, pos[25].k, cp.k, spread );
577 upd( pos[2].k, pos[5].k, pos[8].k, pos[11].k, pos[14].k, pos[17].k, pos[20].k, pos[23].k, pos[26].k, cp.k, spread );
594 vector< AnimatedTexture* >animations;
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) {
604 decal[curtexture] = animations.back();
605 }
else if (texturename.length() == 0) {
606 if (curtexture == 0) {
609 if ( animations.size() ) {
616 decal[curtexture] = tmp;
618 decal[curtexture] = decal[rand()%curtexture]->
Clone();
622 decal[curtexture] =
new Texture( texturename.c_str() );
625 int numVerticesPer = near_stars_alpha ? 4 : 12;
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;
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)
646 if (J.MagnitudeSquared() < .00001)
648 if (K.MagnitudeSquared() < .00001)
655 tmpvertex[LC+0].
s = 0.15625;
656 tmpvertex[LC+0].
t = .984375;
658 tmpvertex[LC+1].
s = .984375;
659 tmpvertex[LC+1].
t = .984375;
661 tmpvertex[LC+2].
s = .984375;
662 tmpvertex[LC+2].
t = .015625;
664 tmpvertex[LC+3].
s = .015625;
665 tmpvertex[LC+3].
t = .015625;
666 if (numVerticesPer > 4) {
668 tmpvertex[LC+4].
s = .015625;
669 tmpvertex[LC+4].
t = .984375;
671 tmpvertex[LC+5].
s = .984375;
672 tmpvertex[LC+5].
t = .984375;
674 tmpvertex[LC+6].
s = .984375;
675 tmpvertex[LC+6].
t = .015625;
677 tmpvertex[LC+7].
s = .015625;
678 tmpvertex[LC+7].
t = .015625;
680 if (numVerticesPer > 8) {
682 tmpvertex[LC+8].
s = .015625;
683 tmpvertex[LC+8].
t = .984375;
685 tmpvertex[LC+9].
s = .984375;
686 tmpvertex[LC+9].
t = .984375;
688 tmpvertex[LC+10].
s = .984375;
689 tmpvertex[LC+10].
t = .015625;
691 tmpvertex[LC+11].
s = .015625;
692 tmpvertex[LC+11].
t = .015625;
698 inc -= inc%numVerticesPer;
700 int later = start+inc;
701 if (
i == NUM_ACTIVE_ANIMATIONS-1)
744 if (force_draw || !isVista)
745 vlist[whichTexture]->
Draw();