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

#include <OOSkyDrawable.h>

Inheritance diagram for OOSkyDrawable:
Collaboration diagram for OOSkyDrawable:

Instance Methods

(id) - initWithColor1:Color2:Color3:Color4:starCount:nebulaCount:nebulaHueFix:clusterFactor:alpha:scale:
(void) - dealloc [implementation]
(void) - renderOpaqueParts [implementation]
(BOOL) - hasOpaqueParts [implementation]
(GLfloat) - maxDrawDistance [implementation]
(void) - setUpStarsWithColor1:color2: [implementation]
(void) - setUpNebulaeWithColor1:color2:clusterFactor:nebulaHueFix:alpha:scale: [implementation]
(void) - loadStarTextures [implementation]
(void) - loadNebulaTextures [implementation]
(void) - addQuads:count: [implementation]
(void) - ensureTexturesLoaded [implementation]
(void) - resetGraphicsState [implementation]
Instance Methods inherited from OODrawable
(void) - renderTranslucentParts
(BOOL) - hasTranslucentParts
(GLfloat) - collisionRadius
(BoundingBox) - boundingBox
(void) - setBindingTarget:
(void) - dumpSelfState

Private Attributes

unsigned _starCount
unsigned _nebulaCount
NSMutableArray * _quadSets
GLint _displayListName

Detailed Description

Definition at line 35 of file OOSkyDrawable.h.

Method Documentation

◆ addQuads:count:

- (void) addQuads: (OOSkyQuadDesc*) quads
count: (unsigned) count 
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 412 of file OOSkyDrawable.m.

412 :(OOSkyQuadDesc*)quads count:(unsigned)count
413{
414 if (_quadSets == nil)
415 _quadSets = [[NSMutableArray alloc] init];
416
417 [OOSkyQuadSet addQuads:quads count:count toArray:_quadSets];
418}
unsigned count
return nil
struct OOSkyQuadDesc OOSkyQuadDesc
NSMutableArray * _quadSets
void addQuads:count:toArray:(OOSkyQuadDesc *quads,[count] unsigned count,[toArray] NSMutableArray *ioArray)

Referenced by OOSkyDrawable(OOPrivate)::setUpNebulaeWithColor1:color2:clusterFactor:nebulaHueFix:alpha:scale:, and OOSkyDrawable(OOPrivate)::setUpStarsWithColor1:color2:.

Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 166 of file OOSkyDrawable.m.

167{
169
170 [_quadSets release];
172 if (_displayListName != 0)
173 glDeleteLists(_displayListName, 1);
174
175 [super dealloc];
176}
#define OO_ENTER_OPENGL()
void unregisterClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()
GLint _displayListName

References _displayListName, dealloc, OO_ENTER_OPENGL, OOGraphicsResetManager::sharedManager, and OOGraphicsResetManager::unregisterClient:.

Referenced by dealloc.

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

◆ ensureTexturesLoaded

- (void) ensureTexturesLoaded
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 452 of file OOSkyDrawable.m.

Referenced by renderOpaqueParts.

Here is the caller graph for this function:

◆ hasOpaqueParts

- (BOOL) hasOpaqueParts
implementation

Reimplemented from OODrawable.

Definition at line 223 of file OOSkyDrawable.m.

224{
225 return YES;
226}

References hasOpaqueParts.

Referenced by hasOpaqueParts.

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

◆ initWithColor1:Color2:Color3:Color4:starCount:nebulaCount:nebulaHueFix:clusterFactor:alpha:scale:

- (id) initWithColor1: (OOColor*) color1
Color2: (OOColor*) color2
Color3: (OOColor*) color3
Color4: (OOColor*) color4
starCount: (unsigned) starCount
nebulaCount: (unsigned) nebulaCount
nebulaHueFix: (BOOL) nebulaHueFix
clusterFactor: (float) nebulaClusterFactor
alpha: (float) nebulaAlpha
scale: (float) nebulaScale 

Definition at line 120 of file OOSkyDrawable.m.

