Oolite
Loading...
Searching...
No Matches
PlanetEntity Class Reference

#include <PlanetEntity.h>

Inheritance diagram for PlanetEntity:
Collaboration diagram for PlanetEntity:

Instance Methods

(id) - initFromDictionary:withAtmosphere:andSeed:
(void) - miniaturize
(BOOL) - setUpPlanetFromTexture:
(int) - planet_seed
(BOOL) - isTextured
(BOOL) - isExplicitlyTextured
(OOTexture *) - texture
(NSString *) - textureFileName
(double) - polar_color_factor
(GLfloat *) - amb_land
(GLfloat *) - amb_polar_land
(GLfloat *) - amb_sea
(GLfloat *) - amb_polar_sea
(OOStellarBodyType) - planetType
(void) - setPlanetType:
(double) - radius
(void) - setRadius:
(double) - rotationalVelocity
(void) - setRotationalVelocity:
(BOOL) - hasAtmosphere
(void) - launchShuttle
(void) - welcomeShuttle:
(void) - drawUnconditionally
(id) - init [implementation]
(id) - initAsAtmosphereForPlanet:dictionary: [implementation]
(void) - dealloc [implementation]
(NSString *) - descriptionComponents [implementation]
(BOOL) - canCollide [implementation]
(BOOL) - checkCloseCollisionWith: [implementation]
(void) - update: [implementation]
(void) - setPosition: [implementation]
(void) - setOrientation: [implementation]
(void) - setUseTexturedModel: [implementation]
(void) - drawImmediate:translucent: [implementation]
(void) - setTextureColorForPlanet:inSystem: [implementation]
(double) - sqrtZeroDistance [implementation]
(void) - drawModelWithVertexArraysAndSubdivision: [implementation]
(void) - initialiseBaseVertexArray [implementation]
(void) - initialiseBaseTerrainArray: [implementation]
(void) - paintVertex:seed: [implementation]
(void) - scaleVertices [implementation]
(void) - deleteDisplayLists [implementation]
(void) - resetGraphicsState [implementation]
(void) - loadTexture: [implementation]
(OOTexture *) - planetTextureWithInfo: [implementation]
(OOTexture *) - cloudTextureWithCloudColor:cloudImpress:cloudBias: [implementation]
(BOOL) - isPlanet [implementation]
(BOOL) - isVisible [implementation]
(id) - initMiniatureFromPlanet:withAlpha: [implementation]
Instance Methods inherited from Entity
(NSUInteger) - sessionID
(BOOL) - isShip
(BOOL) - isDock
(BOOL) - isStation
(BOOL) - isSubEntity
(BOOL) - isPlayer
(BOOL) - isSun
(BOOL) - isSunlit
(BOOL) - isStellarObject
(BOOL) - isSky
(BOOL) - isWormhole
(BOOL) - isEffect
(BOOL) - isVisualEffect
(BOOL) - isWaypoint
(BOOL) - validForAddToUniverse
(void) - addToLinkedLists
(void) - removeFromLinkedLists
(void) - updateLinkedLists
(void) - wasAddedToUniverse
(void) - wasRemovedFromUniverse
(void) - warnAboutHostiles
(CollisionRegion *) - collisionRegion
(void) - setCollisionRegion:
(void) - setUniversalID:
(OOUniversalID) - universalID
(BOOL) - throwingSparks
(void) - setThrowSparks:
(void) - throwSparks
(void) - setOwner:
(id) - owner
(ShipEntity *) - parentEntity
(ShipEntity *) - rootShipEntity
(void) - setPositionX:y:z:
(HPVector) - position
(Vector) - cameraRelativePosition
(GLfloat) - cameraRangeFront
(GLfloat) - cameraRangeBack
(void) - updateCameraRelativePosition
(Vector) - vectorTo:
(HPVector) - absolutePositionForSubentity
(HPVector) - absolutePositionForSubentityOffset:
(double) - zeroDistance
(double) - camZeroDistance
(NSComparisonResult) - compareZeroDistance:
(BoundingBox) - boundingBox
(GLfloat) - mass
(Quaternion) - orientation
(Quaternion) - normalOrientation
(void) - setNormalOrientation:
(void) - orientationChanged
(void) - setVelocity:
(Vector) - velocity
(double) - speed
(GLfloat) - distanceTravelled
(void) - setDistanceTravelled:
(void) - setStatus:
(OOEntityStatus) - status
(void) - setScanClass:
(OOScanClass) - scanClass
(void) - setEnergy:
(GLfloat) - energy
(void) - setMaxEnergy:
(GLfloat) - maxEnergy
(void) - applyRoll:andClimb:
(void) - applyRoll:climb:andYaw:
(void) - moveForward:
(OOMatrix) - rotationMatrix
(OOMatrix) - drawRotationMatrix
(OOMatrix) - transformationMatrix
(OOMatrix) - drawTransformationMatrix
(GLfloat) - collisionRadius
(GLfloat) - frustumRadius
(void) - setCollisionRadius:
(NSMutableArray *) - collisionArray
(void) - applyVelocity:
(void) - takeEnergyDamage:from:becauseOf:weaponIdentifier:
(void) - dumpState
(void) - dumpSelfState
(NSUInteger) - lastDrawCounter
(void) - setLastDrawCounter:
(double) - findCollisionRadius
(BOOL) - isInSpace
(BOOL) - isImmuneToBreakPatternHide
(GLfloat) - universalTime
(GLfloat) - spawnTime
(GLfloat) - timeElapsedSinceSpawn
(void) - setAtmosphereFogging:
(OOColor *) - fogUniform
(BOOL) - checkLinkedLists [implementation]
(id< OOWeakReferenceSupport >) - superShaderBindingTarget [implementation]
(Vector) - relativePosition [implementation]
(void) - subEntityReallyDied: [implementation]
(BOOL) - isBreakPattern
(BOOL) - isECMBlast
(BOOL) - isExhaust
(BOOL) - isFlasher
(BOOL) - isVisibleToScripts
(BOOL) - isVisibleToScripts
(NSString *) - oo_jsClassName
(NSString *) - oo_jsClassName
(void) - getJSClass:andPrototype:
(void) - deleteJSSelf
(void) - deleteJSSelf
(JSClassID) - oo_jsClassID
(jsval) - oo_jsValueInContext: [implementation]
(BOOL) - isCascadeWeapon
(BOOL) - isPlayerLikeShip
(GLfloat) - clock [implementation]
(unsigned) - pseudoFixedD100 [implementation]
(unsigned) - pseudoFixedD256 [implementation]
(unsigned) - systemGovernment [implementation]
(unsigned) - systemEconomy [implementation]
(unsigned) - systemTechLevel [implementation]
(unsigned) - systemPopulation [implementation]
(unsigned) - systemProductivity [implementation]
(BOOL) - isShipWithSubEntityShip:
(void) - drawSubEntityImmediate:translucent: [implementation]
Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
(id) - weakRetain [implementation]
(void) - weakRefDied: [implementation]
Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED
Instance Methods inherited from <OOStellarBody>
(NSString *) - name
(void) - setName:

Class Methods

(static unsigned) + baseVertexIndexForEdge [implementation]

Private Attributes

OOStellarBodyType planet_type
uint8_t lastSubdivideLevel
BOOL useTexturedModel
BOOL isTextureImage
NSString * _textureFileName
OOTexture * _texture
int planet_seed
double polar_color_factor
double rotational_velocity
GLfloat amb_land [4]
GLfloat amb_polar_land [4]
GLfloat amb_sea [4]
GLfloat amb_polar_sea [4]
PlanetEntity * atmosphere
PlanetEntity * root_planet
int shuttles_on_ground
double last_launch_time
double shuttle_launch_interval
double sqrt_zero_distance
GLuint displayListNames [MAX_SUBDIVIDE]
GLuint vertexCount
VertexData vertexdata
Vector rotationAxis

Additional Inherited Members

Public Attributes inherited from Entity
OOUniversalID universalID
unsigned isShip: 1
unsigned isStation: 1
unsigned isPlayer: 1
unsigned isWormhole: 1
unsigned isSubEntity: 1
unsigned hasMoved: 1
unsigned hasRotated: 1
unsigned hasCollided: 1
unsigned isSunlit: 1
unsigned collisionTestFilter: 2
unsigned throw_sparks: 1
unsigned isImmuneToBreakPatternHide: 1
unsigned isExplicitlyNotMainStation: 1
unsigned isVisualEffect: 1
OOScanClass scanClass
GLfloat zero_distance
GLfloat cam_zero_distance
GLfloat no_draw_distance
GLfloat collision_radius
HPVector position
Vector cameraRelativePosition
Quaternion orientation
OOColor * atmosphereFogging
int zero_index
Entity * x_previous
Entity * x_next
Entity * y_previous
Entity * y_next
Entity * z_previous
Entity * z_next
Entity * collision_chain
OOUniversalID shadingEntityID
Entity * collider
CollisionRegion * collisionRegion
Protected Attributes inherited from Entity
HPVector lastPosition
Quaternion lastOrientation
GLfloat distanceTravelled
OOMatrix rotMatrix
Vector velocity
GLfloat energy
GLfloat maxEnergy
BoundingBox boundingBox
GLfloat mass
NSMutableArray * collidingEntities
OOTimeAbsolute spawnTime
struct JSObject * _jsSelf
NSUInteger lastDrawCounter
Protected Attributes inherited from OOWeakRefObject
OOWeakReference * weakSelf

Detailed Description

Definition at line 53 of file PlanetEntity.h.

Method Documentation

◆ amb_land

- (GLfloat *) amb_land

References amb_land.

◆ amb_polar_land

- (GLfloat *) amb_polar_land

References amb_polar_land.

◆ amb_polar_sea

- (GLfloat *) amb_polar_sea

References amb_polar_sea, atmosphere, drawUnconditionally, hasAtmosphere, launchShuttle, PlanetEntity, planetType, radius, and rotationalVelocity.

Here is the call graph for this function:

◆ amb_sea

- (GLfloat *) amb_sea

References amb_sea.

◆ baseVertexIndexForEdge

+ (unsigned) baseVertexIndexForEdge (GLushort) va
(GLushort) vb
(BOOL) textured 
implementation

Definition at line 1212 of file PlanetEntity.m.

