Oolite
Loading...
Searching...
No Matches
OOPlanetEntity.m
Go to the documentation of this file.
1/*
2
3OOPlanetEntity.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25#import "OOPlanetEntity.h"
26
27#if NEW_PLANETS
28
29#define NEW_ATMOSPHERE 1
30
31#import "OOPlanetDrawable.h"
32
33#import "AI.h"
34#import "OOCharacter.h"
35#import "PlayerEntity.h"
36#import "ShipEntity.h"
37#import "ShipEntityAI.h"
38#import "Universe.h"
39
41#import "OOMaths.h"
42#import "OOStringParsing.h"
44#import "ResourceManager.h"
45
50#import "OOShaderMaterial.h"
53#import "OOStringExpander.h"
54
55#define OO_TERMINATOR_THRESHOLD_VECTOR_DEFAULT (make_vector(0.105, 0.18, 0.28)) // used to be (0.1, 0.105, 0.12);
56
57@interface OOPlanetEntity (Private) <OOGraphicsResetClient>
58
59- (void)setUpTerrainParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo;
60- (void)setUpLandParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo;
61- (void)setUpAtmosphereParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo;
62- (void)setUpColorParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo isAtmosphere:(BOOL)isAtmosphere;
63- (void)setUpTypeParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo;
64
65@end
66
67@implementation OOPlanetEntity
68
69// this is exclusively called to initialise the main planet.
70- (id)initAsMainPlanetForSystem:(OOSystemID)s
71{
72 NSMutableDictionary* planetInfo = [[UNIVERSE generateSystemData:s] mutableCopy];
73 [planetInfo autorelease];
74
75 [planetInfo oo_setBool:YES forKey:@"mainForLocalSystem"];
76 if (s != [PLAYER systemID]) {
77 [planetInfo oo_setBool:YES forKey:@"isMiniature"];
78 }
79 return [self initFromDictionary:planetInfo withAtmosphere:[planetInfo oo_boolForKey:@"has_atmosphere" defaultValue:YES] andSeed:[[UNIVERSE systemManager] getRandomSeedForSystem:s inGalaxy:[PLAYER galaxyNumber]] forSystem:s];
80}
81
82static const double kMesosphere = 10.0 * ATMOSPHERE_DEPTH; // atmosphere effect starts at 10x the height of the clouds
83
84- (id)initFromDictionary:(NSDictionary*)dict withAtmosphere:(BOOL)atmosphere andSeed:(Random_Seed)seed forSystem:(OOSystemID)systemID
85{
86 if (dict == nil)
87 dict = [NSDictionary dictionary];
88 RANROTSeed savedRanrotSeed = RANROTGetFullSeed();
89
90 self = [self init];
91 if (self == nil)
92 return nil;
93
94 scanClass = CLASS_NO_DRAW;
95
96 NSMutableDictionary* planetInfo = [[UNIVERSE generateSystemData:systemID] mutableCopy];
97 [planetInfo autorelease];
98
99 [self setUpTypeParametersWithSourceInfo:dict targetInfo:planetInfo];
100
101 [self setUpTerrainParametersWithSourceInfo:dict targetInfo:planetInfo];
102
103 // Load random seed override.
104 NSString* seedStr = [dict oo_stringForKey:@"seed"];
105 if (seedStr != nil) {
106 Random_Seed overrideSeed = RandomSeedFromString(seedStr);
107 if (!is_nil_seed(overrideSeed))
108 seed = overrideSeed;
109 else
110 OOLogERR(@"planet.fromDict", @"could not interpret \"%@\" as planet seed, using default.", seedStr);
111 }
112
113 // Generate various planet info.
115
116 _name = nil;
117 [self setName:OOExpand([dict oo_stringForKey:KEY_PLANETNAME defaultValue:[planetInfo oo_stringForKey:KEY_PLANETNAME defaultValue:@"%H"]])];
118
119 int radius_km = [dict oo_intForKey:KEY_RADIUS defaultValue:[planetInfo oo_intForKey:KEY_RADIUS]];
120 collision_radius = radius_km * 10.0; // Scale down by a factor of 100
121 OOTechLevelID techLevel = [dict oo_intForKey:KEY_TECHLEVEL defaultValue:[planetInfo oo_intForKey:KEY_TECHLEVEL]];
122
123 if (techLevel > 14)
124 techLevel = 14;
125 _shuttlesOnGround = 1 + techLevel / 2;
126 _shuttleLaunchInterval = 3600.0 / (double)_shuttlesOnGround; // All are launched in one hour.
127 _lastLaunchTime = [UNIVERSE getTime] + 30.0 - _shuttleLaunchInterval; // launch 30s after player enters universe.
128 // make delay > 0 to allow scripts adding a station nearby.
129
130 int percent_land = [planetInfo oo_intForKey:@"percent_land" defaultValue:24 + (gen_rnd_number() % 48)];
131 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_land] forKey:@"land_fraction"];
132
133 int percent_ice = [planetInfo oo_intForKey:@"percent_ice" defaultValue:5];
134 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_ice] forKey:@"polar_fraction"];
135
136 RNG_Seed savedRndSeed = currentRandomSeed();
137
138 _planetDrawable = [[OOPlanetDrawable alloc] init];
139
140 _terminatorThresholdVector = [planetInfo oo_vectorForKey:@"terminator_threshold_vector" defaultValue:OO_TERMINATOR_THRESHOLD_VECTOR_DEFAULT];
141
142 // Load material parameters, including atmosphere.
143 RANROTSeed planetNoiseSeed = RANROTGetFullSeed();
144 [planetInfo setObject:[NSValue valueWithBytes:&planetNoiseSeed objCType:@encode(RANROTSeed)] forKey:@"noise_map_seed"];
145 [self setUpLandParametersWithSourceInfo:dict targetInfo:planetInfo];
146
147 _airColor = nil; // default to no air
148 _airColorMixRatio = 0.5f;
149 _airDensity = 0.75f;
150
151 _illuminationColor = [[planetInfo objectForKey:@"illumination_color"] retain];
152
153#if NEW_ATMOSPHERE
154 if (atmosphere) {
155 // shader atmosphere always has a radius of collision_radius + ATMOSPHERE_DEPTH. For texture atmosphere, we need to check
156 // if a shader atmosphere is also used. If yes, set its radius to just cover the planet so that it doesn't conflict with
157 // the shader atmosphere at the planet edges. If no shader atmosphere is used, then set it to the standard radius
158 double atmosphereRadius = [UNIVERSE detailLevel] >= DETAIL_LEVEL_SHADERS ? collision_radius : collision_radius + ATMOSPHERE_DEPTH;
159 _atmosphereDrawable = [[OOPlanetDrawable atmosphereWithRadius:atmosphereRadius] retain];
160 _cloudsShaderDrawable = [[OOPlanetDrawable atmosphereWithRadius:atmosphereRadius] retain];
161 _atmosphereShaderDrawable = [[OOPlanetDrawable atmosphereWithRadius:collision_radius + ATMOSPHERE_DEPTH] retain];
162
163 // convert the atmosphere settings to generic 'material parameters'
164 percent_land = 100 - [dict oo_intForKey:@"percent_cloud" defaultValue:100 - (3 + (gen_rnd_number() & 31) + (gen_rnd_number() & 31))];
165 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_land] forKey:@"cloud_fraction"];
166 [self setUpAtmosphereParametersWithSourceInfo:dict targetInfo:planetInfo];
167 // planetInfo now contains a valid air_color
168 _airColor = [[planetInfo objectForKey:@"air_color"] retain];
169 _airColorMixRatio = [planetInfo oo_floatForKey:@"air_color_mix_ratio"];
170
171 _airDensity = OOClamp_0_1_f([planetInfo oo_floatForKey:@"air_density"]);
172 // OOLog (@"planet.debug",@" translated air colour:%@ cloud colour:%@ polar cloud color:%@", [_airColor rgbaDescription],[(OOColor *)[planetInfo objectForKey:@"cloud_color"] rgbaDescription],[(OOColor *)[planetInfo objectForKey:@"polar_cloud_color"] rgbaDescription]);
173
174 _materialParameters = [planetInfo dictionaryWithValuesForKeys:[NSArray arrayWithObjects:@"cloud_fraction", @"air_color", @"air_color_mix_ratio", @"air_density", @"cloud_color", @"polar_cloud_color", @"cloud_alpha", @"land_fraction", @"land_color", @"sea_color", @"polar_land_color", @"polar_sea_color", @"noise_map_seed", @"economy", @"polar_fraction", @"isMiniature", @"perlin_3d", @"terminator_threshold_vector", nil]];
175 } else
176#else
177 // NEW_ATMOSPHERE is 0? still differentiate between normal planets and moons.
178 if (atmosphere) {
179 _atmosphereDrawable = [[OOPlanetDrawable atmosphereWithRadius:collision_radius + ATMOSPHERE_DEPTH] retain];
180 _airColor = [[OOColor colorWithRed:0.8f green:0.8f blue:0.9f alpha:1.0f] retain];
181 }
182 if (YES) // create _materialParameters when NEW_ATMOSPHERE is set to 0
183#endif
184 {
185 _materialParameters = [planetInfo dictionaryWithValuesForKeys:[NSArray arrayWithObjects:@"land_fraction", @"land_color", @"sea_color", @"polar_land_color", @"polar_sea_color", @"noise_map_seed", @"economy", @"polar_fraction", @"isMiniature", @"perlin_3d", @"terminator_threshold_vector", @"illumination_color", nil]];
186 }
187 [_materialParameters retain];
188
189 _mesopause2 = (atmosphere) ? (kMesosphere + collision_radius) * (kMesosphere + collision_radius) : 0.0;
190
191 _normSpecMapName = [[dict oo_stringForKey:@"texture_normspec"] retain]; // must be set up before _textureName
192
193 _textureName = [[dict oo_stringForKey:@"texture"] retain];
194 [self setUpPlanetFromTexture:_textureName];
195 [_planetDrawable setRadius:collision_radius];
196
197 // Orientation should be handled by the code that calls this planetEntity. Starting with a default value anyway.
198 orientation = (Quaternion) { M_SQRT1_2, M_SQRT1_2, 0, 0 };
199 _atmosphereOrientation = kIdentityQuaternion;
200 _rotationAxis = vector_up_from_quaternion(orientation);
201
202 // set speed of rotation.
203 if ([dict objectForKey:@"rotational_velocity"]) {
204 _rotationalVelocity = [dict oo_floatForKey:@"rotational_velocity" defaultValue:0.01f * randf()]; // 0.0 .. 0.01 avr 0.005
205 } else {
206 _rotationalVelocity = [planetInfo oo_floatForKey:@"rotation_speed" defaultValue:0.005f * randf()]; // 0.0 .. 0.005 avr 0.0025
207 _rotationalVelocity *= [planetInfo oo_floatForKey:@"rotation_speed_factor" defaultValue:1.0f];
208 }
209
210 _atmosphereRotationalVelocity = [dict oo_floatForKey:@"atmosphere_rotational_velocity" defaultValue:0.01f * randf()];
211
212 // set energy
213 energy = collision_radius * 1000.0f;
214
215 setRandomSeed(savedRndSeed);
216 RANROTSetFullSeed(savedRanrotSeed);
217
218 // rotate planet based on current time, needs to be done here - backported from PlanetEntity.
219 int deltaT = floor(fmod([PLAYER clockTimeAdjusted], 86400));
220 quaternion_rotate_about_axis(&orientation, _rotationAxis, _rotationalVelocity * deltaT);
221 quaternion_rotate_about_axis(&_atmosphereOrientation, kBasisYVector, _atmosphereRotationalVelocity * deltaT);
222
223#ifdef OO_DUMP_PLANETINFO
224#define CPROP(PROP) OOLog(@"planetinfo.record", @ #PROP " = %@;", [(OOColor*)[planetInfo objectForKey:@ #PROP] descriptionComponents]);
225#define FPROP(PROP) OOLog(@"planetinfo.record", @ #PROP " = %f;", [planetInfo oo_floatForKey:@"" #PROP]);
226 CPROP(air_color);
227 CPROP(illumination_color);
228 FPROP(air_color_mix_ratio);
229 FPROP(cloud_alpha);
230 CPROP(cloud_color);
231 FPROP(cloud_fraction);
232 CPROP(land_color);
233 FPROP(land_fraction);
234 CPROP(polar_cloud_color);
235 CPROP(polar_land_color);
236 CPROP(polar_sea_color);
237 CPROP(sea_color);
238 OOLog(@"planetinfo.record", @"rotation_speed = %f", _rotationalVelocity);
239#endif
240
241 [self setStatus:STATUS_ACTIVE];
242
244
245 return self;
246}
247
248static Vector RandomHSBColor(void)
249{
250 return (Vector) {
251 gen_rnd_number() / 256.0,
252 gen_rnd_number() / 256.0,
253 0.5 + gen_rnd_number() / 512.0
254 };
255}
256
257static Vector LighterHSBColor(Vector c)
258{
259 return (Vector) {
260 c.x,
261 c.y * 0.25f,
262 1.0f - (c.z * 0.1f)
263 };
264}
265
266static Vector HSBColorWithColor(OOColor* color)
267{
268 OOHSBAComponents c = [color hsbaComponents];
269 return (Vector) { c.h / 360, c.s, c.b };
270}
271
272static OOColor* ColorWithHSBColor(Vector c)
273{
274 return [OOColor colorWithHue:c.x saturation:c.y brightness:c.z alpha:1.0];
275}
276
277- (void)setUpTypeParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo
278{
279 [targetInfo oo_setBool:[sourceInfo oo_boolForKey:@"mainForLocalSystem"] forKey:@"mainForLocalSystem"];
280 [targetInfo oo_setBool:[sourceInfo oo_boolForKey:@"isMiniature"] forKey:@"isMiniature"];
281}
282
283- (void)setUpTerrainParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo
284{
285 NSArray* keys = [NSArray arrayWithObjects:@"atmosphere_rotational_velocity", @"rotational_velocity", @"cloud_alpha", @"has_atmosphere", @"percent_cloud", @"percent_ice", @"percent_land", @"radius", @"seed", nil];
286 NSString* key = nil;
287 foreach (key, keys) {
288 id sval = [sourceInfo objectForKey:key];
289 if (sval != nil) {
290 [targetInfo setObject:sval forKey:key];
291 }
292 }
293}
294
295- (void)setUpLandParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo
296{
297 [self setUpColorParametersWithSourceInfo:sourceInfo targetInfo:targetInfo isAtmosphere:NO];
298}
299
300- (void)setUpAtmosphereParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo
301{
302 [self setUpColorParametersWithSourceInfo:sourceInfo targetInfo:targetInfo isAtmosphere:YES];
303}
304
305- (void)setUpColorParametersWithSourceInfo:(NSDictionary*)sourceInfo targetInfo:(NSMutableDictionary*)targetInfo isAtmosphere:(BOOL)isAtmosphere
306{
307 // Stir the PRNG fourteen times for backwards compatibility.
308 unsigned i;
309 for (i = 0; i < 14; i++) {
311 }
312
313 Vector landHSB, seaHSB, landPolarHSB, seaPolarHSB, illumHSB;
314 Vector terminatorThreshold;
315 OOColor* color;
316
317 landHSB = RandomHSBColor();
318
319 if (!isAtmosphere) {
320 do {
321 seaHSB = RandomHSBColor();
322 } while (dot_product(landHSB, seaHSB) > .80f); // make sure land and sea colors differ significantly
323
324 // saturation bias - avoids really grey oceans
325 if (seaHSB.y < 0.22f)
326 seaHSB.y = seaHSB.y * 0.3f + 0.2f;
327 // brightness bias - avoids really bright landmasses
328 if (landHSB.z > 0.66f)
329 landHSB.z = 0.66f;
330
331 // planetinfo.plist overrides
332 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"land_color"]];
333 if (color != nil)
334 landHSB = HSBColorWithColor(color);
335 else
336 ScanVectorFromString([sourceInfo oo_stringForKey:@"land_hsb_color"], &landHSB);
337
338 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"sea_color"]];
339 if (color != nil)
340 seaHSB = HSBColorWithColor(color);
341 else
342 ScanVectorFromString([sourceInfo oo_stringForKey:@"sea_hsb_color"], &seaHSB);
343
344 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"illumination_color"]];
345 if (color != nil)
346 illumHSB = HSBColorWithColor(color);
347 else {
348 NSString* illumHSBColorString = [sourceInfo oo_stringForKey:@"illumination_hsb_color"];
349 if (illumHSBColorString)
350 ScanVectorFromString(illumHSBColorString, &illumHSB);
351 else
352 illumHSB = HSBColorWithColor([OOColor colorWithRed:0.8f green:0.8f blue:0.4f alpha:1.0f]);
353 }
354
355 // polar areas are brighter but have less colour (closer to white)
356 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"polar_land_color"]];
357 if (color != nil) {
358 landPolarHSB = HSBColorWithColor(color);
359 } else {
360 landPolarHSB = LighterHSBColor(landHSB);
361 }
362
363 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"polar_sea_color"]];
364 if (color != nil) {
365 seaPolarHSB = HSBColorWithColor(color);
366 } else {
367 seaPolarHSB = LighterHSBColor(seaHSB);
368 }
369
370 [targetInfo setObject:ColorWithHSBColor(landHSB) forKey:@"land_color"];
371 [targetInfo setObject:ColorWithHSBColor(seaHSB) forKey:@"sea_color"];
372 [targetInfo setObject:ColorWithHSBColor(landPolarHSB) forKey:@"polar_land_color"];
373 [targetInfo setObject:ColorWithHSBColor(seaPolarHSB) forKey:@"polar_sea_color"];
374 [targetInfo setObject:ColorWithHSBColor(illumHSB) forKey:@"illumination_color"];
375 } else {
376 landHSB = RandomHSBColor(); // NB: randomcolor is called twice to make the cloud colour similar to the old one.
377
378 // add a cloud_color tinge to sky blue({0.66, 0.3, 1}).
379 seaHSB = vector_add(landHSB, ((Vector) { 1.333, 0.6, 2 })); // 1 part cloud, 2 parts sky blue
380 scale_vector(&seaHSB, 0.333);
381
382 float cloudAlpha = OOClamp_0_1_f([sourceInfo oo_floatForKey:@"cloud_alpha" defaultValue:1.0f]);
383 [targetInfo setObject:[NSNumber numberWithFloat:cloudAlpha] forKey:@"cloud_alpha"];
384
385 // planetinfo overrides
386 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"air_color"]];
387 if (color != nil)
388 seaHSB = HSBColorWithColor(color);
389
390 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"cloud_color"]];
391 if (color != nil)
392 landHSB = HSBColorWithColor(color);
393
394 // polar areas: brighter, less saturation
395 landPolarHSB = vector_add(landHSB, LighterHSBColor(landHSB));
396 scale_vector(&landPolarHSB, 0.5);
397
398 color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"polar_cloud_color"]];
399 if (color != nil)
400 landPolarHSB = HSBColorWithColor(color);
401
402 [targetInfo setObject:ColorWithHSBColor(seaHSB) forKey:@"air_color"];
403 [targetInfo setObject:ColorWithHSBColor(landHSB) forKey:@"cloud_color"];
404 [targetInfo setObject:ColorWithHSBColor(landPolarHSB) forKey:@"polar_cloud_color"];
405 [targetInfo setObject:[NSNumber numberWithFloat:[sourceInfo oo_floatForKey:@"air_color_mix_ratio"]] forKey:@"air_color_mix_ratio"];
406 }
407 terminatorThreshold = [sourceInfo oo_vectorForKey:@"terminator_threshold_vector" defaultValue:OO_TERMINATOR_THRESHOLD_VECTOR_DEFAULT];
408 [targetInfo setObject:[NSString stringWithFormat:@"%f %f %f", terminatorThreshold.x, terminatorThreshold.y, terminatorThreshold.z] forKey:@"terminator_threshold_vector"];
409}
410
411- (id)initAsMiniatureVersionOfPlanet:(OOPlanetEntity*)planet
412{
413 // Nasty, nasty. I'd really prefer to have a separate entity class for this.
414 if (planet == nil) {
415 [self release];
416 return nil;
417 }
418
419 self = [self init];
420 if (self == nil)
421 return nil;
422
423 scanClass = CLASS_NO_DRAW;
424 [self setStatus:STATUS_COCKPIT_DISPLAY];
425
426 collision_radius = planet->collision_radius * PLANET_MINIATURE_FACTOR;
427 orientation = planet->orientation;
428 _rotationAxis = planet->_rotationAxis;
429 _atmosphereOrientation = planet->_atmosphereOrientation;
430 _rotationalVelocity = 0.04;
431
432 _terminatorThresholdVector = planet->_terminatorThresholdVector;
433
434 _miniature = YES;
435
436 _planetDrawable = [planet->_planetDrawable copy];
437 [_planetDrawable setRadius:collision_radius];
438
439 // FIXME: in old planet code, atmosphere (if textured) is set to 0.6 alpha.
440 _atmosphereDrawable = [planet->_atmosphereDrawable copy];
441 _cloudsShaderDrawable = [planet->_cloudsShaderDrawable copy];
442 _atmosphereShaderDrawable = [planet->_atmosphereShaderDrawable copy];
443 [_atmosphereDrawable setRadius:collision_radius + ATMOSPHERE_DEPTH * PLANET_MINIATURE_FACTOR * 2.0]; // not to scale: invisible otherwise
444 if (_cloudsShaderDrawable)
445 [_cloudsShaderDrawable setRadius:collision_radius + ATMOSPHERE_DEPTH * PLANET_MINIATURE_FACTOR * 2.0]; // not to scale: invisible otherwise
446 if (_atmosphereShaderDrawable)
447 [_atmosphereShaderDrawable setRadius:collision_radius + ATMOSPHERE_DEPTH * PLANET_MINIATURE_FACTOR * 2.0];
448
449 [_planetDrawable setLevelOfDetail:0.8f];
450 [_atmosphereDrawable setLevelOfDetail:0.8f];
451 if (_cloudsShaderDrawable)
452 [_cloudsShaderDrawable setLevelOfDetail:0.8f];
453 if (_atmosphereShaderDrawable)
454 [_atmosphereShaderDrawable setLevelOfDetail:0.8f];
455
456 return self;
457}
458
459- (void)dealloc
460{
461 DESTROY(_name);
462 DESTROY(_planetDrawable);
463 DESTROY(_atmosphereDrawable);
464 DESTROY(_cloudsShaderDrawable);
465 DESTROY(_atmosphereShaderDrawable);
466 DESTROY(_airColor);
467 DESTROY(_illuminationColor);
468 DESTROY(_materialParameters);
469 DESTROY(_textureName);
470 DESTROY(_normSpecMapName);
471
473
474 [super dealloc];
475}
476
477- (NSString*)descriptionComponents
478{
479 return [NSString stringWithFormat:@"position: %@ radius: %g m", HPVectorDescription([self position]), [self radius]];
480}
481
482- (void)setOrientation:(Quaternion)quat
483{
484 [super setOrientation:quat];
485 _rotationAxis = vector_up_from_quaternion(quat);
486}
487
488- (double)radius
489{
490 return collision_radius;
491}
492
493- (OOStellarBodyType)planetType
494{
495 if (_miniature)
497 if (_atmosphereDrawable != nil)
499 return STELLAR_TYPE_MOON;
500}
501
502- (instancetype)miniatureVersion
503{
504 return [[[[self class] alloc] initAsMiniatureVersionOfPlanet:self] autorelease];
505}
506
507- (void)update:(OOTimeDelta)delta_t
508{
509 [super update:delta_t];
510
511 if (EXPECT(!_miniature)) {
512 BOOL canDrawShaderAtmosphere = _atmosphereShaderDrawable && [UNIVERSE detailLevel] >= DETAIL_LEVEL_SHADERS;
513 if (EXPECT_NOT(_atmosphereDrawable && cam_zero_distance < _mesopause2)) {
514 NSAssert(_airColor != nil, @"Expected a non-nil air colour for normal planet. Exiting.");
515 double alt = (sqrt(cam_zero_distance) - collision_radius) / kMesosphere; // the viewpoint altitude
516 double trueAlt = (sqrt(zero_distance) - collision_radius) / kMesosphere; // the actual ship altitude
517 // if at long distance external view, rotating the camera could potentially end up with it being
518 // at negative altitude. Since we know we are already inside the atmosphere at this point, just make sure
519 // that altitude is kept to a minimum positive value to avoid sudden black skies
520 if (alt <= 0.0)
521 alt = 1e-4;
522 if (EXPECT_NOT(alt > 0 && alt <= 1.0)) // ensure aleph is clamped between 0 and 1
523 {
524 double aleph = 1.0 - alt;
525 double aleph2 = aleph * aleph;
526
527 // night sky, reddish flash on entering the atmosphere, low light pollution otherwhise
528 OOColor* mixColor = [OOColor colorWithRed:(EXPECT_NOT(alt > 0.98) ? 30.0f : 0.1f)
529 green:0.1f
530 blue:0.1f
531 alpha:aleph];
532
533 // occlusion rate: .9 is 18 degrees after the terminus, where twilight ends.
534 // 1 is the terminus, 1.033 is 6 degrees before the terminus, where the sky begins to redden
535 double rate = ([PLAYER occlusionLevel] - 0.97) / 0.06; // from 0.97 to 1.03
536
537 if (EXPECT(rate <= 1.0 && rate > 0.0)) {
538 mixColor = [mixColor blendedColorWithFraction:rate ofColor:_airColor];
539 // TODO: properly calculated pink sky - needs to depend on sun's angular size,
540 // and its angular height on the horizon.
541 /*
542 rate -= 0.7;
543 if (rate >= 0.0) // pink sky!
544 {
545 rate = 0.5 - (fabs(rate - 0.15) / 0.3); // at most a 50% blend!
546 mixColor = [mixColor blendedColorWithFraction:rate ofColor:[OOColor colorWithRed:0.6
547 green:0.1
548 blue:0.0
549 alpha:aleph]];
550 }
551 */
552 } else {
553 if (PLAYER->isSunlit && _airColor != nil)
554 mixColor = _airColor;
555 }
556 [UNIVERSE setSkyColorRed:[mixColor redComponent] * aleph2
557 green:[mixColor greenComponent] * aleph2
558 blue:[mixColor blueComponent] * aleph
559 alpha:aleph];
560 double atmosphereRadius = canDrawShaderAtmosphere ? collision_radius : collision_radius + (ATMOSPHERE_DEPTH * alt);
561 [_atmosphereDrawable setRadius:atmosphereRadius];
562 if (_cloudsShaderDrawable)
563 [_cloudsShaderDrawable setRadius:atmosphereRadius];
564 if (_atmosphereShaderDrawable)
565 [_atmosphereShaderDrawable setRadius:collision_radius + (ATMOSPHERE_DEPTH * alt)];
566 // apply air resistance for the ship, not the camera. Although setSkyColorRed
567 // has already set the air resistance to aleph, override it immediately
568 [UNIVERSE setAirResistanceFactor:OOClamp_0_1_f(1.0 - trueAlt)];
569 }
570 } else {
571 if (EXPECT_NOT([_atmosphereDrawable radius] < collision_radius + ATMOSPHERE_DEPTH)) {
572 [_atmosphereDrawable setRadius:collision_radius + ATMOSPHERE_DEPTH];
573 if (_cloudsShaderDrawable)
574 [_cloudsShaderDrawable setRadius:collision_radius * ATMOSPHERE_DEPTH];
575 if (_atmosphereShaderDrawable)
576 [_atmosphereShaderDrawable setRadius:collision_radius + ATMOSPHERE_DEPTH];
577 }
578 if (canDrawShaderAtmosphere && [_atmosphereDrawable radius] != collision_radius) {
579 // if shader atmo is in use, force texture atmo radius to just collision_radius for cosmetic purposes
580 [_atmosphereDrawable setRadius:collision_radius];
581 if (_cloudsShaderDrawable)
582 [_cloudsShaderDrawable setRadius:collision_radius];
583 }
584 if ([PLAYER findNearestPlanet] == self) // ensure no problems in case of more than one planets
585 {
586 [UNIVERSE setAirResistanceFactor:0.0f]; // out of atmosphere - no air friction
587 }
588 }
589
590 double time = [UNIVERSE getTime];
591
592 if (_shuttlesOnGround > 0 && time > _lastLaunchTime + _shuttleLaunchInterval)
593 [self launchShuttle];
594 }
595
596 quaternion_rotate_about_axis(&orientation, _rotationAxis, _rotationalVelocity * delta_t);
597 // atmosphere orientation is relative to the orientation of the planet
598 quaternion_rotate_about_axis(&_atmosphereOrientation, kBasisYVector, _atmosphereRotationalVelocity * delta_t);
599
600 [self orientationChanged];
601
602 // FIXME: update atmosphere rotation
603}
604
605- (BOOL)isFinishedLoading
606{
607 OOMaterial* material = [self material];
608 if (material != nil && ![material isFinishedLoading])
609 return NO;
610 material = [self atmosphereMaterial];
611 if (material != nil && ![material isFinishedLoading])
612 return NO;
613 material = [self atmosphereShaderMaterial];
614 if (material != nil && ![material isFinishedLoading])
615 return NO;
616 return YES;
617}
618
619- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
620{
621 BOOL canDrawShaderAtmosphere = _atmosphereShaderDrawable && [UNIVERSE detailLevel] >= DETAIL_LEVEL_SHADERS;
622
623 if ([UNIVERSE breakPatternHide])
624 return; // DON'T DRAW
625 if (_miniature && ![self isFinishedLoading])
626 return; // For responsiveness, don't block to draw as miniature.
627
628 // too far away to be drawn
629 if (magnitude(cameraRelativePosition) > [self radius] * 3000) {
630 return;
631 }
632 if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:([self radius] + ATMOSPHERE_DEPTH)]) {
633 // Don't draw
634 return;
635 }
636
637 if ([UNIVERSE wireframeGraphics])
639
640 if (!_miniature) {
641 [_planetDrawable calculateLevelOfDetailForViewDistance:cam_zero_distance];
642 [_atmosphereDrawable setLevelOfDetail:[_planetDrawable levelOfDetail]];
643 if (canDrawShaderAtmosphere) {
644 if (_cloudsShaderDrawable)
645 [_cloudsShaderDrawable setLevelOfDetail:[_planetDrawable levelOfDetail]];
646 [_atmosphereShaderDrawable setLevelOfDetail:[_planetDrawable levelOfDetail]];
647 }
648 }
649
650 // 500km squared
651 // if (magnitude2(cameraRelativePosition) > 250000000000.0)
652 /* Temporarily for 1.82 make this branch unconditional. There's an
653 * odd change in appearance when crossing this boundary, which can
654 * be quite noticeable. There don't appear to be close-range
655 * problems with doing it this way all the time, though it's not
656 * ideal. - CIM */
657 {
658 /* at this distance the atmosphere is too close to the planet
659 * for a 24-bit depth buffer to reliably distinguish the two,
660 * so cheat and draw the atmosphere on the opaque pass: it's
661 * far enough away that painter's algorithm should do fine */
662 [_planetDrawable renderOpaqueParts];
663 if (_atmosphereDrawable != nil) {
665 OOGLMultModelView(OOMatrixForQuaternionRotation(_atmosphereOrientation));
666 if (canDrawShaderAtmosphere) {
667 if (_cloudsShaderDrawable)
668 [_cloudsShaderDrawable renderTranslucentPartsOnOpaquePass];
669 [_atmosphereShaderDrawable renderTranslucentPartsOnOpaquePass];
670 } else {
671 [_atmosphereDrawable renderTranslucentPartsOnOpaquePass];
672 }
674 }
675 }
676#if OOLITE_HAVE_FIXED_THE_ABOVE_DESCRIBED_BUG_WHICH_WE_HAVENT
677 else
678 {
679 /* At close range we can do this properly and draw the
680 * atmosphere on the transparent pass */
681 if (translucent) {
682 if (_atmosphereDrawable != nil) {
684 OOGLMultModelView(OOMatrixForQuaternionRotation(_atmosphereOrientation));
685 [_atmosphereDrawable renderTranslucentParts];
686 if (canDrawShaderAtmosphere)
687 [_atmosphereShaderDrawable renderTranslucentParts];
689 }
690 } else {
691 [_planetDrawable renderOpaqueParts];
692 }
693 }
694#endif
695
696 if ([UNIVERSE wireframeGraphics])
698}
699
700- (BOOL)checkCloseCollisionWith:(Entity*)other
701{
702 if (!other)
703 return NO;
704 if (other->isShip) {
705 ShipEntity* ship = (ShipEntity*)other;
706 if ([ship behaviour] == BEHAVIOUR_LAND_ON_PLANET) {
707 return NO;
708 }
709 }
710
711 return YES;
712}
713
714- (BOOL)planetHasStation
715{
716 // find the nearest station...
717 ShipEntity* station = nil;
718 station = [UNIVERSE nearestShipMatchingPredicate:IsStationPredicate
719 parameter:nil
720 relativeToEntity:self];
721
722 if (station && HPdistance([station position], position) < 4 * collision_radius) // there is a station in range.
723 {
724 return YES;
725 }
726 return NO;
727}
728
729- (void)launchShuttle
730{
731 if (_shuttlesOnGround == 0) {
732 return;
733 }
734 if ([PLAYER status] == STATUS_START_GAME) {
735 // don't launch if game not started
736 return;
737 }
738 if (self != [UNIVERSE planet] && ![self planetHasStation]) {
739 // don't launch shuttles when no station is nearby.
740 _shuttlesOnGround = 0;
741 return;
742 }
743
744 Quaternion q1;
746 float start_distance = collision_radius + 125.0f;
748
749 ShipEntity* shuttle_ship = [UNIVERSE newShipWithRole:@"shuttle"]; // retain count = 1
750 if (shuttle_ship) {
751 if ([[shuttle_ship crew] count] == 0) {
752 [shuttle_ship setSingleCrewWithRole:@"trader"];
753 }
754
755 [shuttle_ship setPosition:launch_pos];
756 [shuttle_ship setOrientation:q1];
757
758 [shuttle_ship setScanClass:CLASS_NEUTRAL];
759 [shuttle_ship setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL];
760 [shuttle_ship switchAITo:@"oolite-shuttleAI.js"];
761 [UNIVERSE addEntity:shuttle_ship]; // STATUS_IN_FLIGHT, AI state GLOBAL
762 _shuttlesOnGround--;
763 _lastLaunchTime = [UNIVERSE getTime];
764
765 [shuttle_ship release];
766 }
767}
768
769- (void)welcomeShuttle:(ShipEntity*)shuttle
770{
771 _shuttlesOnGround++;
772}
773
774- (BOOL)isPlanet
775{
776 return YES;
777}
778
779- (BOOL)isVisible
780{
781 return YES;
782}
783
784- (double)rotationalVelocity
785{
786 return _rotationalVelocity;
787}
788
789- (void)setRotationalVelocity:(double)v
790{
791 if ([self hasAtmosphere]) {
792 // FIXME: change atmosphere rotation speed proportionally
793 }
794 _rotationalVelocity = v;
795}
796
797// this method is visible to shader bindings, hence it returns vector
798- (Vector)airColorAsVector
799{
800 float r, g, b, a;
801 [_airColor getRed:&r green:&g blue:&b alpha:&a];
802 return make_vector(r, g, b); // don't care about a
803}
804
805- (OOColor*)airColor
806{
807 return _airColor;
808}
809
810- (void)setAirColor:(OOColor*)newColor
811{
812 if (newColor) {
813 [_airColor release];
814 _airColor = [newColor retain];
815 }
816}
817
818// this method is visible to shader bindings, hence it returns vector
819- (Vector)illuminationColorAsVector
820{
821 float r, g, b, a;
822 [_illuminationColor getRed:&r green:&g blue:&b alpha:&a];
823 return make_vector(r, g, b); // don't care about a
824}
825
826- (OOColor*)illuminationColor
827{
828 return _illuminationColor;
829}
830
831- (void)setIlluminationColor:(OOColor*)newColor
832{
833 if (newColor) {
834 [_illuminationColor release];
835 _illuminationColor = [newColor retain];
836 }
837}
838
839// visible to shader bindings
840- (float)airColorMixRatio
841{
842 return _airColorMixRatio;
843}
844
845- (void)setAirColorMixRatio:(float)newRatio
846{
847 _airColorMixRatio = OOClamp_0_1_f(newRatio);
848}
849
850// visible to shader bindings
851- (float)airDensity
852{
853 return _airDensity;
854}
855
856- (void)setAirDensity:(float)newDensity
857{
858 _airDensity = OOClamp_0_1_f(newDensity);
859}
860
861- (void)setTerminatorThresholdVector:(Vector)newTerminatorThresholdVector
862{
863 _terminatorThresholdVector.x = newTerminatorThresholdVector.x;
864 _terminatorThresholdVector.y = newTerminatorThresholdVector.y;
865 _terminatorThresholdVector.z = newTerminatorThresholdVector.z;
866}
867
868- (Vector)terminatorThresholdVector
869{
870 return _terminatorThresholdVector;
871}
872
873- (BOOL)hasAtmosphere
874{
875 return _atmosphereDrawable != nil;
876}
877
878// FIXME: need material model.
879- (NSString*)textureFileName
880{
881 return [_planetDrawable textureName];
882}
883
884- (void)resetGraphicsState
885{
886 // reset the texture if graphics mode changes
887 [self setUpPlanetFromTexture:_textureName];
888}
889
890- (void)setTextureFileName:(NSString*)textureName
891{
892 BOOL isMoon = _atmosphereDrawable == nil;
893
894 OOTexture* diffuseMap = nil;
895 OOTexture* normalMap = nil;
896 NSDictionary* macros = nil;
897 NSDictionary* materialDefaults = [ResourceManager materialDefaults];
898
899#if OO_SHADERS
900 OOGraphicsDetail detailLevel = [UNIVERSE detailLevel];
901 BOOL shadersOn = detailLevel >= DETAIL_LEVEL_SHADERS;
902#else
903 const BOOL shadersOn = NO;
904#endif
905
906 if (textureName != nil) {
907 NSDictionary* spec = [NSDictionary dictionaryWithObjectsAndKeys:textureName, @"name", @"yes", @"repeat_s", @"linear", @"min_filter", @"yes", @"cube_map", nil];
908 diffuseMap = [OOTexture textureWithConfiguration:spec];
909 if (diffuseMap == nil)
910 return; // OOTexture will have logged a file-not-found warning.
911 if (shadersOn) {
912 [diffuseMap ensureFinishedLoading]; // only know if it is a cube map if it's loaded
913 if ([diffuseMap isCubeMap]) {
914 macros = [materialDefaults oo_dictionaryForKey:isMoon ? @"moon-customized-cubemap-macros" : @"planet-customized-cubemap-macros"];
915 } else {
916 macros = [materialDefaults oo_dictionaryForKey:isMoon ? @"moon-customized-macros" : @"planet-customized-macros"];
917 }
918 } else
919 textureName = @"dynamic";
920
921 // let's try giving some love to normalMap too
922 if (_normSpecMapName) {
923 NSDictionary* nspec = [NSDictionary dictionaryWithObjectsAndKeys:_normSpecMapName, @"name", @"yes", @"repeat_s", @"linear", @"min_filter", @"yes", @"cube_map", nil];
924 normalMap = [OOTexture textureWithConfiguration:nspec];
925 if (normalMap != nil) // OOTexture will have logged a file-not-found warning.
926 {
927 if (shadersOn) {
928 [normalMap ensureFinishedLoading]; // only know if it is a cube map if it's loaded
929 if ([normalMap isCubeMap]) {
930 macros = [materialDefaults oo_dictionaryForKey:isMoon ? @"moon-customized-cubemap-normspec-macros" : @"planet-customized-cubemap-normspec-macros"];
931 } else {
932 macros = [materialDefaults oo_dictionaryForKey:isMoon ? @"moon-customized-normspec-macros" : @"planet-customized-normspec-macros"];
933 }
934 }
935 }
936 }
937 } else {
938 [OOPlanetTextureGenerator generatePlanetTexture:&diffuseMap
939 secondaryTexture:(detailLevel >= DETAIL_LEVEL_SHADERS) ? &normalMap : NULL
940 withInfo:_materialParameters];
941
942 if (shadersOn) {
943 macros = [materialDefaults oo_dictionaryForKey:isMoon ? @"moon-dynamic-macros" : @"planet-dynamic-macros"];
944 }
945 textureName = @"dynamic";
946 }
947
948 /* Generate atmosphere texture */
949 if (!isMoon) {
950 OOLog(@"texture.planet.generate", @"Preparing atmosphere for planet %@", self);
951 /* Generate a standalone atmosphere texture */
952 OOTexture* atmosphere = nil;
954 withInfo:_materialParameters];
955
956 OOLog(@"texture.planet.generate", @"Planet %@ has atmosphere %@", self, atmosphere);
957
958 OOSingleTextureMaterial* dynamicMaterial = [[OOSingleTextureMaterial alloc] initWithName:@"dynamic" texture:atmosphere configuration:nil];
959 [_atmosphereDrawable setMaterial:dynamicMaterial];
960
961 if (shadersOn) {
962 NSMutableDictionary* aConfig = [[[materialDefaults oo_dictionaryForKey:@"atmosphere-material"] mutableCopy] autorelease];
963 [aConfig setObject:[NSArray arrayWithObjects:diffuseMap, normalMap, nil] forKey:@"_oo_texture_objects"];
964
965 NSDictionary* amacros = [materialDefaults oo_dictionaryForKey:@"atmosphere-dynamic-macros"];
966
967 OOMaterial* dynamicShaderMaterial = [OOShaderMaterial shaderMaterialWithName:@"dynamic"
968 configuration:aConfig
969 macros:amacros
970 bindingTarget:self];
971
972 if (dynamicShaderMaterial == nil) {
973 DESTROY(_atmosphereShaderDrawable);
974 } else {
975 [_atmosphereShaderDrawable setMaterial:dynamicShaderMaterial];
976 }
977
978 NSMutableDictionary* cloudConfig = [[[materialDefaults oo_dictionaryForKey:@"clouds-dynamic-material"] mutableCopy] autorelease];
979 [cloudConfig setObject:[NSArray arrayWithObjects:atmosphere, nil] forKey:@"_oo_texture_objects"];
980 NSDictionary* cloudMacros = [materialDefaults oo_dictionaryForKey:@"clouds-dynamic-macros"];
981
982 OOMaterial* cloudsMaterial = [OOShaderMaterial shaderMaterialWithName:@"dynamic"
983 configuration:cloudConfig
984 macros:cloudMacros
985 bindingTarget:self];
986 if (cloudsMaterial == nil) {
987 DESTROY(_cloudsShaderDrawable);
988 } else {
989 [_cloudsShaderDrawable setMaterial:cloudsMaterial];
990 }
991 }
992
993 [dynamicMaterial release];
994 }
995
996 OOMaterial* material = nil;
997
998#if OO_SHADERS
999 if (shadersOn) {
1000 NSMutableDictionary* config = [[[materialDefaults oo_dictionaryForKey:@"planet-material"] mutableCopy] autorelease];
1001 [config setObject:[NSArray arrayWithObjects:diffuseMap, normalMap, nil] forKey:@"_oo_texture_objects"];
1002
1003 material = [OOShaderMaterial shaderMaterialWithName:textureName
1004 configuration:config
1005 macros:macros
1006 bindingTarget:self];
1007 }
1008#endif
1009 if (material == nil) {
1010 material = [[OOSingleTextureMaterial alloc] initWithName:textureName texture:diffuseMap configuration:nil];
1011 [material autorelease];
1012 }
1013 [_planetDrawable setMaterial:material];
1014}
1015
1016- (BOOL)setUpPlanetFromTexture:(NSString*)textureName
1017{
1018 [self setTextureFileName:textureName];
1019 return YES;
1020}
1021
1022- (OOMaterial*)material
1023{
1024 return [_planetDrawable material];
1025}
1026
1027- (OOMaterial*)atmosphereMaterial
1028{
1029 return [_atmosphereDrawable material];
1030}
1031
1032- (OOMaterial*)atmosphereShaderMaterial
1033{
1034 if (!_atmosphereShaderDrawable)
1035 return nil;
1036 return [_atmosphereShaderDrawable material];
1037}
1038
1039- (NSString*)name
1040{
1041 return _name;
1042}
1043
1044- (void)setName:(NSString*)name
1045{
1046 [_name release];
1047 _name = [name retain];
1048}
1049
1050@end
1051
1052#endif // NEW_PLANETS
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define DESTROY(x)
#define EXPECT_NOT(x)
#define EXPECT(x)
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
struct HPVector HPVector
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define M_SQRT1_2
Definition OOMaths.h:75
OOMatrix OOMatrixForQuaternionRotation(Quaternion orientation)
Definition OOMatrix.m:56
void OOGLPushModelView(void)
void OOGLMultModelView(OOMatrix matrix)
OOMatrix OOGLPopModelView(void)
void OOGLWireframeModeOn(void)
Definition OOOpenGL.m:85
void OOGLWireframeModeOff(void)
Definition OOOpenGL.m:100
unsigned count
return nil
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
struct Quaternion Quaternion
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
const Quaternion kIdentityQuaternion
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
void quaternion_set_random(Quaternion *quat) NONNULL_FUNC
#define PLANET_MINIATURE_FACTOR
#define ATMOSPHERE_DEPTH
OOStellarBodyType
@ STELLAR_TYPE_MOON
@ STELLAR_TYPE_MINIATURE
@ STELLAR_TYPE_NORMAL_PLANET
Random_Seed RandomSeedFromString(NSString *abcdefString)
BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector)
OOGraphicsDetail
Definition OOTypes.h:208
@ DETAIL_LEVEL_SHADERS
Definition OOTypes.h:211
NSUInteger OOTechLevelID
Definition OOTypes.h:177
int16_t OOSystemID
Definition OOTypes.h:183
double OOTimeDelta
Definition OOTypes.h:193
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE OOScalar magnitude(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:242
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
struct Vector Vector
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:299
const Vector kBasisYVector
Definition OOVector.h:46
OOINLINE void scale_vector(Vector *outVector, OOScalar factor) ALWAYS_INLINE_FUNC NONNULL_FUNC
Definition OOVector.h:166
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
#define PLAYER
#define UNIVERSE
Definition Universe.h:827
void setOrientation:(Quaternion quat)
Definition Entity.m:676
unsigned isShip
Definition Entity.m:125
void setScanClass:(OOScanClass sClass)
Definition Entity.m:738
void setPosition:(HPVector posn)
Definition Entity.m:608
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:107
float blueComponent()
Definition OOColor.m:339
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135
OOColor * colorWithHue:saturation:brightness:alpha:(float hue,[saturation] float saturation,[brightness] float brightness,[alpha] float alpha)
Definition OOColor.m:100
float redComponent()
Definition OOColor.m:329
OOHSBAComponents hsbaComponents()
Definition OOColor.m:431
OOColor * blendedColorWithFraction:ofColor:(float fraction,[ofColor] OOColor *color)
Definition OOColor.m:309
float greenComponent()
Definition OOColor.m:334
void registerClient:(id< OOGraphicsResetClient > client)
void unregisterClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()
instancetype atmosphereWithRadius:(float radius)
BOOL generateAtmosphereTexture:withInfo:(OOTexture **texture,[withInfo] NSDictionary *planetInfo)
void ensureFinishedLoading()
Definition OOTexture.m:278
id textureWithConfiguration:(id configuration)
Definition OOTexture.m:186
NSDictionary * materialDefaults()
void setCargoFlag:(OOCargoFlag flag)
void setSingleCrewWithRole:(NSString *crewRole)
void switchAITo:(NSString *aiString)
RANROTSeed RANROTGetFullSeed(void)
void setRandomSeed(RNG_Seed a_seed)
RNG_Seed currentRandomSeed(void)
void RANROTSetFullSeed(RANROTSeed seed)
int gen_rnd_number(void)
void seed_for_planet_description(Random_Seed s_seed)
struct RANROTSeed RANROTSeed
OOINLINE int is_nil_seed(Random_Seed a_seed) INLINE_CONST_FUNC
struct Random_Seed Random_Seed
struct RNG_Seed RNG_Seed
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34