Fix for bug #17216 Broken untextured planets. This introduces (or exposes) a new bug with axial tilt under fiddly circumstances (distinct from bug #17243), but everything to do with rotation axes needs to be reviewed after 1.74.0 anyway.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3503 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-06-11 22:21:59 +00:00
parent 94fe97a1e3
commit ff39408225
4 changed files with 58 additions and 130 deletions

View File

@ -90,16 +90,16 @@ typedef struct
Vector rotationAxis;
}
- (id) initAsMainPlanetForSystemSeed:(Random_Seed) p_seed;
- (void) miniaturize;
- (id) initMiniatureFromPlanet:(PlanetEntity *)planet;
- (id) initFromDictionary:(NSDictionary*)dict withAtmosphere:(BOOL)atmo andSeed:(Random_Seed)p_seed;
- (void) miniaturize;
- (BOOL) setUpPlanetFromTexture:(NSString *)fileName;
- (int*) r_seed;
- (int) planet_seed;
- (BOOL) isTextured;
- (BOOL) isExplicitlyTextured; // Specified texture, not synthesized.
- (OOTexture *) texture;
- (NSString *) textureFileName;
- (double) polar_color_factor;

View File

@ -81,8 +81,6 @@ static GLfloat texture_uv_array[10400 * 2];
- (id) initMiniatureFromPlanet:(PlanetEntity*) planet withAlpha:(float) alpha;
- (OOTexture *) texture;
- (void) loadTexture:(NSDictionary *)configuration;
- (OOTexture *) planetTextureWithInfo:(NSDictionary *)info;
- (OOTexture *) cloudTextureWithCloudColor:(OOColor *)cloudColor cloudImpress:(GLfloat)cloud_impress cloudBias:(GLfloat)cloud_bias;
@ -266,16 +264,6 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured);
}
- (id) initAsMainPlanetForSystemSeed:(Random_Seed) p_seed
{
// this is exclusively called to initialise the main planet
NSMutableDictionary* planetInfo = [NSMutableDictionary dictionaryWithDictionary:[UNIVERSE generateSystemData:p_seed]];
[planetInfo oo_setBool:equal_seeds(p_seed, [UNIVERSE systemSeed]) forKey:@"mainForLocalSystem"];
return [self initFromDictionary:planetInfo withAtmosphere:YES andSeed:p_seed];
}
- (void) miniaturize
{
shuttles_on_ground = 0;
@ -297,90 +285,6 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured);
}
- (id) initMiniatureFromPlanet:(PlanetEntity *)planet
{
return [self initMiniatureFromPlanet:planet withAlpha:1.0f];
}
- (id) initMiniatureFromPlanet:(PlanetEntity *)planet withAlpha:(float)alpha
{
int i;
if (planet == nil)
{
[self release];
return nil;
}
if (!(self = [super init])) return nil;
_texture = [[planet texture] retain];
_textureFileName = [[planet textureFileName] copy];
planet_seed = [planet planet_seed];
shuttles_on_ground = 0;
last_launch_time = 0.0;
shuttle_launch_interval = 3600.0;
collision_radius = [planet collisionRadius] * PLANET_MINIATURE_FACTOR; // teeny tiny
scanClass = CLASS_NO_DRAW;
[self setStatus:STATUS_COCKPIT_DISPLAY];
orientation = planet->orientation;
if ([planet planetType] == STELLAR_TYPE_ATMOSPHERE)
{
planet_type = STELLAR_TYPE_ATMOSPHERE;
rotational_velocity = 0.02;
[self setModelName:kTexturedPlanetModel];
}
else
{
planet_type = STELLAR_TYPE_MINIATURE;
rotational_velocity = 0.04;
[self setModelName:(_texture != nil) ? kTexturedPlanetModel : kUntexturedPlanetModel];
}
[self rescaleTo:1.0];
for (i = 0; i < 3; i++)
{
amb_land[i] = [planet amb_land][i];
amb_sea[i] = [planet amb_sea][i];
amb_polar_land[i] = [planet amb_polar_land][i];
amb_polar_sea[i] = [planet amb_polar_sea][i];
}
//alpha channel
amb_land[i] = [planet amb_land][i] * alpha;
amb_sea[i] = [planet amb_sea][i] * alpha;
amb_polar_land[i] = [planet amb_polar_land][i] * alpha;
amb_polar_sea[i] = [planet amb_polar_sea][i] * alpha;
vertexdata = planet->vertexdata;
[self scaleVertices];
if (planet->atmosphere)
{
// copy clouds but make fainter if isTextureImage
atmosphere = [[PlanetEntity alloc] initMiniatureFromPlanet:planet->atmosphere withAlpha:planet->isTextureImage ? 0.6f : 1.0f];
atmosphere->collision_radius = collision_radius + ATMOSPHERE_DEPTH * PLANET_MINIATURE_FACTOR*2.0; //not to scale: invisible otherwise
[atmosphere rescaleTo:1.0];
[atmosphere scaleVertices];
atmosphere->root_planet = self;
}
rotationAxis = kBasisYVector;
[[OOGraphicsResetManager sharedManager] registerClient:self];
return self;
}
- (id) initFromDictionary:(NSDictionary*)dict withAtmosphere:(BOOL)atmo andSeed:(Random_Seed)p_seed;
{
BOOL procGen = NO;
@ -400,6 +304,14 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured);
else
planet_seed = p_seed.a * 7 + p_seed.c * 11 + p_seed.e * 13; // pseudo-random set-up for vertex colours
OOTexture *texture = [dict oo_objectOfClass:[OOTexture class] forKey:@"_oo_textureObject"];
if (texture != nil)
{
_texture = [texture retain];
isTextureImage = [dict oo_boolForKey:@"_oo_isExplicitlyTextured"];
}
else
{
NSDictionary *textureSpec = [dict oo_textureSpecifierForKey:@"texture" defaultName:nil];
if (textureSpec == nil && !procGen && !atmo)
{
@ -424,6 +336,7 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured);
OOLogERR(@"planet.fromDict", @"could not interpret \"%@\" as planet seed, using default.", seedStr);
}
}
}
seed_for_planet_description(p_seed);
@ -1448,6 +1361,12 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured)
}
- (BOOL) isExplicitlyTextured
{
return isTextureImage;
}
- (OOTexture *) texture
{
return _texture;

View File

@ -2638,19 +2638,27 @@ static int scriptRandomSeed = -1; // ensure proper random function
if (doppelganger == nil) return NO;
#else
OOPlanetEntity* doppelganger=nil;
OOPlanetEntity* doppelganger = nil;
NSMutableDictionary *planetInfo = [NSMutableDictionary dictionaryWithDictionary:[UNIVERSE generateSystemData:target_system_seed]];
if ([i_key isEqualToString:@"local-planet"] && [UNIVERSE sun])
{
// use a clone of the current system planet, to include temporary js retexturing!
doppelganger = [[OOPlanetEntity alloc] initMiniatureFromPlanet:[UNIVERSE planet]];
}
else
OOPlanetEntity *mainPlanet = [UNIVERSE planet];
OOTexture *texture = [mainPlanet texture];
if (texture != nil)
{
doppelganger = [[OOPlanetEntity alloc] initAsMainPlanetForSystemSeed:target_system_seed];
[doppelganger miniaturize];
[planetInfo setObject:texture forKey:@"_oo_textureObject"];
[planetInfo oo_setBool:[mainPlanet isExplicitlyTextured] forKey:@"_oo_isExplicitlyTextured"];
[planetInfo oo_setBool:YES forKey:@"mainForLocalSystem"];
[planetInfo oo_setQuaternion:[mainPlanet orientation] forKey:@"orientation"];
}
if (!doppelganger)
return NO;
}
doppelganger = [[OOPlanetEntity alloc] initFromDictionary:planetInfo withAtmosphere:YES andSeed:target_system_seed];
[doppelganger miniaturize];
[doppelganger autorelease];
if (doppelganger == nil) return NO;
#endif
ScanVectorFromString([[i_info subarrayWithRange:NSMakeRange(1, 3)] componentsJoinedByString:@" "], &model_p0);
@ -2673,9 +2681,6 @@ static int scriptRandomSeed = -1; // ensure proper random function
[doppelganger setPosition: model_p0];
[UNIVERSE addEntity:doppelganger];
#if !NEW_PLANETS
[doppelganger autorelease];
#endif
return YES;
}

View File

@ -702,7 +702,11 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
{
// set the system seed for random number generation
seed_for_planet_description(system_seed);
OOPlanetEntity *a_planet = [[OOPlanetEntity alloc] initAsMainPlanetForSystemSeed:[UNIVERSE systemSeed]];
Random_Seed systemSeed = [self systemSeed];
NSMutableDictionary *planetDict = [NSMutableDictionary dictionaryWithDictionary:[self generateSystemData:systemSeed]];
[planetDict oo_setBool:YES forKey:@"mainForLocalSystem"];
OOPlanetEntity *a_planet = [[OOPlanetEntity alloc] initFromDictionary:planetDict withAtmosphere:YES andSeed:systemSeed];
double planet_radius = [a_planet radius];
double planet_zpos = (12.0 + (Ranrot() & 3) - (Ranrot() & 3) ) * planet_radius; // 9..15 pr (planet radii) ahead