1213{
1214 if (va < vb) {
1215 GLushort temp = va;
1216 va = vb;
1217 vb = temp;
1218 }
1219 void* key = (void*)(((uintptr_t)va << 16) | vb);
1220 uintptr_t num = (uintptr_t)NSMapGet(sEdgeToVertex, key);
1221 if (num != 0) {
1222 // Overall cache hit rate is just over 83 %.
1223 return (unsigned)num - 1;
1224 } else {
1225 unsigned vindex = next_free_vertex++;
1226 NSCAssert(vindex < sizeof base_vertex_array / sizeof *base_vertex_array, @"Vertex array overflow in planet setup.");
1227
1228 // calculate position of new vertex
1230 pos = vector_normal(pos); // guaranteed non-zero
1231 base_vertex_array[vindex] = pos;
1232
1233 if (textured) {
1234 // calculate new texture coordinates
1235 NSPoint uva = (NSPoint) { texture_uv_array[va * 2], texture_uv_array[va * 2 + 1] };
1236 NSPoint uvb = (NSPoint) { texture_uv_array[vb * 2], texture_uv_array[vb * 2 + 1] };
1237
1238 // if either of these is the polar vertex treat it specially to help with polar distortion:
1239 if (uva.y == 0.0 || uva.y == 1.0)
1240 uva.x = uvb.x;
1241 if (uvb.y == 0.0 || uvb.y == 1.0)
1242 uvb.x = uva.x;
1243
1244 texture_uv_array[vindex * 2] = 0.5 * (uva.x + uvb.x);
1245 texture_uv_array[vindex * 2 + 1] = 0.5 * (uva.y + uvb.y);
1246 }
1247
1248 // add new edge to the look-up
1249 num = vindex + 1;
1250 NSMapInsertKnownAbsent(sEdgeToVertex, key, (void*)num);
1251 return vindex;
1252 }
1253}
float y
float x
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
struct Vector Vector
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
static Vector base_vertex_array[MAX_PLANET_VERTICES]
static NSMapTable * sEdgeToVertex
static GLfloat texture_uv_array[MAX_PLANET_VERTICES *2]
static unsigned next_free_vertex

References base_vertex_array, next_free_vertex, sEdgeToVertex, texture_uv_array, vector_add(), and vector_normal().

Here is the call graph for this function:

◆ canCollide

- (BOOL) canCollide
implementation

Reimplemented from Entity.

Definition at line 590 of file PlanetEntity.m.

591{
592 switch (planet_type) {
595 return NO;
596 break;
599 case STELLAR_TYPE_SUN:
600 return YES;
601 break;
602 }
603 return YES;
604}
@ STELLAR_TYPE_MOON
@ STELLAR_TYPE_ATMOSPHERE
@ STELLAR_TYPE_MINIATURE
@ STELLAR_TYPE_SUN
@ STELLAR_TYPE_NORMAL_PLANET

References canCollide, planet_type, STELLAR_TYPE_ATMOSPHERE, STELLAR_TYPE_MINIATURE, STELLAR_TYPE_MOON, STELLAR_TYPE_NORMAL_PLANET, and STELLAR_TYPE_SUN.

Referenced by canCollide.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkCloseCollisionWith:

- (BOOL) checkCloseCollisionWith: (Entity*) other
implementation

Reimplemented from Entity.

Definition at line 606 of file PlanetEntity.m.

606 :(Entity*)other
607{
608#ifdef OO_DEBUG_MONITOR_ENABLED
610 OOLog(@"planet.collide", @"PLANET Collision!");
611#endif
612
613 if (!other)
614 return NO;
615 if (other->isShip) {
616 ShipEntity* ship = (ShipEntity*)other;
617 if ([ship behaviour] == BEHAVIOUR_LAND_ON_PLANET) {
618 return NO;
619 }
620#ifndef NDEBUG
621 if ([ship reportAIMessages]) {
622 HPVector p1 = ship->position;
623 OOLog(@"planet.collide.shipHit", @"DEBUG: %@ %d collided with planet at (%.1f,%.1f,%.1f)", [ship name], [ship universalID], p1.x, p1.y, p1.z);
624 }
625#endif
626 }
627
628 return YES;
629}
#define gDebugFlags
@ DEBUG_COLLISIONS
Definition OODebugFlags.h:6
struct HPVector HPVector
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned isShip
Definition Entity.m:125
HPVector position
Definition Entity.m:576
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38

References DEBUG_COLLISIONS, gDebugFlags, Entity::isShip, <OOStellarBody>::name, OOLog, Entity::position, Entity::universalID, HPVector::x, HPVector::y, and HPVector::z.

Here is the call graph for this function:

◆ cloudTextureWithCloudColor:cloudImpress:cloudBias:

- (OOTexture *) cloudTextureWithCloudColor: (OOColor*) cloudColor
cloudImpress: (GLfloat) cloud_impress
cloudBias: (GLfloat) cloud_bias 
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1452 of file PlanetEntity.m.

1452 :(OOColor*)cloudColor cloudImpress:(GLfloat)cloud_impress cloudBias:(GLfloat)cloud_bias
1453{
1454 unsigned char* data;
1455 GLuint width, height;
1456
1458 if (![TextureStore getCloudTextureNameFor:
1459 cloudColor:cloud_impress
1460 :cloud_bias
1461 intoData:&data
1462 width:&width
1463 height:&height]) {
1464 return nil;
1465 }
1466
1467 OOPixMap pm = OOMakePixMap(data, width, height, kOOPixMapRGBA, 0, 0);
1468 OOTextureGenerator* loader = [[OOPixMapTextureLoader alloc] initWithPixMap:pm
1469 textureOptions:kOOTextureDefaultOptions | kOOTextureRepeatS
1470 freeWhenDone:YES];
1471 [loader autorelease];
1472
1473 return [OOTexture textureWithGenerator:loader];
1474}
@ kOOPixMapRGBA
Definition OOPixMap.h:40
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:44
struct OOPixMap OOPixMap
return nil
void fillRanNoiseBuffer()
id textureWithGenerator:(OOTextureGenerator *generator)
Definition OOTexture.m:209

References fillRanNoiseBuffer(), kOOPixMapRGBA, nil, OOMakePixMap(), and OOTexture::textureWithGenerator:.

Referenced by PlanetEntity(OOPrivate)::initAsAtmosphereForPlanet:dictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Reimplemented from Entity.

Definition at line 554 of file PlanetEntity.m.

555{
556 [self deleteDisplayLists];
557
558 DESTROY(atmosphere);
559 DESTROY(_texture);
560 DESTROY(_textureFileName);
561
563
564 [super dealloc];
565}
#define DESTROY(x)
void unregisterClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()

References _texture, _textureFileName, atmosphere, Entity::dealloc, dealloc, deleteDisplayLists, DESTROY, OOGraphicsResetManager::sharedManager, and OOGraphicsResetManager::unregisterClient:.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteDisplayLists

- (void) deleteDisplayLists
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1382 of file PlanetEntity.m.

1383{
1384 unsigned i;
1385 for (i = 0; i < MAX_SUBDIVIDE; i++) {
1386 if (displayListNames[i] != 0) {
1387 glDeleteLists(displayListNames[i], 1);
1388 displayListNames[i] = 0;
1389 }
1390 }
1391}
#define MAX_SUBDIVIDE
GLuint displayListNames[MAX_SUBDIVIDE]

References PlanetEntity(OOPrivate)::deleteDisplayLists, and MAX_SUBDIVIDE.

Referenced by dealloc, PlanetEntity(OOPrivate)::deleteDisplayLists, PlanetEntity(OOPrivate)::initMiniatureFromPlanet:withAlpha:, resetGraphicsState, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented from Entity.

Definition at line 567 of file PlanetEntity.m.

568{
569 NSString* typeString;
570 switch (planet_type) {
572 typeString = @"STELLAR_TYPE_MINIATURE";
573 break;
575 typeString = @"STELLAR_TYPE_NORMAL_PLANET";
576 break;
578 typeString = @"STELLAR_TYPE_ATMOSPHERE";
579 break;
581 typeString = @"STELLAR_TYPE_MOON";
582 break;
583
584 default:
585 typeString = @"UNKNOWN";
586 }
587 return [NSString stringWithFormat:@"ID: %u position: %@ type: %@ radius: %.3fkm", [self universalID], HPVectorDescription([self position]), typeString, 0.001 * [self radius]];
588}

References descriptionComponents, planet_type, Entity::position, radius, STELLAR_TYPE_ATMOSPHERE, STELLAR_TYPE_MINIATURE, STELLAR_TYPE_MOON, STELLAR_TYPE_NORMAL_PLANET, and Entity::universalID.

Referenced by descriptionComponents.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawImmediate:translucent:

- (void) drawImmediate: (bool) immediate
translucent: (bool) translucent 
implementation

Reimplemented from Entity.

Definition at line 721 of file PlanetEntity.m.

721 :(bool)immediate translucent:(bool)translucent
722{
723 if ([UNIVERSE breakPatternHide] || translucent || immediate)
724 return; // DON'T DRAW
725 GLfloat radWithAtmosphere = [self radius] + ATMOSPHERE_DEPTH;
726 if (radWithAtmosphere * radWithAtmosphere * 1.1 < cam_zero_distance) {
727 // for some reason this check doesn't work when extremely close to
728 // the planet and with the horizon near the side of the frame (FP
729 // inaccuracy?)
730 if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:radWithAtmosphere]) {
731 // Don't draw
732 return;
733 }
734 }
735
736 [self drawUnconditionally];
737}
#define ATMOSPHERE_DEPTH
#define UNIVERSE
Definition Universe.h:827

References ATMOSPHERE_DEPTH, Entity::cam_zero_distance, Entity::cameraRelativePosition, drawUnconditionally, radius, and UNIVERSE.

Referenced by drawUnconditionally.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawModelWithVertexArraysAndSubdivision:

- (void) drawModelWithVertexArraysAndSubdivision: (int) subdivide
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1077 of file PlanetEntity.m.

1077 :(int)subdivide
1078{
1079 OOGL(glDrawElements(GL_TRIANGLES, 3 * n_triangles[subdivide], GL_UNSIGNED_INT, &vertexdata.index_array[triangle_start[subdivide]]));
1080}
#define OOGL(statement)
Definition OOOpenGL.h:262
static int triangle_start[MAX_SUBDIVIDE]
static int n_triangles[MAX_SUBDIVIDE]
VertexData vertexdata
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
GLuint index_array[MAX_TRI_INDICES]

References n_triangles, OOGL, and triangle_start.

Referenced by drawUnconditionally.

Here is the caller graph for this function:

◆ drawUnconditionally

- (void) drawUnconditionally

Definition at line 739 of file PlanetEntity.m.

