16 #include "gfx/planetary_transform.h"
68 unsigned char *tex = (
unsigned char*) malloc(
sizeof (
char)*rez*4 );
69 for (
int i = 0;
i < rez; ++
i) {
80 vector< string >
override;
81 override.push_back( nam );
102 float distance = dirtocam.Magnitude();
105 float HorizonHeight =
sqrt( 1-MyDistanceRadiusFactor*MyDistanceRadiusFactor )*
planetRadius;
110 dirtocam.Normalize();
119 if ( meshdata.empty() ) meshdata.push_back( NULL );
121 Mesh *shield = meshdata.back();
124 std::vector< Mesh* >fogs;
125 for (
unsigned int i = 0;
i < v.size(); ++
i) {
127 fogs.push_back( fog );
135 getSubUnits().preinsert( fawg );
138 meshdata.push_back( shield );
148 bool reverse_normals )
150 if ( meshdata.empty() )
151 meshdata.push_back( NULL );
152 Mesh *shield = meshdata.back();
157 static float daymaterialweight =
159 m.
dr = m.
dg = m.
db = m.
da = materialweight;
161 m.
er = m.
eg = m.
eb = m.
ea = daymaterialweight;
164 meshdata.push_back(
new CityLights( radius, stacks, stacks, texture.c_str(), numwrapx, numwrapy, inside_out,
ONE,
ONE,
165 false, 0,
M_PI, 0.0, 2*
M_PI, reverse_normals ) );
166 meshdata.back()->setEnvMap(
GFXFALSE );
167 meshdata.back()->SetMaterial( m );
169 meshdata.push_back( shield );
183 if ( meshdata.empty() )
184 meshdata.push_back( NULL );
185 Mesh *shield = meshdata.back();
188 meshdata.push_back(
new SphereMesh( radius, stacks, stacks, texture.c_str(), string(), NULL, inside_out, blendSrc, blendDst ) );
189 if ( meshdata.back() ) {
198 meshdata.back()->SetMaterial( a );
200 meshdata.push_back( shield );
213 if ( meshdata.empty() )
214 meshdata.push_back( NULL );
215 Mesh *shield = meshdata.back();
222 for (
int i = 0;
i < slices;
i++)
223 meshdata.push_back(
new RingMesh( iradius, oradius, stacks, texture.c_str(),
R,
S, wrapx, wrapy, blendSrc, blendDst,
224 false,
i*(2*
M_PI)/( (
float) slices ), (
i+1)*(2*
M_PI)/( (
float) slices ) ) );
226 meshdata.push_back( shield );
237 const string &textname,
238 const string &technique,
239 const string &unitname,
242 const vector< string > &dest,
246 const std::vector< GFXLightLocal > &ligh,
256 unsigned int nlights = 0;
258 nlights = ligh.size();
259 for (
unsigned int i = 0;
i < nlights;
i++) {
264 bool wormhole = dest.size() != 0;
266 static std::string wormhole_unit =
vs_config->
getVariable(
"graphics",
"wormhole",
"wormhole" );
267 string stab(
".stable" );
268 if (rand() > RAND_MAX*.99)
270 string wormholename = wormhole_unit+stab;
271 string wormholeneutralname = wormhole_unit+
".neutral"+stab;
274 faction = neutralfaction;
278 bool anytrue =
false;
279 while (jump != NULL) {
280 if (jump->name !=
"LOAD_FAILED") {
282 radius = jump->
rSize();
283 Mesh *shield = jump->meshdata.size() ? jump->meshdata.back() : NULL;
284 if ( jump->meshdata.size() ) jump->meshdata.pop_back();
285 while ( jump->meshdata.size() ) {
286 this->meshdata.push_back( jump->meshdata.back() );
287 jump->meshdata.pop_back();
289 jump->meshdata.push_back( shield );
291 for (
un_kiter i = jump->viewSubUnits(); (su = *
i) != NULL; ++
i)
292 SubUnits.prepend( su );
302 meshdata.push_back( NULL );
307 atmospheric = !(blendSrc ==
ONE && blendDst ==
ZERO);
308 meshdata.push_back(
new SphereMesh( radius, stacks, stacks, textname.c_str(), technique, NULL, inside_out, blendSrc, blendDst ) );
309 meshdata.back()->setEnvMap(
GFXFALSE );
310 meshdata.back()->SetMaterial( ourmat );
311 meshdata.push_back( NULL );
313 calculate_extent(
false );
317 corner_min.i = corner_min.j = corner_min.k = -radius;
318 corner_max.i = corner_max.j = corner_max.k = radius;
319 radial_size = radius;
320 if ( !meshdata.empty() )
321 meshdata[0]->setVirtualBoundingBox( corner_min, corner_max, radius );
323 if (ligh.size() > 0) {
328 static float glowradius =
335 c = ligh[0].ligh.GetProperties(
DIFFUSE );
337 c = ligh[0].ligh.GetProperties(
AMBIENT );
339 if ( shines.empty() )
340 shines.push_back(
"shine.ani" );
341 shine =
new Animation( shines[rand()%shines.size()].c_str(),
true, .1,
BILINEAR,
false,
true,
c );
342 shine->
SetDimensions( glowradius*radius, glowradius*radius );
346 meshdata.push_back( NULL );
350 this->InitPlanet( x, y, vely, rotvel,
353 textname, technique, unitname,
370 static int counter = 0;
371 if (counter++ > 100) {
372 if (t.Magnitude() < corner_max.i) {
378 #ifdef PLANETARYTRANSFORM
379 terrain->DisableUpdate();
385 for (
unsigned int i = 0;
i <
lights.size();
i++)
387 if (inside && terrain)
388 PlanetTerrainDrawQueue.push_back(
new UnitContainer(
this ) );
395 static int num_shine_drawing =
397 for (
int i = 0; i < num_shine_drawing; ++i)
403 while ( !PlanetTerrainDrawQueue.empty() ) {
404 Planet *pl = (
Planet*) PlanetTerrainDrawQueue.back()->GetUnit();
406 PlanetTerrainDrawQueue.back()->SetUnit( NULL );
407 delete PlanetTerrainDrawQueue.back();
408 PlanetTerrainDrawQueue.pop_back();
416 terrain->EnableUpdate();
417 #ifdef PLANETARYTRANSFORM
419 Normalize( TerrainUp );
420 TerrainH = TerrainUp.Cross(
Vector( -TerrainUp.i+.25, TerrainUp.j-.24, -TerrainUp.k+.24 ) );
421 Normalize( TerrainH );
425 if (inside && terrain) {
430 #ifdef PLANETARYTRANSFORM
432 terrain->SetTransformation( tmp );
436 Vector tup( tmp[4], tmp[5], tmp[6] );
439 blah = p-( blah.Dot( tup ) )*tup;
455 const Vector &smallnormal,
464 un->SetPlanetOrbitData( terraintrans );
475 terraintrans->InvTransformBasis( top, P, Q, R, un->
Position() );
481 #ifdef PLANETARYTRANSFORM
482 terraintrans->GrabPerpendicularOrigin( un->
Position(), top );
485 terrain->Collide( un, top );
488 jumpReactToCollision( un );
490 if (!terrain && GetDestinations().empty() && !atmospheric) {
493 static bool planet_crash_docks =
503 for (
unsigned int i = 0;
i <
lights.size();
i++)
508 for (
unsigned int i = 0;
i <
lights.size();
i++)
522 *tmp = cumulative_transformation_matrix;
523 terraintrans->SetTransformation( tmp );
537 terraintrans =
new PlanetaryTransform( .8*corner_max.i, x*ratiox, z, numwraps, scaleatmos );
538 terraintrans->SetTransformation( &cumulative_transformation_matrix );
556 for (
unsigned int i = 0;
i < this->
lights.size();
i++)