120 :(OOColor*)color1
121 Color2:(OOColor*)color2
122 Color3:(OOColor*)color3
123 Color4:(OOColor*)color4
124 starCount:(unsigned)starCount
125 nebulaCount:(unsigned)nebulaCount
126 nebulaHueFix:(BOOL)nebulaHueFix
127 clusterFactor:(float)nebulaClusterFactor
128 alpha:(float)nebulaAlpha
129 scale:(float)nebulaScale
130{
131 NSAutoreleasePool* pool = nil;
132
133 if (!sInited) {
134 sInited = YES;
135 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"sky-render-inset-coords"]) {
136 sMinTexCoord += 1.0f / 128.0f;
137 sMaxTexCoord -= 1.0f / 128.0f;
138 }
139 }
140
141 self = [super init];
142 if (self == nil)
143 return nil;
144
145 _starCount = starCount;
146 _nebulaCount = nebulaCount;
147
148 pool = [[NSAutoreleasePool alloc] init];
149 [self setUpStarsWithColor1:color1 color2:color2];
150
151 if (![UNIVERSE reducedDetail]) {
152 [self setUpNebulaeWithColor1:color3
153 color2:color4
154 clusterFactor:nebulaClusterFactor
155 nebulaHueFix:nebulaHueFix
156 alpha:nebulaAlpha
157 scale:nebulaScale];
158 }
159 [pool release];
160
162
163 return self;
164}
static BOOL sInited
Definition OOCPUInfo.m:56
static float sMaxTexCoord
static float sMinTexCoord
#define UNIVERSE
Definition Universe.h:827
void registerClient:(id< OOGraphicsResetClient > client)
unsigned _nebulaCount
unsigned _starCount

References _nebulaCount, _starCount, nil, OOGraphicsResetManager::registerClient:, setUpNebulaeWithColor1:color2:clusterFactor:nebulaHueFix:alpha:scale:, setUpStarsWithColor1:color2:, OOGraphicsResetManager::sharedManager, sInited, sMaxTexCoord, sMinTexCoord, and UNIVERSE.

Here is the call graph for this function:

◆ loadNebulaTextures

- (void) loadNebulaTextures
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 436 of file OOSkyDrawable.m.

437{
438 if (sNebulaTextures == nil) {
440 initWithPListName:@"nebulatextures.plist"
441 options:kOOTextureDefaultOptions | kOOTextureAlphaMask
442 anisotropy:0.0f
443 lodBias:0.0f];
444 if (sNebulaTextures == nil) {
445 [NSException raise:OOLITE_EXCEPTION_DATA_NOT_FOUND format:@"No nebula textures could be loaded."];
446 }
447 }
448
449 [sNebulaTextures setSeed:RANROTGetFullSeed()];
450}
static OOProbabilisticTextureManager * sNebulaTextures

Referenced by OOSkyDrawable(OOPrivate)::setUpNebulaeWithColor1:color2:clusterFactor:nebulaHueFix:alpha:scale:.

Here is the caller graph for this function:

◆ loadStarTextures

- (void) loadStarTextures
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 420 of file OOSkyDrawable.m.

421{
422 if (sStarTextures == nil) {
424 initWithPListName:@"startextures.plist"
425 options:kOOTextureMinFilterMipMap | kOOTextureMagFilterLinear | kOOTextureAlphaMask
426 anisotropy:0.0f
427 lodBias:-0.0f];
428 if (sStarTextures == nil) {
429 [NSException raise:OOLITE_EXCEPTION_DATA_NOT_FOUND format:@"No star textures could be loaded."];
430 }
431 }
432
433 [sStarTextures setSeed:RANROTGetFullSeed()];
434}
static OOProbabilisticTextureManager * sStarTextures

Referenced by OOSkyDrawable(OOPrivate)::setUpStarsWithColor1:color2:.

Here is the caller graph for this function:

◆ maxDrawDistance

- (GLfloat) maxDrawDistance
implementation

Reimplemented from OODrawable.

Definition at line 228 of file OOSkyDrawable.m.

229{
230 return INFINITY;
231}

References maxDrawDistance.

Referenced by maxDrawDistance.

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

◆ renderOpaqueParts

- (void) renderOpaqueParts
implementation

Reimplemented from OODrawable.

Definition at line 178 of file OOSkyDrawable.m.