740{
741 uint8_t subdivideLevel = 2; // 4 is probably the maximum!
742
743 double drawFactor = [[UNIVERSE gameView] viewSize].width / 100.0;
744 double drawRatio2 = drawFactor * collision_radius / sqrt_zero_distance; // equivalent to size on screen in pixels
745
746 if (cam_zero_distance > 0.0) {
747 subdivideLevel = 2 + floor(drawRatio2);
748 if (subdivideLevel > 4)
749 subdivideLevel = 4;
750 }
751
752 if (planet_type == STELLAR_TYPE_MINIATURE) {
753 subdivideLevel = [UNIVERSE reducedDetail] ? 3 : 4; // max detail or less
754 }
755
756 lastSubdivideLevel = subdivideLevel; // record
757
759 OOGL(glPushAttrib(GL_ENABLE_BIT));
760
761 // OOGL(glEnable(GL_LIGHTING));
762 // OOGL(glEnable(GL_LIGHT1));
763 GLfloat specular[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
764 OOGL(glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular));
765 OOGL(glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0));
766
767 /*
768
769 The depth test gets disabled in parts of this and instead
770 we rely on the painters algorithm instead.
771
772 The depth buffer isn't granular enough to cope with huge objects at vast
773 distances.
774
775 */
776
777 BOOL ignoreDepthBuffer = (planet_type == STELLAR_TYPE_ATMOSPHERE);
778
779 if (cam_zero_distance > collision_radius * collision_radius * 25) // is 'far away'
780 {
781 ignoreDepthBuffer |= YES;
782 }
783
784 [_texture ensureFinishedLoading];
785
786 switch (planet_type) {
788 if (root_planet) {
789 subdivideLevel = root_planet->lastSubdivideLevel; // copy it from the planet (stops jerky LOD and such)
790 }
791 OOGLMultModelVew(rotMatrix); // rotate the clouds!
792 OOGL(glEnable(GL_BLEND));
793 // OOGL(glDisable(GL_LIGHTING));
794 // Fall through.
795
799 // if ((gDebugFlags & DEBUG_WIREFRAME_GRAPHICS)
800 if ([UNIVERSE wireframeGraphics]) {
801 // Drop the detail level a bit, it still looks OK in wireframe and does not penalize
802 // the system that much.
803 subdivideLevel = 2;
805 }
806
807 {
808 GLfloat mat1[] = { 1.0, 1.0, 1.0, 1.0 }; // opaque white
809
810 if (_texture != nil) {
811 if ([_texture isCubeMap]) {
812#if OO_TEXTURE_CUBE_MAP
813 OOGL(glDisable(GL_TEXTURE_2D));
814 OOGL(glEnable(GL_TEXTURE_CUBE_MAP));
815#endif
816 } else {
817 // OOGL(glEnable(GL_TEXTURE_2D));
818 }
819 OOGL(glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, mat1));
820 [_texture apply];
821 } else {
822 OOGL(glDisable(GL_TEXTURE_2D));
824 }
825
826 OOGL(glShadeModel(GL_SMOOTH));
827
828 // far enough away to draw flat ?
829 if (ignoreDepthBuffer) {
830 OOGL(glDisable(GL_DEPTH_TEST));
831 }
832
833 OOGL(glColor4fv(mat1));
834 OOGL(glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat1));
835
836 OOGL(glEnableClientState(GL_COLOR_ARRAY));
837 OOGL(glColorPointer(4, GL_FLOAT, 0, vertexdata.color_array));
838 // OOGL(glEnableClientState(GL_VERTEX_ARRAY));
839 OOGL(glVertexPointer(3, GL_FLOAT, 0, vertexdata.vertex_array));
840 // OOGL(glEnableClientState(GL_NORMAL_ARRAY));
841 OOGL(glNormalPointer(GL_FLOAT, 0, vertexdata.normal_array));
842
843 if (_texture != nil) {
844 OOGL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
845 if ([_texture isCubeMap]) {
846 OOGL(glTexCoordPointer(3, GL_FLOAT, 0, vertexdata.vertex_array));
847 } else {
848 OOGL(glTexCoordPointer(2, GL_FLOAT, 0, vertexdata.uv_array));
849 }
850 } else {
851 OOGL(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
852 }
853
854 if (displayListNames[subdivideLevel] != 0) {
855 OOGL(glCallList(displayListNames[subdivideLevel]));
856 } else {
857
858 OOGL(displayListNames[subdivideLevel] = glGenLists(1));
859 if (displayListNames[subdivideLevel] != 0) // sanity check
860 {
861 OOGL(glNewList(displayListNames[subdivideLevel], GL_COMPILE_AND_EXECUTE));
862
863 OOGL(glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE));
864 OOGL(glEnable(GL_COLOR_MATERIAL));
865
866 [self drawModelWithVertexArraysAndSubdivision:subdivideLevel];
867
868 OOGL(glDisable(GL_COLOR_MATERIAL));
869 OOGL(glEndList());
870 }
871 }
872
873#if OO_TEXTURE_CUBE_MAP
874 if ([_texture isCubeMap]) {
875 OOGL(glDisable(GL_TEXTURE_CUBE_MAP));
876 OOGL(glEnable(GL_TEXTURE_2D));
877 }
878#endif
879
880 OOGL(glDisableClientState(GL_COLOR_ARRAY));
881 OOGL(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
882 OOGL(glEnable(GL_DEPTH_TEST));
883 }
884
885 // if ((gDebugFlags & DEBUG_WIREFRAME_GRAPHICS)
886 if ([UNIVERSE wireframeGraphics]) {
888 }
889 // OOGL(glDisableClientState(GL_VERTEX_ARRAY));
890 // OOGL(glDisableClientState(GL_NORMAL_ARRAY));
891
892 break;
893
894 case STELLAR_TYPE_SUN:
895 break;
896 }
897
898 if (ignoreDepthBuffer) {
899 OOGL(glEnable(GL_DEPTH_TEST));
900 }
901 OOGL(glEnable(GL_TEXTURE_2D));
902 // OOGL(glEnable(GL_LIGHTING));
903 OOGL(glDisable(GL_BLEND));
904
905 OOGL(glPopAttrib());
907 OOCheckOpenGLErrors(@"PlanetEntity after drawing %@", self);
908
909 if (atmosphere) {
910 OOGLPopModelView(); // get old draw matrix back
911 OOGLPushModelView(); // and store it again
912 OOGLTranslateModelView(cameraRelativePosition); // centre on the planet
913 // rotate
914 // OOGLMultModelView([atmosphere rotationMatrix]);
915 // draw atmosphere entity
916 [atmosphere drawImmediate:false translucent:false];
917 }
918}
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
OOMatrix OOGLPopModelView(void)
void OOGLWireframeModeOn(void)
Definition OOOpenGL.m:85
void OOGLWireframeModeOff(void)
Definition OOOpenGL.m:100
@ OPENGL_STATE_OPAQUE
Definition OOOpenGL.h:121
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
GLfloat collision_radius
Definition Entity.h:107
void applyNone()
Definition OOTexture.m:263
double sqrt_zero_distance
PlanetEntity * root_planet
uint8_t lastSubdivideLevel
OOStellarBodyType planet_type
GLfloat color_array[4 *MAX_PLANET_VERTICES]
GLfloat uv_array[2 *MAX_PLANET_VERTICES]
Vector vertex_array[MAX_PLANET_VERTICES+2]
Vector normal_array[MAX_PLANET_VERTICES]

References _texture, OOTexture::apply, OOTexture::applyNone, atmosphere, Entity::cam_zero_distance, Entity::cameraRelativePosition, Entity::collision_radius, displayListNames, drawImmediate:translucent:, drawModelWithVertexArraysAndSubdivision:, drawUnconditionally, OOTexture::ensureFinishedLoading, lastSubdivideLevel, nil, OOCheckOpenGLErrors(), OOGL, OOGLPopModelView(), OOGLPushModelView(), OOGLTranslateModelView(), OOGLWireframeModeOff(), OOGLWireframeModeOn(), OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_OPAQUE, planet_type, root_planet, Entity::rotMatrix, sqrt_zero_distance, STELLAR_TYPE_ATMOSPHERE, STELLAR_TYPE_MINIATURE, STELLAR_TYPE_MOON, STELLAR_TYPE_NORMAL_PLANET, STELLAR_TYPE_SUN, UNIVERSE, and vertexdata.

Referenced by amb_polar_sea, drawImmediate:translucent:, and drawUnconditionally.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasAtmosphere

- (BOOL) hasAtmosphere

Definition at line 1072 of file PlanetEntity.m.

1073{
1074 return atmosphere != nil;
1075}
PlanetEntity * atmosphere

References atmosphere, hasAtmosphere, and nil.

Referenced by amb_polar_sea, hasAtmosphere, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init

- (id) init
implementation

Reimplemented from Entity.

Definition at line 180 of file PlanetEntity.m.

181{
182 [self release];
183 [NSException raise:NSInternalInconsistencyException format:@"%s, believed dead, called.", __PRETTY_FUNCTION__];
184 return nil;
185}

References init, and nil.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initAsAtmosphereForPlanet:dictionary:

- (id) initAsAtmosphereForPlanet: (PlanetEntity*) planet
dictionary: (NSDictionary*) dict 
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 187 of file PlanetEntity.m.

187 :(PlanetEntity*)planet dictionary:(NSDictionary*)dict
188{
189 BOOL procGen = [UNIVERSE doProcedurallyTexturedPlanets];
190
191 if (dict == nil)
192 dict = [NSDictionary dictionary];
193
194 self = [super init];
195
196 int percent_land = 100 - [dict oo_intForKey:@"percent_cloud" defaultValue:100 - (3 + (gen_rnd_number() & 31) + (gen_rnd_number() & 31))];
197
198 polar_color_factor = 1.0;
199
200#define CLEAR_SKY_ALPHA 0.05
201#define CLOUD_ALPHA 0.50
202#define POLAR_CLEAR_SKY_ALPHA 0.34
203#define POLAR_CLOUD_ALPHA 0.75
204
205 amb_land[0] = gen_rnd_number() / 256.0;
206 amb_land[1] = gen_rnd_number() / 256.0;
207 amb_land[2] = gen_rnd_number() / 256.0;
208 amb_land[3] = CLEAR_SKY_ALPHA; // blue sky, zero clouds
209 amb_sea[0] = 0.5 + gen_rnd_number() / 512.0;
210 amb_sea[1] = 0.5 + gen_rnd_number() / 512.0;
211 amb_sea[2] = 0.5 + gen_rnd_number() / 512.0;
212 amb_sea[3] = CLOUD_ALPHA; // 50% opaque clouds
213 amb_polar_land[0] = gen_rnd_number() / 256.0;
214 amb_polar_land[1] = gen_rnd_number() / 256.0;
215 amb_polar_land[2] = gen_rnd_number() / 256.0;
216 amb_polar_land[3] = POLAR_CLEAR_SKY_ALPHA; // 34% gray clouds
217 amb_polar_sea[0] = 0.9 + gen_rnd_number() / 2560.0;
218 amb_polar_sea[1] = 0.9 + gen_rnd_number() / 2560.0;
219 amb_polar_sea[2] = 0.9 + gen_rnd_number() / 2560.0;
220 amb_polar_sea[3] = POLAR_CLOUD_ALPHA; // 75% clouds
221
222 // Colour overrides from dictionary
223 OOColor* clearSkyColor = nil;
224 OOColor* cloudColor = nil;
225 OOColor* polarClearSkyColor = nil;
226 OOColor* polarCloudColor = nil;
227 float cloudAlpha;
228
229 clearSkyColor = [OOColor colorWithDescription:[dict objectForKey:@"atmosphere_color"]];
230 cloudColor = [OOColor colorWithDescription:[dict objectForKey:@"cloud_color"]];
231 polarClearSkyColor = [OOColor colorWithDescription:[dict objectForKey:@"polar_atmosphere_color"]];
232 polarCloudColor = [OOColor colorWithDescription:[dict objectForKey:@"polar_cloud_color"]];
233 cloudAlpha = OOClamp_0_1_f([dict oo_floatForKey:@"cloud_alpha" defaultValue:1.0]);
234
235 if (clearSkyColor != nil) {
236 [clearSkyColor getRed:&amb_land[0] green:&amb_land[1] blue:&amb_land[2] alpha:&amb_land[3]];
237 }
238
239 if (cloudColor != nil) {
240 [cloudColor getRed:&amb_sea[0] green:&amb_sea[1] blue:&amb_sea[2] alpha:&amb_sea[3]];
241 }
242
243 if (polarClearSkyColor != nil) {
244 [polarClearSkyColor getRed:&amb_polar_land[0] green:&amb_polar_land[1] blue:&amb_polar_land[2] alpha:&amb_polar_land[3]];
245 } else if (clearSkyColor != nil) {
246 memmove(amb_polar_land, amb_land, sizeof amb_polar_land);
248 }
249
250 if (polarCloudColor != nil) {
251 [polarCloudColor getRed:&amb_polar_sea[0] green:&amb_polar_sea[1] blue:&amb_polar_sea[2] alpha:&amb_polar_sea[3]];
252 } else if (cloudColor != nil) {
253 memmove(amb_polar_sea, amb_sea, sizeof amb_polar_sea);
255 }
256
257 // amb_land[3] is already 0.05
258 amb_sea[3] *= cloudAlpha;
259 amb_polar_land[3] *= cloudAlpha;
260 amb_polar_sea[3] *= cloudAlpha;
261
262 amb_sea[3] = OOClamp_0_1_f(amb_sea[3]);
263 amb_polar_sea[3] = OOClamp_0_1_f(amb_polar_sea[3]);
264
265 atmosphere = nil;
266
267 if (procGen) {
268 RANROTSeed ranrotSavedSeed = RANROTGetFullSeed();
269 RNG_Seed saved_seed = currentRandomSeed();
270 cloudColor = [OOColor colorWithRed:amb_sea[0] green:amb_sea[1] blue:amb_sea[2] alpha:amb_sea[3]];
271 float cloud_bias = -0.01 * (float)percent_land;
272 float cloud_impress = 1.0 - cloud_bias;
273
274 _texture = [self cloudTextureWithCloudColor:cloudColor cloudImpress:cloud_impress cloudBias:cloud_bias];
275 [_texture retain];
276 isTextureImage = NO;
277
278 setRandomSeed(saved_seed);
279 RANROTSetFullSeed(ranrotSavedSeed);
280 }
281
282 if (!planet) {
283 OOLogERR(@"planet.atmosphere.init.noPlanet", @"planet entity initAsAtmosphereForPlanet: no planet found.");
284 return self;
285 }
286
287 [self setOwner:planet];
288
289 position = [planet position];
290 orientation = [planet orientation];
291
293 collision_radius = planet->collision_radius + ATMOSPHERE_DEPTH; // atmosphere is 500m deep only
294 if (planet->planet_type == STELLAR_TYPE_MINIATURE)
295 collision_radius = planet->collision_radius + ATMOSPHERE_DEPTH * PLANET_MINIATURE_FACTOR * 2.0; // not to scale: invisible otherwise
296
298 last_launch_time = 0.0;
300
301 scanClass = CLASS_NO_DRAW;
302
303 // orientation.w = M_SQRT1_2; // is already planet->orientation
304 // orientation.x = M_SQRT1_2;
305 // orientation.y = 0.0;
306 // orientation.z = 0.0;
307
309
310 planet_seed = ranrot_rand(); // random set-up for vertex colours
311
312 [self setUseTexturedModel:YES];
313 [self initialiseBaseVertexArray];
314 [self initialiseBaseTerrainArray:percent_land];
315 unsigned i;
316 for (i = 0; i < next_free_vertex; i++) {
317 [self paintVertex:i:planet_seed];
318 }
319
320 [self scaleVertices];
321
322 // set speed of rotation
323 rotational_velocity = [dict oo_floatForKey:@"atmosphere_rotational_velocity" defaultValue:[planet rotationalVelocity] * (0.9 + (randf() * 0.2))]; // 90-110% of planet rotation speed
324
325 root_planet = planet;
326
328
330
331 return self;
332}
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
#define PLANET_MINIATURE_FACTOR
#define PlanetEntity
#define CLOUD_ALPHA
#define POLAR_CLEAR_SKY_ALPHA
#define POLAR_CLOUD_ALPHA
#define CLEAR_SKY_ALPHA
Quaternion orientation
Definition Entity.m:682
OOScanClass scanClass
Definition Entity.m:743
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:107
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344
void registerClient:(id< OOGraphicsResetClient > client)
double rotational_velocity
double last_launch_time
Vector rotationAxis
GLfloat amb_polar_sea[4]
double shuttle_launch_interval
OOTexture * _texture
GLfloat amb_polar_land[4]
double polar_color_factor
GLfloat amb_land[4]
BOOL isTextureImage
GLfloat amb_sea[4]
int shuttles_on_ground
double rotationalVelocity()
RANROTSeed RANROTGetFullSeed(void)
void setRandomSeed(RNG_Seed a_seed)
RNG_Seed currentRandomSeed(void)
void RANROTSetFullSeed(RANROTSeed seed)
int gen_rnd_number(void)
struct RANROTSeed RANROTSeed
struct RNG_Seed RNG_Seed
#define ranrot_rand()

References ATMOSPHERE_DEPTH, CLEAR_SKY_ALPHA, CLOUD_ALPHA, cloudTextureWithCloudColor:cloudImpress:cloudBias:, Entity::collision_radius, OOColor::colorWithDescription:, OOColor::colorWithRed:green:blue:alpha:, currentRandomSeed(), gen_rnd_number(), OOColor::getRed:green:blue:alpha:, Entity::init, initialiseBaseTerrainArray:, initialiseBaseVertexArray, next_free_vertex, nil, OOClamp_0_1_f(), OOLogERR, Entity::orientation, PLANET_MINIATURE_FACTOR, planet_type, PlanetEntity, POLAR_CLEAR_SKY_ALPHA, POLAR_CLOUD_ALPHA, Entity::position, ranrot_rand, RANROTGetFullSeed(), RANROTSetFullSeed(), OOGraphicsResetManager::registerClient:, rotationalVelocity, scaleVertices, Entity::setOwner:, setRandomSeed(), setUseTexturedModel:, OOGraphicsResetManager::sharedManager, STELLAR_TYPE_ATMOSPHERE, STELLAR_TYPE_MINIATURE, STELLAR_TYPE_NORMAL_PLANET, and vector_up_from_quaternion().

Here is the call graph for this function:

◆ initFromDictionary:withAtmosphere:andSeed:

- (id) initFromDictionary: (NSDictionary*) dict
withAtmosphere: (BOOL) atmo
andSeed: (Random_Seed) p_seed 

Definition at line 351 of file PlanetEntity.m.