179{
180 // While technically translucent, the sky doesn't need to be depth-sorted
181 // since it'll be behind everything else anyway.
182
185
186 OOGL(glDisable(GL_DEPTH_TEST)); // don't read the depth buffer
187 OOGL(glEnable(GL_TEXTURE_2D));
188
189 // Make stars dim in atmosphere. Note: works OK on night side because sky is dark blue, not black.
190 GLfloat fogColor[4] = { 0.02, 0.02, 0.02, 1.0 };
191 OOGL(glFogfv(GL_FOG_COLOR, fogColor));
192
193 if (_displayListName != 0) {
194 OOGL(glCallList(_displayListName));
195 } else {
196 // Set up display list
197 [self ensureTexturesLoaded];
198 _displayListName = glGenLists(1);
199
200 OOGL(glNewList(_displayListName, GL_COMPILE));
201
202 OOGL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
203 OOGL(glEnableClientState(GL_COLOR_ARRAY));
204
205 [_quadSets makeObjectsPerformSelector:@selector(render)];
206
207 OOGL(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
208 OOGL(glDisableClientState(GL_COLOR_ARRAY));
209
210 OOGL(glEndList());
211 }
212
213 // Restore state
214 OOGL(glEnable(GL_DEPTH_TEST));
215 OOGL(glDisable(GL_TEXTURE_2D));
216
217 // Resetting fog is draw loop's responsibility.
218
220 OOCheckOpenGLErrors(@"OOSkyDrawable after rendering");
221}
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:123
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262

References _displayListName, ensureTexturesLoaded, OO_ENTER_OPENGL, OOCheckOpenGLErrors(), OOGL, OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_ADDITIVE_BLENDING, and renderOpaqueParts.

Referenced by renderOpaqueParts.

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

◆ resetGraphicsState

- (void) resetGraphicsState
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 458 of file OOSkyDrawable.m.

459{
461
462 if (_displayListName != 0) {
463 glDeleteLists(_displayListName, 1);
465 }
466}

◆ setUpNebulaeWithColor1:color2:clusterFactor:nebulaHueFix:alpha:scale:

- (void) setUpNebulaeWithColor1: (OOColor*) color1
color2: (OOColor*) color2
clusterFactor: (float) nebulaClusterFactor
nebulaHueFix: (BOOL) nebulaHueFix
alpha: (float) nebulaAlpha
scale: (float) nebulaScale 
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 322 of file OOSkyDrawable.m.

322 :(OOColor*)color1
323 color2:(OOColor*)color2
324 clusterFactor:(float)nebulaClusterFactor
325 nebulaHueFix:(BOOL)nebulaHueFix
326 alpha:(float)nebulaAlpha
327 scale:(float)nebulaScale
328{
329 OOSkyQuadDesc *quads = NULL, *currQuad = NULL;
330 unsigned i, actualCount = 0;
331 OOColor* color;
332 Quaternion q;
333 Vector vi, vj, vk;
334 double size, r2;
335 Vector middle, offset;
336 int r1;
337
338 [self loadNebulaTextures];
339
340 quads = malloc(sizeof *quads * _nebulaCount);
341 if (quads == NULL)
342 return;
343
344 currQuad = quads;
345 for (i = 0; i < _nebulaCount; ++i) {
346 color = SaturatedColorInRange(color1, color2, nebulaHueFix);
347
348 // Select a direction and rotation.
349 q = OORandomQuaternion();
350
351 // Create a cluster of nebula quads.
352 while ((i < _nebulaCount) && (randf() < nebulaClusterFactor)) {
353 // Select size.
354 r1 = 1 + (ranrot_rand() & 15);
355 size = nebulaScale * r1 * SKY_ELEMENT_SCALE_FACTOR;
356
357 // Calculate centre position and offset to first corner.
358 basis_vectors_from_quaternion(q, &vi, &vj, &vk);
359
360 // Select colour and texture. Smaller nebula quads are dimmer.
361#if DEBUG_COLORS
362 currQuad->color = DebugColor(vk);
363#else
364 currQuad->color = [color colorWithBrightnessFactor:nebulaAlpha * (0.5f + (float)r1 / 32.0f)];
365#endif
366 currQuad->texture = [sNebulaTextures selectTexture]; // Not retained, since sStarTextures is never released.
367
369 offset = vector_multiply_scalar(vector_add(vi, vj), 0.5f * size);
370
371 // Rotate vi and vj by a random angle
372 r2 = randf() * M_PI * 2.0;
376
377 // Scale the "side" vectors.
380
381 // Set up corners.
382 currQuad->corners[0] = vector_subtract(middle, offset);
383 currQuad->corners[1] = vector_add(currQuad->corners[0], vj);
384 currQuad->corners[2] = vector_add(currQuad->corners[1], vi);
385 currQuad->corners[3] = vector_add(currQuad->corners[0], vi);
386
387 // Shuffle direction quat around a bit to spread the cluster out.
389 q.x += size * (randf() - 0.5);
390 q.y += size * (randf() - 0.5);
391 q.z += size * (randf() - 0.5);
392 q.w += size * (randf() - 0.5);
394
395 ++i;
396 ++currQuad;
397 ++actualCount;
398 }
399 }
400
401 /* The above code generates less than _nebulaCount quads, because i is
402 incremented once in the outer loop as well as in the inner loop. To
403 keep skies looking the same, we leave the bug in and fill in the
404 actual generated count here.
405 */
406 _nebulaCount = actualCount;
407
408 [self addQuads:quads count:_nebulaCount];
409 free(quads);
410}
#define M_PI
Definition OOMaths.h:54
void basis_vectors_from_quaternion(Quaternion quat, Vector *outRight, Vector *outUp, Vector *outForward)
struct Quaternion Quaternion
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
OOINLINE Quaternion OORandomQuaternion(void) ALWAYS_INLINE_FUNC
Vector vector_right_from_quaternion(Quaternion quat) CONST_FUNC
#define SKY_ELEMENT_SCALE_FACTOR
#define NEBULA_SHUFFLE_FACTOR
static OOColor * SaturatedColorInRange(OOColor *color1, OOColor *color2, BOOL hueFix)
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE Vector vector_subtract(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:218
struct Vector Vector
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
#define BILLBOARD_DEPTH
Definition Universe.h:154
OOColor * colorWithBrightnessFactor:(float factor)
Definition OOColor.m:457
voidpf void uLong size
Definition ioapi.h:126
voidpf uLong offset
Definition ioapi.h:132
float randf(void)
#define ranrot_rand()
OOScalar w
OOScalar x
OOScalar y
OOScalar z

Referenced by initWithColor1:Color2:Color3:Color4:starCount:nebulaCount:nebulaHueFix:clusterFactor:alpha:scale:.

Here is the caller graph for this function:

◆ setUpStarsWithColor1:color2:

- (void) setUpStarsWithColor1: (OOColor*) color1
color2: (OOColor*) color2 
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 271 of file OOSkyDrawable.m.

271 :(OOColor*)color1 color2:(OOColor*)color2
272{
273 OOSkyQuadDesc *quads = NULL, *currQuad = NULL;
274 unsigned i;
275 Quaternion q;
276 Vector vi, vj, vk;
277 float size;
278 Vector middle, offset;
279
280 [self loadStarTextures];
281
282 quads = malloc(sizeof *quads * _starCount);
283 if (quads == NULL)
284 return;
285
286 currQuad = quads;
287 for (i = 0; i != _starCount; ++i) {
288 // Select a direction and rotation.
289 q = OORandomQuaternion();
290 basis_vectors_from_quaternion(q, &vi, &vj, &vk);
291
292 // Select colour and texture.
293#if DEBUG_COLORS
294 currQuad->color = DebugColor(vk);
295#else
296 currQuad->color = [color1 blendedColorWithFraction:randf() ofColor:color2];
297#endif
298 currQuad->texture = [sStarTextures selectTexture]; // Not retained, since sStarTextures is never released.
299
300 // Select scale; calculate centre position and offset to first corner.
301 size = (1 + (ranrot_rand() % 6)) * SKY_ELEMENT_SCALE_FACTOR;
303 offset = vector_multiply_scalar(vector_add(vi, vj), 0.5f * size);
304
305 // Scale the "side" vectors.
308
309 // Set up corners.
310 currQuad->corners[0] = vector_subtract(middle, offset);
311 currQuad->corners[1] = vector_add(currQuad->corners[0], vj2);
312 currQuad->corners[2] = vector_add(currQuad->corners[1], vi2);
313 currQuad->corners[3] = vector_add(currQuad->corners[0], vi2);
314
315 ++currQuad;
316 }
317
318 [self addQuads:quads count:_starCount];
319 free(quads);
320}
OOColor * blendedColorWithFraction:ofColor:(float fraction,[ofColor] OOColor *color)
Definition OOColor.m:309

Referenced by initWithColor1:Color2:Color3:Color4:starCount:nebulaCount:nebulaHueFix:clusterFactor:alpha:scale:.

Here is the caller graph for this function:

Member Data Documentation

◆ _displayListName

- (GLint) _displayListName
private

Definition at line 42 of file OOSkyDrawable.h.

Referenced by dealloc, and renderOpaqueParts.

◆ _nebulaCount

- (unsigned) _nebulaCount
private

◆ _quadSets

- (NSMutableArray*) _quadSets
private

Definition at line 40 of file OOSkyDrawable.h.

◆ _starCount

- (unsigned) _starCount
private

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