351 :(NSDictionary*)dict withAtmosphere:(BOOL)atmo andSeed:(Random_Seed)p_seed
352{
353 BOOL procGen = [UNIVERSE doProcedurallyTexturedPlanets];
354
355 if (dict == nil)
356 dict = [NSDictionary dictionary];
357 RANROTSeed ranrotSavedSeed = RANROTGetFullSeed();
358
359 self = [super init];
360
362
363 if (atmo)
364 planet_seed = p_seed.a * 13 + p_seed.c * 11 + p_seed.e * 7; // pseudo-random set-up for vertex colours
365 else
366 planet_seed = p_seed.a * 7 + p_seed.c * 11 + p_seed.e * 13; // pseudo-random set-up for vertex colours
367
368 OOTexture* texture = [dict oo_objectOfClass:[OOTexture class] forKey:@"_oo_textureObject"];
369 if (texture != nil) {
370 _texture = [texture retain];
371 isTextureImage = [dict oo_boolForKey:@"_oo_isExplicitlyTextured"];
372 } else {
373 NSDictionary* textureSpec = [dict oo_textureSpecifierForKey:@"texture" defaultName:nil];
374 if (textureSpec != nil) {
375 [self loadTexture:textureSpec];
376 }
377
378 // CIM: nothing actually uses textureSpec after the assignment below, so skip it
379 /* if (textureSpec == nil && !procGen && !atmo)
380 {
381 // Moons use metal.png by default.
382 textureSpec = OOTextureSpecFromObject(@"metal.png", nil);
383 } */
384
385 NSString* seedStr = [dict oo_stringForKey:@"seed"];
386 if (seedStr != nil) {
387 Random_Seed seed = RandomSeedFromString(seedStr);
388 if (!is_nil_seed(seed)) {
389 p_seed = seed;
390 } else {
391 OOLogERR(@"planet.fromDict", @"could not interpret \"%@\" as planet seed, using default.", seedStr);
392 }
393 }
394 }
395
397
398 NSMutableDictionary* planetInfo = [NSMutableDictionary dictionaryWithDictionary:[UNIVERSE generateSystemData:p_seed]];
399 int radius_km = [dict oo_intForKey:KEY_RADIUS
400 defaultValue:[planetInfo oo_intForKey:KEY_RADIUS]];
401 int techlevel = [dict oo_intForKey:KEY_TECHLEVEL
402 defaultValue:[planetInfo oo_intForKey:KEY_TECHLEVEL]];
403
404 shuttles_on_ground = 1 + floor(techlevel * 0.5);
405 last_launch_time = 0.0;
406 shuttle_launch_interval = 3600.0 / shuttles_on_ground; // all are launched in an hour
407
408 last_launch_time = [UNIVERSE getTime] + 30.0 - shuttle_launch_interval; // debug - launch 30s after player enters universe
409
410 collision_radius = radius_km * 10.0; // scale down by a factor of 100 !
411
412 scanClass = CLASS_NO_DRAW;
413
416 orientation.y = 0.0;
417 orientation.z = 0.0;
418
419 [self setUseTexturedModel:(procGen || _texture != nil)];
420
421 int percent_land = [planetInfo oo_intForKey:@"percent_land" defaultValue:24 + (gen_rnd_number() % 48)];
422 // if (isTextured) percent_land = atmo ? 0 :100; // moon/planet override
423
424 // save the current random number generator seed
425 RNG_Seed saved_seed = currentRandomSeed();
426
427 // For historical reasons, stir the PRNG vertexCount times.
428 unsigned i;
429 for (i = 0; i < vertexCount; i++)
431
432 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_land] forKey:@"land_fraction"];
433
434 polar_color_factor = [dict oo_doubleForKey:@"polar_color_factor" defaultValue:0.5f];
435
436 Vector land_hsb, sea_hsb, land_polar_hsb, sea_polar_hsb;
437
438 if (isTextureImage) {
439 // standard overlay colours.
440 land_hsb.x = 0.0;
441 land_hsb.y = 0.0;
442 land_hsb.z = 1.0; // non-saturated fully bright (white)
443 sea_hsb.x = 0.0;
444 sea_hsb.y = 1.0;
445 sea_hsb.z = 1.0; // fully-saturated fully bright (red)
446 // override the mainPlanet texture colour...
447 [self setTextureColorForPlanet:!![dict objectForKey:@"mainForLocalSystem"] inSystem:[dict oo_boolForKey:@"mainForLocalSystem" defaultValue:NO]];
448 } else {
449 // random land & sea colours.
450 land_hsb.x = gen_rnd_number() / 256.0;
451 land_hsb.y = gen_rnd_number() / 256.0;
452 land_hsb.z = 0.5 + gen_rnd_number() / 512.0;
453 sea_hsb.x = gen_rnd_number() / 256.0;
454 sea_hsb.y = gen_rnd_number() / 256.0;
455 sea_hsb.z = 0.5 + gen_rnd_number() / 512.0;
456 while (dot_product(land_hsb, sea_hsb) > .80) // make sure land and sea colors differ significantly
457 {
458 sea_hsb.x = gen_rnd_number() / 256.0;
459 sea_hsb.y = gen_rnd_number() / 256.0;
460 sea_hsb.z = 0.5 + gen_rnd_number() / 512.0;
461 }
462
463 // assign land_hsb and sea_hsb overrides from planetinfo.plist if they're there.
464 ScanVectorFromString([dict objectForKey:@"land_hsb_color"], &land_hsb);
465 ScanVectorFromString([dict objectForKey:@"sea_hsb_color"], &sea_hsb);
466
467 // polar areas are brighter but have less color (closer to white)
468 land_polar_hsb.x = land_hsb.x;
469 land_polar_hsb.y = (land_hsb.y / 4.0);
470 land_polar_hsb.z = 1.0 - (land_hsb.z / 10.0);
471 sea_polar_hsb.x = sea_hsb.x;
472 sea_polar_hsb.y = (sea_hsb.y / 4.0);
473 sea_polar_hsb.z = 1.0 - (sea_hsb.z / 10.0);
474
475 OOColor* amb_land_color = [OOColor colorWithHue:land_hsb.x saturation:land_hsb.y brightness:land_hsb.z alpha:1.0];
476 OOColor* amb_sea_color = [OOColor colorWithHue:sea_hsb.x saturation:sea_hsb.y brightness:sea_hsb.z alpha:1.0];
477 OOColor* amb_polar_land_color = [OOColor colorWithHue:land_polar_hsb.x saturation:land_polar_hsb.y brightness:land_polar_hsb.z alpha:1.0];
478 OOColor* amb_polar_sea_color = [OOColor colorWithHue:sea_polar_hsb.x saturation:sea_polar_hsb.y brightness:sea_polar_hsb.z alpha:1.0];
479
480 amb_land[0] = [amb_land_color redComponent];
481 amb_land[1] = [amb_land_color blueComponent];
482 amb_land[2] = [amb_land_color greenComponent];
483 amb_land[3] = 1.0;
484 amb_sea[0] = [amb_sea_color redComponent];
485 amb_sea[1] = [amb_sea_color blueComponent];
486 amb_sea[2] = [amb_sea_color greenComponent];
487 amb_sea[3] = 1.0;
488 amb_polar_land[0] = [amb_polar_land_color redComponent];
489 amb_polar_land[1] = [amb_polar_land_color blueComponent];
490 amb_polar_land[2] = [amb_polar_land_color greenComponent];
491 amb_polar_land[3] = 1.0;
492 amb_polar_sea[0] = [amb_polar_sea_color redComponent];
493 amb_polar_sea[1] = [amb_polar_sea_color blueComponent];
494 amb_polar_sea[2] = [amb_polar_sea_color greenComponent];
495 amb_polar_sea[3] = 1.0;
496
497 [planetInfo setObject:amb_land_color forKey:@"land_color"];
498 [planetInfo setObject:amb_sea_color forKey:@"sea_color"];
499 [planetInfo setObject:amb_polar_land_color forKey:@"polar_land_color"];
500 [planetInfo setObject:amb_polar_sea_color forKey:@"polar_sea_color"];
501 }
502
503 if (procGen && _texture == nil) {
504 _texture = [self planetTextureWithInfo:planetInfo];
505 isTextureImage = NO;
506 [_texture retain];
507 }
508
509 [self initialiseBaseVertexArray];
510 [self initialiseBaseTerrainArray:percent_land];
511
512 for (i = 0; i < next_free_vertex; i++) {
513 [self paintVertex:i:planet_seed];
514 }
515
516 [self scaleVertices];
517 // set speed of rotation
518 if ([dict objectForKey:@"rotational_velocity"]) {
519 rotational_velocity = [dict oo_floatForKey:@"rotational_velocity" defaultValue:0.01f * randf()]; // 0.0 .. 0.01 avr 0.005
520 } else {
521 rotational_velocity = [planetInfo oo_floatForKey:@"rotation_speed" defaultValue:0.002 * (0.5 + 0.5 * randf())]; // 0.001 .. 0.002 avr 0.0015
522 rotational_velocity *= [planetInfo oo_floatForKey:@"rotation_speed_factor" defaultValue:1.0f];
523 }
524
525 // do atmosphere
526 NSDictionary* atmoDict = dict;
527 if (_texture != nil)
528 atmoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"0", @"percent_cloud", [NSNumber numberWithFloat:[planetInfo oo_floatForKey:@"cloud_alpha" defaultValue:1.0]], @"cloud_alpha", nil];
529 if (atmo)
530 atmosphere = [[PlanetEntity alloc] initAsAtmosphereForPlanet:self dictionary:atmoDict];
531
532 setRandomSeed(saved_seed);
533 RANROTSetFullSeed(ranrotSavedSeed);
534
535 // set energy
536 energy = collision_radius * 1000.0;
537
538 root_planet = self;
539
541
542 /* MKW - rotate planet based on current time.
543 * - do it here so that we catch all planets (OXP-added and otherwise! */
544 int deltaT = floor(fmod([PLAYER clockTimeAdjusted], 86400));
545 quaternion_rotate_about_axis(&orientation, rotationAxis, rotational_velocity * deltaT);
546
547 [self setStatus:STATUS_ACTIVE];
548
550
551 return self;
552}
#define M_SQRT1_2
Definition OOMaths.h:75
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
Random_Seed RandomSeedFromString(NSString *abcdefString)
BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector)
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:299
#define PLAYER
GLfloat energy
Definition Entity.m:753
float blueComponent()
Definition OOColor.m:339
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
float greenComponent()
Definition OOColor.m:334
GLuint vertexCount
OOTexture * texture()
void seed_for_planet_description(Random_Seed s_seed)
OOINLINE int is_nil_seed(Random_Seed a_seed) INLINE_CONST_FUNC
struct Random_Seed Random_Seed
OOScalar w
OOScalar x
OOScalar y
OOScalar z
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References _texture, Random_Seed::a, amb_land, amb_polar_land, amb_polar_sea, amb_sea, atmosphere, OOColor::blueComponent, Random_Seed::c, Entity::collision_radius, OOColor::colorWithHue:saturation:brightness:alpha:, currentRandomSeed(), dot_product(), Random_Seed::e, Entity::energy, gen_rnd_number(), OOColor::greenComponent, Entity::init, initialiseBaseTerrainArray:, initialiseBaseVertexArray, is_nil_seed(), isTextureImage, last_launch_time, loadTexture:, M_SQRT1_2, next_free_vertex, nil, OOLogERR, Entity::orientation, planet_seed, planet_type, planetTextureWithInfo:, PLAYER, polar_color_factor, quaternion_rotate_about_axis(), RandomSeedFromString(), RANROTGetFullSeed(), RANROTSetFullSeed(), OOColor::redComponent, OOGraphicsResetManager::registerClient:, root_planet, rotational_velocity, rotationAxis, scaleVertices, Entity::scanClass, ScanVectorFromString(), seed_for_planet_description(), setRandomSeed(), Entity::setStatus:, setTextureColorForPlanet:inSystem:, setUseTexturedModel:, OOGraphicsResetManager::sharedManager, shuttle_launch_interval, shuttles_on_ground, STELLAR_TYPE_MOON, STELLAR_TYPE_NORMAL_PLANET, texture, vector_up_from_quaternion(), vertexCount, Vector::x, Vector::y, and Vector::z.

Here is the call graph for this function:

◆ initialiseBaseTerrainArray:

- (void) initialiseBaseTerrainArray: (int) percent_land
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1255 of file PlanetEntity.m.

1255 :(int)percent_land
1256{
1257 RANROTSeed saved_seed = RANROTGetFullSeed();
1258
1259 // set first 12 or 14 vertices
1260 if (percent_land >= 0) {
1261 GLuint vi;
1262 for (vi = 0; vi < vertexCount; vi++) {
1263 if (gen_rnd_number() < 256 * percent_land / 100)
1264 base_terrain_array[vi] = 0; // land
1265 else
1266 base_terrain_array[vi] = 100; // sea
1267 }
1268 }
1269
1270 // for the next levels of subdivision simply build up from the level below!...
1271 BOOL isTextured = [self isTextured];
1272
1273 int sublevel;
1274 for (sublevel = 0; sublevel < MAX_SUBDIVIDE - 1; sublevel++) {
1275 int tri;
1276 for (tri = 0; tri < n_triangles[sublevel]; tri++) {
1277 // get the six vertices for this group of four triangles
1278 int v0 = vertex_index_array[triangle_start[sublevel] + tri * 3 + 0];
1279 int v1 = vertex_index_array[triangle_start[sublevel] + tri * 3 + 1];
1280 int v2 = vertex_index_array[triangle_start[sublevel] + tri * 3 + 2];
1281 int v01 = baseVertexIndexForEdge(v0, v1, isTextured); // sets it up if required
1282 int v12 = baseVertexIndexForEdge(v1, v2, isTextured); // ..
1283 int v20 = baseVertexIndexForEdge(v2, v0, isTextured); // ..
1284 // v01
1287 else {
1288 uint32_t s1 = 0xffff0000 * base_vertex_array[v01].x;
1289 uint32_t s2 = 0x00ffff00 * base_vertex_array[v01].y;
1290 uint32_t s3 = 0x0000ffff * base_vertex_array[v01].z;
1291 ranrot_srand(s1 + s2 + s3);
1292 base_terrain_array[v01] = (ranrot_rand() & 4) * 25;
1293 }
1294 // v12
1297 else {
1298 uint32_t s1 = 0xffff0000 * base_vertex_array[v12].x;
1299 uint32_t s2 = 0x00ffff00 * base_vertex_array[v12].y;
1300 uint32_t s3 = 0x0000ffff * base_vertex_array[v12].z;
1301 ranrot_srand(s1 + s2 + s3);
1302 base_terrain_array[v12] = (ranrot_rand() & 4) * 25;
1303 }
1304 // v20
1307 else {
1308 uint32_t s1 = 0xffff0000 * base_vertex_array[v20].x;
1309 uint32_t s2 = 0x00ffff00 * base_vertex_array[v20].y;
1310 uint32_t s3 = 0x0000ffff * base_vertex_array[v20].z;
1311 ranrot_srand(s1 + s2 + s3);
1312 base_terrain_array[v20] = (ranrot_rand() & 4) * 25;
1313 }
1314 }
1315 }
1316
1317 RANROTSetFullSeed(saved_seed);
1318}
static GLuint vertex_index_array[3 *(20+80+320+1280+5120+20480)]
static unsigned baseVertexIndexForEdge(GLushort va, GLushort vb, BOOL textured)
static int base_terrain_array[MAX_PLANET_VERTICES]
void ranrot_srand(uint32_t seed)

References base_terrain_array, base_vertex_array, baseVertexIndexForEdge(), gen_rnd_number(), isTextured, MAX_SUBDIVIDE, n_triangles, ranrot_rand, ranrot_srand(), RANROTGetFullSeed(), RANROTSetFullSeed(), and vertex_index_array.

Referenced by PlanetEntity(OOPrivate)::initAsAtmosphereForPlanet:dictionary:, initFromDictionary:withAtmosphere:andSeed:, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseBaseVertexArray

- (void) initialiseBaseVertexArray
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1120 of file PlanetEntity.m.

1121{
1122 BOOL isTextured = [self isTextured];
1123 static BOOL lastOneWasTextured;
1124
1125 if (lastOneWasTextured != isTextured) {
1126 if (sEdgeToVertex != NULL) {
1127 NSFreeMapTable(sEdgeToVertex);
1128 sEdgeToVertex = NULL;
1129 }
1130 lastOneWasTextured = isTextured;
1131 }
1132
1133 if (sEdgeToVertex == NULL) {
1134 sEdgeToVertex = NSCreateMapTable(NSIntegerMapKeyCallBacks, NSIntegerMapValueCallBacks, 7680); // make a new one
1135 next_free_vertex = 0;
1136
1137 const Vector* vertices = NULL;
1138 const BaseFace(*faces)[3] = NULL;
1139 GLuint faceCount = 0;
1140 if (useTexturedModel) {
1141 vertices = kTexturedVertices;
1142 faces = kTexturedFaces;
1143 faceCount = sizeof kTexturedFaces / sizeof *kTexturedFaces;
1144 } else {
1145 vertices = kUntexturedVertices;
1146 faces = kUntexturedFaces;
1147 faceCount = sizeof kUntexturedFaces / sizeof *kUntexturedFaces;
1148 }
1149
1150 // set first 12 or 14 vertices
1151 GLuint vi;
1152 for (vi = 0; vi < vertexCount; vi++) {
1153 base_vertex_array[next_free_vertex++] = vertices[vi];
1154 }
1155
1156 // set first 20 triangles
1157 triangle_start[0] = 0;
1158 n_triangles[0] = faceCount;
1159 GLuint fi;
1160 for (fi = 0; fi < faceCount; fi++) {
1161 unsigned j;
1162 for (j = 0; j < 3; j++) {
1163 vertex_index_array[fi * 3 + j] = faces[fi][j].v;
1164 texture_uv_array[faces[fi][j].v * 2 + 0] = faces[fi][j].s;
1165 texture_uv_array[faces[fi][j].v * 2 + 1] = faces[fi][j].t;
1166 }
1167 }
1168
1169 // for the next levels of subdivision simply build up from the level below!...
1170 unsigned sublevel;
1171 for (sublevel = 0; sublevel < MAX_SUBDIVIDE - 1; sublevel++) {
1172 int newlevel = sublevel + 1;
1173 triangle_start[newlevel] = triangle_start[sublevel] + n_triangles[sublevel] * 3;
1174 n_triangles[newlevel] = n_triangles[sublevel] * 4;
1175
1176 int tri;
1177 for (tri = 0; tri < n_triangles[sublevel]; tri++) {
1178 // get the six vertices for this group of four triangles
1179 int v0 = vertex_index_array[triangle_start[sublevel] + tri * 3 + 0];
1180 int v1 = vertex_index_array[triangle_start[sublevel] + tri * 3 + 1];
1181 int v2 = vertex_index_array[triangle_start[sublevel] + tri * 3 + 2];
1182 int v01 = baseVertexIndexForEdge(v0, v1, isTextured); // sets it up if required
1183 int v12 = baseVertexIndexForEdge(v1, v2, isTextured); // ..
1184 int v20 = baseVertexIndexForEdge(v2, v0, isTextured); // ..
1185 // v0 v01 v20
1186 vertex_index_array[triangle_start[newlevel] + tri * 12 + 0] = v0;
1187 vertex_index_array[triangle_start[newlevel] + tri * 12 + 1] = v01;
1188 vertex_index_array[triangle_start[newlevel] + tri * 12 + 2] = v20;
1189 // v01 v1 v12
1190 vertex_index_array[triangle_start[newlevel] + tri * 12 + 3] = v01;
1191 vertex_index_array[triangle_start[newlevel] + tri * 12 + 4] = v1;
1192 vertex_index_array[triangle_start[newlevel] + tri * 12 + 5] = v12;
1193 // v20 v12 v2
1194 vertex_index_array[triangle_start[newlevel] + tri * 12 + 6] = v20;
1195 vertex_index_array[triangle_start[newlevel] + tri * 12 + 7] = v12;
1196 vertex_index_array[triangle_start[newlevel] + tri * 12 + 8] = v2;
1197 // v01 v12 v20
1198 vertex_index_array[triangle_start[newlevel] + tri * 12 + 9] = v01;
1199 vertex_index_array[triangle_start[newlevel] + tri * 12 + 10] = v12;
1200 vertex_index_array[triangle_start[newlevel] + tri * 12 + 11] = v20;
1201 }
1202 }
1203 }
1204
1205 // all done - copy the indices to the instance
1206 unsigned i;
1207 for (i = 0; i < MAX_TRI_INDICES; i++) {
1209 }
1210}
#define MAX_TRI_INDICES
static const Vector kUntexturedVertices[]
static const Vector kTexturedVertices[]
static const BaseFace kUntexturedFaces[][3]
static const BaseFace kTexturedFaces[][3]

References base_vertex_array, baseVertexIndexForEdge(), PlanetEntity(OOPrivate)::initialiseBaseVertexArray, isTextured, kTexturedFaces, kTexturedVertices, kUntexturedFaces, kUntexturedVertices, MAX_SUBDIVIDE, MAX_TRI_INDICES, n_triangles, next_free_vertex, sEdgeToVertex, texture_uv_array, triangle_start, and vertex_index_array.

Referenced by PlanetEntity(OOPrivate)::initAsAtmosphereForPlanet:dictionary:, initFromDictionary:withAtmosphere:andSeed:, PlanetEntity(OOPrivate)::initialiseBaseVertexArray, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initMiniatureFromPlanet:withAlpha:

- (id) initMiniatureFromPlanet: (PlanetEntity *) planet
withAlpha: (float) alpha 
implementation

Provided by category PlanetEntity(OOPrivate).

◆ isExplicitlyTextured

- (BOOL) isExplicitlyTextured

Definition at line 1398 of file PlanetEntity.m.

1399{
1400 return isTextureImage;
1401}

References isExplicitlyTextured, and isTextureImage.

Referenced by isExplicitlyTextured, and planet_seed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPlanet

- (BOOL) isPlanet
implementation

Reimplemented from Entity.

Definition at line 1486 of file PlanetEntity.m.

1487{
1488 return YES;
1489}

References isPlanet.

Referenced by isPlanet.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTextured

- (BOOL) isTextured

Definition at line 932 of file PlanetEntity.m.

933{
934 return _texture != nil;
935}

References _texture, isTextured, and nil.

Referenced by PlanetEntity(OOPrivate)::initialiseBaseTerrainArray:, PlanetEntity(OOPrivate)::initialiseBaseVertexArray, isTextured, planet_seed, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isVisible

- (BOOL) isVisible
implementation

Reimplemented from Entity.

Definition at line 1491 of file PlanetEntity.m.

1492{
1493 return YES;
1494}

References isVisible.

Referenced by isVisible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ launchShuttle

- (void) launchShuttle

Definition at line 1082 of file PlanetEntity.m.

1083{
1084 ShipEntity* shuttle_ship;
1085 Quaternion q1;
1086 HPVector launch_pos = position;
1087 double start_distance = collision_radius + 125.0;
1088
1090
1092
1093 launch_pos.x += start_distance * vf.x;
1094 launch_pos.y += start_distance * vf.y;
1095 launch_pos.z += start_distance * vf.z;
1096
1097 shuttle_ship = [UNIVERSE newShipWithRole:@"shuttle"]; // retain count = 1
1098 if (shuttle_ship) {
1099 if (![shuttle_ship crew]) {
1100 [shuttle_ship setSingleCrewWithRole:@"trader"];
1101 }
1102
1103 [shuttle_ship setPosition:launch_pos];
1104 [shuttle_ship setOrientation:q1];
1105
1106 [shuttle_ship setScanClass:CLASS_NEUTRAL];
1107 [shuttle_ship setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL];
1108 [shuttle_ship switchAITo:@"oolite-shuttleAI.js"];
1109 [UNIVERSE addEntity:shuttle_ship];
1110
1111 [shuttle_ship release];
1112 }
1113}
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
struct Quaternion Quaternion
void quaternion_set_random(Quaternion *quat) NONNULL_FUNC
void setOrientation:(Quaternion quat)
Definition Entity.m:676
void setScanClass:(OOScanClass sClass)
Definition Entity.m:738
void setPosition:(HPVector posn)
Definition Entity.m:608
void setCargoFlag:(OOCargoFlag flag)
void setSingleCrewWithRole:(NSString *crewRole)
void switchAITo:(NSString *aiString)

References Entity::collision_radius, launchShuttle, Entity::position, quaternion_set_random(), ShipEntity::setCargoFlag:, Entity::setOrientation:, Entity::setPosition:, Entity::setScanClass:, ShipEntity::setSingleCrewWithRole:, ShipEntity::switchAITo:, vector_forward_from_quaternion(), HPVector::x, Vector::x, HPVector::y, Vector::y, HPVector::z, and Vector::z.

Referenced by amb_polar_sea, launchShuttle, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadTexture:

- (void) loadTexture: (NSDictionary*) configuration
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1408 of file PlanetEntity.m.

1408 :(NSDictionary*)configuration
1409{
1410 [_texture release];
1411 _texture = [OOTexture textureWithConfiguration:configuration extraOptions:kOOTextureAllowCubeMap | kOOTextureRepeatS];
1412 [_texture retain];
1413
1414 [_textureFileName release];
1415 if (_texture != nil) {
1416 _textureFileName = [[configuration oo_stringForKey:@"name"] copy];
1417 isTextureImage = YES;
1418 } else {
1420 isTextureImage = NO;
1421 }
1422}
id textureWithConfiguration:extraOptions:(id configuration,[extraOptions] OOTextureFlags extraOptions)
Definition OOTexture.m:191
NSString * _textureFileName

References nil, and OOTexture::textureWithConfiguration:extraOptions:.

Referenced by initFromDictionary:withAtmosphere:andSeed:, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ miniaturize

- (void) miniaturize

Definition at line 334 of file PlanetEntity.m.

335{
338 last_launch_time = 0.0;
340 [self setStatus:STATUS_COCKPIT_DISPLAY];
341 collision_radius = [self collisionRadius] * PLANET_MINIATURE_FACTOR; // teeny tiny
342 [self scaleVertices];
343 if (atmosphere != nil) {
344 atmosphere->collision_radius = collision_radius + ATMOSPHERE_DEPTH * PLANET_MINIATURE_FACTOR * 2.0; // not to scale: invisible otherwise
345 [atmosphere scaleVertices];
346 }
347 rotational_velocity = 0.04;
349}
const Vector kBasisYVector
Definition OOVector.h:46

References atmosphere, ATMOSPHERE_DEPTH, Entity::collision_radius, Entity::collisionRadius, kBasisYVector, last_launch_time, miniaturize, nil, PLANET_MINIATURE_FACTOR, planet_type, rotational_velocity, rotationAxis, scaleVertices, Entity::setStatus:, shuttle_launch_interval, shuttles_on_ground, and STELLAR_TYPE_MINIATURE.

Referenced by miniaturize.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paintVertex:seed:

- (void) paintVertex: (unsigned) vi
seed: (int) seed 
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1320 of file PlanetEntity.m.

1320 :(unsigned)vi seed:(int)seed
1321{
1322 RANROTSeed saved_seed = RANROTGetFullSeed();
1323 BOOL isTextured = _texture != nil;
1324
1325 GLfloat paint_land[4] = { 0.2, 0.9, 0.0, 1.0 };
1326 GLfloat paint_sea[4] = { 0.0, 0.2, 0.9, 1.0 };
1327 GLfloat paint_color[4];
1328 Vector v = base_vertex_array[vi];
1329 int r = isTextured ? 0 : base_terrain_array[vi]; // use land color (0) for textured planets
1330 int i;
1331 double pole_blend = v.z * v.z * polar_color_factor;
1332 if (pole_blend < 0.0)
1333 pole_blend = 0.0;
1334 if (pole_blend > 1.0)
1335 pole_blend = 1.0;
1336
1337 paint_land[0] = (1.0 - pole_blend) * amb_land[0] + pole_blend * amb_polar_land[0];
1338 paint_land[1] = (1.0 - pole_blend) * amb_land[1] + pole_blend * amb_polar_land[1];
1339 paint_land[2] = (1.0 - pole_blend) * amb_land[2] + pole_blend * amb_polar_land[2];
1340 paint_sea[0] = (1.0 - pole_blend) * amb_sea[0] + pole_blend * amb_polar_sea[0];
1341 paint_sea[1] = (1.0 - pole_blend) * amb_sea[1] + pole_blend * amb_polar_sea[1];
1342 paint_sea[2] = (1.0 - pole_blend) * amb_sea[2] + pole_blend * amb_polar_sea[2];
1343 if (planet_type == STELLAR_TYPE_ATMOSPHERE) // do alphas
1344 {
1345 paint_land[3] = (1.0 - pole_blend) * amb_land[3] + pole_blend * amb_polar_land[3];
1346 paint_sea[3] = (1.0 - pole_blend) * amb_sea[3] + pole_blend * amb_polar_sea[3];
1347 }
1348
1349 ranrot_srand((uint32_t)(seed + v.x * 1000 + v.y * 100 + v.z * 10));
1350
1351 for (i = 0; i < 3; i++) {
1352 double cv = (ranrot_rand() % 100) * 0.01; // 0..1 ***** DON'T CHANGE THIS LINE, '% 100' MAY NOT BE EFFICIENT BUT THE PATTERNING IS GOOD.
1353 paint_land[i] += (cv - 0.5) * 0.1;
1354 paint_sea[i] += (cv - 0.5) * 0.1;
1355 }
1356
1357 for (i = 0; i < 4; i++) {
1358 if (planet_type == STELLAR_TYPE_ATMOSPHERE && isTextured)
1359 paint_color[i] = 1.0;
1360 else
1361 paint_color[i] = (r * paint_sea[i]) * 0.01 + ((100 - r) * paint_land[i]) * 0.01;
1362 // finally initialise the color array entry
1363 vertexdata.color_array[vi * 4 + i] = paint_color[i];
1364 }
1365
1366 RANROTSetFullSeed(saved_seed);
1367}

References base_terrain_array, base_vertex_array, nil, ranrot_rand, ranrot_srand(), RANROTGetFullSeed(), RANROTSetFullSeed(), STELLAR_TYPE_ATMOSPHERE, Vector::x, Vector::y, and Vector::z.

Here is the call graph for this function:

◆ planet_seed

References int(), isExplicitlyTextured, isTextured, planet_seed, texture, and textureFileName.

Here is the call graph for this function:

◆ planetTextureWithInfo:

- (OOTexture *) planetTextureWithInfo: (NSDictionary*) info
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1430 of file PlanetEntity.m.

1430 :(NSDictionary*)info
1431{
1432 unsigned char* data;
1433 GLuint width, height;
1434
1436 if (![TextureStore getPlanetTextureNameFor:info
1437 intoData:&data
1438 width:&width
1439 height:&height]) {
1440 return nil;
1441 }
1442
1443 OOPixMap pm = OOMakePixMap(data, width, height, kOOPixMapRGBA, 0, 0);
1444 OOTextureGenerator* loader = [[OOPixMapTextureLoader alloc] initWithPixMap:pm
1445 textureOptions:kOOTextureDefaultOptions | kOOTextureRepeatS
1446 freeWhenDone:YES];
1447 [loader autorelease];
1448
1449 return [OOTexture textureWithGenerator:loader];
1450}

References fillRanNoiseBuffer(), kOOPixMapRGBA, nil, OOMakePixMap(), and OOTexture::textureWithGenerator:.

Referenced by initFromDictionary:withAtmosphere:andSeed:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ planetType

- (OOStellarBodyType) planetType

Reimplemented from <OOStellarBody>.

Definition at line 1033 of file PlanetEntity.m.

1034{
1035 return planet_type;
1036}

References planet_type, and planetType.

Referenced by amb_polar_sea, and planetType.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ polar_color_factor

- (double) polar_color_factor

References polar_color_factor.

◆ radius

- (double) radius

Reimplemented from <OOStellarBody>.

Definition at line 1043 of file PlanetEntity.m.

1044{
1045 return collision_radius;
1046}

References Entity::collision_radius, and radius.

Referenced by amb_polar_sea, descriptionComponents, drawImmediate:translucent:, and radius.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetGraphicsState

- (void) resetGraphicsState
implementation

Definition at line 1393 of file PlanetEntity.m.

1394{
1395 [self deleteDisplayLists];
1396}

References deleteDisplayLists, and resetGraphicsState.

Referenced by resetGraphicsState.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotationalVelocity

- (double) rotationalVelocity

Definition at line 1053 of file PlanetEntity.m.

1054{
1055 return rotational_velocity;
1056}

References rotational_velocity, and rotationalVelocity.

Referenced by amb_polar_sea, PlanetEntity(OOPrivate)::initAsAtmosphereForPlanet:dictionary:, rotationalVelocity, and setRotationalVelocity:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scaleVertices

- (void) scaleVertices
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1369 of file PlanetEntity.m.

1370{
1371 NSUInteger vi;
1372 for (vi = 0; vi < next_free_vertex; vi++) {
1373 Vector v = base_vertex_array[vi];
1374 vertexdata.normal_array[vi] = v;
1375 vertexdata.vertex_array[vi] = make_vector(v.x * collision_radius, v.y * collision_radius, v.z * collision_radius);
1376
1377 vertexdata.uv_array[vi * 2] = texture_uv_array[vi * 2];
1378 vertexdata.uv_array[vi * 2 + 1] = texture_uv_array[vi * 2 + 1];
1379 }
1380}
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149

References base_vertex_array, make_vector(), next_free_vertex, PlanetEntity(OOPrivate)::scaleVertices, texture_uv_array, Vector::x, Vector::y, and Vector::z.

Referenced by PlanetEntity(OOPrivate)::initAsAtmosphereForPlanet:dictionary:, initFromDictionary:withAtmosphere:andSeed:, miniaturize, PlanetEntity(OOPrivate)::scaleVertices, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setOrientation:

- (void) setOrientation: (Quaternion) inOrientation
implementation

Reimplemented from Entity.

Definition at line 701 of file PlanetEntity.m.

701 :(Quaternion)inOrientation
702{
704 [super setOrientation:inOrientation];
705 if (atmosphere)
706 [atmosphere setOrientation:inOrientation];
707}

References atmosphere, rotationAxis, Entity::setOrientation:, setOrientation:, and vector_up_from_quaternion().

Referenced by setOrientation:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPlanetType:

- (void) setPlanetType: (OOStellarBodyType) pt

Definition at line 1038 of file PlanetEntity.m.

1039{
1040 planet_type = pt;
1041}
OOStellarBodyType

References planet_type.

◆ setPosition:

- (void) setPosition: (HPVector) posn
implementation

Reimplemented from Entity.

Definition at line 695 of file PlanetEntity.m.

695 :(HPVector)posn
696{
697 position = posn;
698 [atmosphere setPosition:posn];
699}

References Entity::position, and setPosition:.

Referenced by setPosition:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRadius:

- (void) setRadius: (GLfloat) rad

Definition at line 1048 of file PlanetEntity.m.

1048 :(GLfloat)rad
1049{
1050 collision_radius = rad;
1051}

References Entity::collision_radius.

◆ setRotationalVelocity:

- (void) setRotationalVelocity: (double) v

Definition at line 1058 of file PlanetEntity.m.

1058 :(double)v
1059{
1060 if (atmosphere) // change rotation speed proportionally
1061 {
1062 [atmosphere setRotationalVelocity:[atmosphere rotationalVelocity] * v / [self rotationalVelocity]];
1063 }
1065}

References atmosphere, rotational_velocity, rotationalVelocity, and setRotationalVelocity:.

Referenced by setRotationalVelocity:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTextureColorForPlanet:inSystem:

- (void) setTextureColorForPlanet: (BOOL) isMain
inSystem: (BOOL) isLocal 
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 942 of file PlanetEntity.m.

942 :(BOOL)isMain inSystem:(BOOL)isLocal
943{
944 Vector land_hsb, land_polar_hsb;
945 land_hsb.x = 0.0;
946 land_hsb.y = 0.0;
947 land_hsb.z = 1.0; // white
948
949 // the colour override should only apply to main planets
950 if (isMain) {
951 if (isLocal)
952 ScanVectorFromString([[UNIVERSE currentSystemData] objectForKey:@"texture_hsb_color"], &land_hsb);
953 else
954 ScanVectorFromString([[UNIVERSE generateSystemData:[PLAYER target_system_seed]] objectForKey:@"texture_hsb_color"], &land_hsb);
955 }
956
957 land_polar_hsb.x = land_hsb.x;
958 land_polar_hsb.y = (land_hsb.y / 5.0);
959 land_polar_hsb.z = 1.0 - (land_hsb.z / 10.0);
960
961 amb_sea[0] = amb_land[0] = [[OOColor colorWithHue:land_hsb.x saturation:land_hsb.y brightness:land_hsb.z alpha:1.0] redComponent];
962 amb_sea[1] = amb_land[1] = [[OOColor colorWithHue:land_hsb.x saturation:land_hsb.y brightness:land_hsb.z alpha:1.0] blueComponent];
963 amb_sea[2] = amb_land[2] = [[OOColor colorWithHue:land_hsb.x saturation:land_hsb.y brightness:land_hsb.z alpha:1.0] greenComponent];
964 amb_sea[3] = amb_land[3] = 1.0;
965 amb_polar_sea[0] = amb_polar_land[0] = [[OOColor colorWithHue:land_polar_hsb.x saturation:land_polar_hsb.y brightness:land_polar_hsb.z alpha:1.0] redComponent];
966 amb_polar_sea[1] = amb_polar_land[1] = [[OOColor colorWithHue:land_polar_hsb.x saturation:land_polar_hsb.y brightness:land_polar_hsb.z alpha:1.0] blueComponent];
967 amb_polar_sea[2] = amb_polar_land[2] = [[OOColor colorWithHue:land_polar_hsb.x saturation:land_polar_hsb.y brightness:land_polar_hsb.z alpha:1.0] greenComponent];
968 amb_polar_sea[3] = amb_polar_land[3] = 1.0;
969}

References OOColor::blueComponent, OOColor::colorWithHue:saturation:brightness:alpha:, OOColor::greenComponent, PLAYER, OOColor::redComponent, ScanVectorFromString(), UNIVERSE, Vector::x, Vector::y, and Vector::z.

Referenced by initFromDictionary:withAtmosphere:andSeed:, and setUpPlanetFromTexture:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpPlanetFromTexture:

- (BOOL) setUpPlanetFromTexture: (NSString*) fileName

Definition at line 971 of file PlanetEntity.m.

971 :(NSString*)fileName
972{
973 if (fileName == nil)
974 return NO;
975
976 [self loadTexture:OOTextureSpecFromObject(fileName, nil)];
977 [self deleteDisplayLists];
978
979 unsigned i;
980 [self setUseTexturedModel:YES];
981
982 // recolour main planet according to "texture_hsb_color"
983 // this function is only called for local systems!
984 [self setTextureColorForPlanet:([UNIVERSE planet] == self) inSystem:YES];
985
986 [self initialiseBaseVertexArray];
987 [self initialiseBaseTerrainArray:100];
988 for (i = 0; i < next_free_vertex; i++) {
989 [self paintVertex:i:planet_seed];
990 }
991
992 [self scaleVertices];
993
994 GLfloat oldCloudAlpha = 0.0;
995 if (atmosphere) {
996 oldCloudAlpha = [atmosphere amb_sea][3] / CLOUD_ALPHA;
997 }
998
999 NSDictionary* atmo_dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"0", @"percent_cloud", [NSNumber numberWithFloat:oldCloudAlpha], @"cloud_alpha", nil];
1000 [atmosphere autorelease];
1001 atmosphere = [self hasAtmosphere] ? [[PlanetEntity alloc] initAsAtmosphereForPlanet:self dictionary:atmo_dictionary] : nil;
1002
1003 // rotationAxis = vector_up_from_quaternion(orientation);
1004
1005 return [self isTextured];
1006}

References amb_sea, atmosphere, CLOUD_ALPHA, deleteDisplayLists, hasAtmosphere, initialiseBaseTerrainArray:, initialiseBaseVertexArray, isTextured, loadTexture:, next_free_vertex, nil, scaleVertices, setTextureColorForPlanet:inSystem:, and setUseTexturedModel:.

Here is the call graph for this function:

◆ setUseTexturedModel:

- (void) setUseTexturedModel: (BOOL) flag
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 709 of file PlanetEntity.m.

709 :(BOOL)flag
710{
711 if (flag) {
712 useTexturedModel = YES;
714 } else {
715 useTexturedModel = NO;
717 }
718}
BOOL useTexturedModel

References kTexturedVertices, and kUntexturedVertices.

Referenced by PlanetEntity(OOPrivate)::initAsAtmosphereForPlanet:dictionary:, initFromDictionary:withAtmosphere:andSeed:, and setUpPlanetFromTexture:.

Here is the caller graph for this function:

◆ sqrtZeroDistance

- (double) sqrtZeroDistance
implementation

Provided by category PlanetEntity(OOPrivate).

Definition at line 1067 of file PlanetEntity.m.

1068{
1069 return sqrt_zero_distance;
1070}

References PlanetEntity(OOPrivate)::sqrtZeroDistance.

Referenced by PlanetEntity(OOPrivate)::sqrtZeroDistance.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ texture

- (OOTexture *) texture

Definition at line 1403 of file PlanetEntity.m.

1404{
1405 return _texture;
1406}

References _texture, and texture.

Referenced by initFromDictionary:withAtmosphere:andSeed:, planet_seed, and texture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textureFileName

- (NSString *) textureFileName

Definition at line 937 of file PlanetEntity.m.

938{
939 return _textureFileName;
940}

References _textureFileName, and textureFileName.

Referenced by planet_seed, and textureFileName.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update:

- (void) update: (OOTimeDelta) delta_t
implementation

Reimplemented from Entity.

Definition at line 631 of file PlanetEntity.m.

631 :(OOTimeDelta)delta_t
632{
633 [super update:delta_t];
634 sqrt_zero_distance = sqrt(cam_zero_distance);
635
636 switch (planet_type) {
638 // we have atmosphere in any case.
639 {
641 double atmo = 10.0 * (atmosphere->collision_radius - collision_radius); // effect starts at 10x the height of the clouds
642
643 if ((alt > 0) && (alt <= atmo)) {
644 double aleph = (atmo - alt) / atmo;
645 if (aleph < 0.0)
646 aleph = 0.0;
647 if (aleph > 1.0)
648 aleph = 1.0;
649
650 [UNIVERSE setSkyColorRed:0.8 * aleph * aleph
651 green:0.8 * aleph * aleph
652 blue:0.9 * aleph
653 alpha:aleph];
654 } else if (alt > 0 && alt <= atmo * 1.5) {
655 /* Without this, if you leave the atmosphere at very low
656 * frame rates, you might still have skyalpha > 0 when you
657 * go sun-skimming. Since skyalpha > 0 simulates atmospheric
658 * friction and continually pumps heat into the ship, this
659 * is rapidly fatal - CIM */
660 [UNIVERSE setSkyColorRed:0.0f
661 green:0.0f
662 blue:0.0f
663 alpha:0.0f];
664 }
665 }
666 case STELLAR_TYPE_MOON: {
667 double ugt = [UNIVERSE getTime];
668
669 if ((shuttles_on_ground > 0) && (ugt > last_launch_time + shuttle_launch_interval)) {
670 [self launchShuttle];
672 last_launch_time = ugt;
673 }
674 }
675
677 // normal planetary rotation
678 if (atmosphere)
679 [atmosphere update:delta_t];
680 quaternion_rotate_about_axis(&orientation, rotationAxis, rotational_velocity * delta_t);
681 [self orientationChanged];
682 break;
683
685 // atmospheric rotation
686 quaternion_rotate_about_axis(&orientation, rotationAxis, rotational_velocity * delta_t);
687 [self orientationChanged];
688 } break;
689
690 case STELLAR_TYPE_SUN:
691 break;
692 }
693}
double OOTimeDelta
Definition OOTypes.h:193

References atmosphere, Entity::cam_zero_distance, Entity::collision_radius, last_launch_time, launchShuttle, Entity::orientation, Entity::orientationChanged, planet_type, quaternion_rotate_about_axis(), rotational_velocity, rotationAxis, shuttle_launch_interval, shuttles_on_ground, sqrt_zero_distance, STELLAR_TYPE_ATMOSPHERE, STELLAR_TYPE_MINIATURE, STELLAR_TYPE_MOON, STELLAR_TYPE_NORMAL_PLANET, STELLAR_TYPE_SUN, Entity::update:, and update:.

Referenced by update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ welcomeShuttle:

- (void) welcomeShuttle: (ShipEntity*) shuttle

Definition at line 1115 of file PlanetEntity.m.

1115 :(ShipEntity*)shuttle
1116{
1118}

References shuttles_on_ground.

Member Data Documentation

◆ _texture

- (OOTexture*) _texture
private

◆ _textureFileName

- (NSString*) _textureFileName
private

Definition at line 60 of file PlanetEntity.h.

Referenced by dealloc, and textureFileName.

◆ amb_land

- (GLfloat *) amb_land
private

Definition at line 1013 of file PlanetEntity.m.

1014{
1015 return amb_land;
1016}

Referenced by amb_land, and initFromDictionary:withAtmosphere:andSeed:.

◆ amb_polar_land

- (GLfloat *) amb_polar_land
private

Definition at line 1018 of file PlanetEntity.m.

1019{
1020 return amb_polar_land;
1021}

Referenced by amb_polar_land, and initFromDictionary:withAtmosphere:andSeed:.

◆ amb_polar_sea

- (GLfloat *) amb_polar_sea
private

Definition at line 1028 of file PlanetEntity.m.

1029{
1030 return amb_polar_sea;
1031}

Referenced by amb_polar_sea, and initFromDictionary:withAtmosphere:andSeed:.

◆ amb_sea

- (GLfloat *) amb_sea
private

Definition at line 1023 of file PlanetEntity.m.

1024{
1025 return amb_sea;
1026}

Referenced by amb_sea, initFromDictionary:withAtmosphere:andSeed:, and setUpPlanetFromTexture:.

◆ atmosphere

◆ displayListNames

- (GLuint displayListNames[MAX_SUBDIVIDE])
private

Definition at line 82 of file PlanetEntity.h.

Referenced by drawUnconditionally.

◆ isTextureImage

- (BOOL) isTextureImage
private

Definition at line 59 of file PlanetEntity.h.

Referenced by initFromDictionary:withAtmosphere:andSeed:, and isExplicitlyTextured.

◆ last_launch_time

- (double) last_launch_time
private

Definition at line 77 of file PlanetEntity.h.

Referenced by initFromDictionary:withAtmosphere:andSeed:, miniaturize, and update:.

◆ lastSubdivideLevel

- (uint8_t) lastSubdivideLevel
private

Definition at line 57 of file PlanetEntity.h.

Referenced by drawUnconditionally.

◆ planet_seed

- (int) planet_seed
private

Definition at line 927 of file PlanetEntity.m.

928{
929 return planet_seed;
930}

Referenced by initFromDictionary:withAtmosphere:andSeed:, and planet_seed.

◆ planet_type

◆ polar_color_factor

- (double) polar_color_factor
private

Definition at line 1008 of file PlanetEntity.m.

1009{
1010 return polar_color_factor;
1011}

Referenced by initFromDictionary:withAtmosphere:andSeed:, and polar_color_factor.

◆ root_planet

- (PlanetEntity*) root_planet
private

Definition at line 74 of file PlanetEntity.h.

Referenced by drawUnconditionally, and initFromDictionary:withAtmosphere:andSeed:.

◆ rotational_velocity

- (double) rotational_velocity
private

◆ rotationAxis

- (Vector) rotationAxis
private

◆ shuttle_launch_interval

- (double) shuttle_launch_interval
private

Definition at line 78 of file PlanetEntity.h.

Referenced by initFromDictionary:withAtmosphere:andSeed:, miniaturize, and update:.

◆ shuttles_on_ground

- (int) shuttles_on_ground
private

◆ sqrt_zero_distance

- (double) sqrt_zero_distance
private

Definition at line 80 of file PlanetEntity.h.

Referenced by drawUnconditionally, and update:.

◆ useTexturedModel

- (BOOL) useTexturedModel
private

Definition at line 58 of file PlanetEntity.h.

◆ vertexCount

- (GLuint) vertexCount
private

Definition at line 83 of file PlanetEntity.h.

Referenced by initFromDictionary:withAtmosphere:andSeed:.

◆ vertexdata

- (VertexData) vertexdata
private

Definition at line 84 of file PlanetEntity.h.

Referenced by drawUnconditionally.


The documentation for this class was generated from the following files: