Oolite 1.91.0.7646-241128-10e222e
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]
 
(NSSet *) - allTextures [implementation]
 
(size_t) - totalSize [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 36 of file OOSkyDrawable.h.

Method Documentation

◆ addQuads:count:

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

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 83 of file OOSkyDrawable.m.

444 :(OOSkyQuadDesc *)quads count:(unsigned)count
445{
446 if (_quadSets == nil) _quadSets = [[NSMutableArray alloc] init];
447
448 [OOSkyQuadSet addQuads:quads count:count toArray:_quadSets];
449}
unsigned count
return nil
void addQuads:count:toArray:(OOSkyQuadDesc *quads,[count] unsigned count,[toArray] NSMutableArray *ioArray)

◆ allTextures

- (NSSet *) allTextures
implementation

Reimplemented from OODrawable.

Definition at line 83 of file OOSkyDrawable.m.

256{
257 NSMutableSet *result = [NSMutableSet setWithCapacity:[_quadSets count]];
258
259 NSEnumerator *quadSetEnum = nil;
260 OOSkyQuadSet *quadSet = nil;
261 for (quadSetEnum = [_quadSets objectEnumerator]; (quadSet = [quadSetEnum nextObject]); )
262 {
263 [result addObject:[quadSet texture]];
264 }
265
266 return result;
267}
NSMutableArray * _quadSets
OOTexture * texture()

◆ dealloc

- (void) dealloc
implementation

Definition at line 83 of file OOSkyDrawable.m.

183{
185
186 [_quadSets release];
188 if (_displayListName != 0) glDeleteLists(_displayListName, 1);
189
190 [super dealloc];
191}
#define OO_ENTER_OPENGL()
void unregisterClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()
GLint _displayListName

◆ ensureTexturesLoaded

- (void) ensureTexturesLoaded
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 83 of file OOSkyDrawable.m.

493{
494 [sStarTextures ensureTexturesLoaded];
495 [sNebulaTextures ensureTexturesLoaded];
496}

◆ hasOpaqueParts

- (BOOL) hasOpaqueParts
implementation

Reimplemented from OODrawable.

Definition at line 83 of file OOSkyDrawable.m.

244{
245 return YES;
246}

◆ 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 83 of file OOSkyDrawable.m.

133 :(OOColor *)color1
134 Color2:(OOColor *)color2
135 Color3:(OOColor *)color3
136 Color4:(OOColor *)color4
137 starCount:(unsigned)starCount
138 nebulaCount:(unsigned)nebulaCount
139 nebulaHueFix:(BOOL)nebulaHueFix
140 clusterFactor:(float)nebulaClusterFactor
141 alpha:(float)nebulaAlpha
142 scale:(float)nebulaScale
143{
144 NSAutoreleasePool *pool = nil;
145
146 if (!sInited)
147 {
148 sInited = YES;
149 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"sky-render-inset-coords"])
150 {
151 sMinTexCoord += 1.0f/128.0f;
152 sMaxTexCoord -= 1.0f/128.0f;
153 }
154 }
155
156 self = [super init];
157 if (self == nil) return nil;
158
159 _starCount = starCount;
160 _nebulaCount = nebulaCount;
161
162 pool = [[NSAutoreleasePool alloc] init];
163 [self setUpStarsWithColor1:color1 color2:color2];
164
165 if (![UNIVERSE reducedDetail])
166 {
167 [self setUpNebulaeWithColor1:color3
168 color2:color4
169 clusterFactor:nebulaClusterFactor
170 nebulaHueFix:nebulaHueFix
171 alpha:nebulaAlpha
172 scale:nebulaScale];
173 }
174 [pool release];
175
177
178 return self;
179}
static BOOL sInited
static float sMaxTexCoord
static float sMinTexCoord
#define UNIVERSE
Definition Universe.h:840
void registerClient:(id< OOGraphicsResetClient > client)
unsigned _nebulaCount
unsigned _starCount

◆ loadNebulaTextures

- (void) loadNebulaTextures
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 83 of file OOSkyDrawable.m.

473{
474 if (sNebulaTextures == nil)
475 {
477 initWithPListName:@"nebulatextures.plist"
478 options:kOOTextureDefaultOptions | kOOTextureAlphaMask
479 anisotropy:0.0f
480 lodBias:0.0f];
481 if (sNebulaTextures == nil)
482 {
483 [NSException raise:OOLITE_EXCEPTION_DATA_NOT_FOUND format:@"No nebula textures could be loaded."];
484 }
485 }
486
487 [sNebulaTextures setSeed:RANROTGetFullSeed()];
488
489}
static OOProbabilisticTextureManager * sNebulaTextures

◆ loadStarTextures

- (void) loadStarTextures
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 83 of file OOSkyDrawable.m.

453{
454 if (sStarTextures == nil)
455 {
457 initWithPListName:@"startextures.plist"
458 options:kOOTextureMinFilterMipMap | kOOTextureMagFilterLinear | kOOTextureAlphaMask
459 anisotropy:0.0f
460 lodBias:-0.0f];
461 if (sStarTextures == nil)
462 {
463 [NSException raise:OOLITE_EXCEPTION_DATA_NOT_FOUND format:@"No star textures could be loaded."];
464 }
465 }
466
467 [sStarTextures setSeed:RANROTGetFullSeed()];
468
469}
static OOProbabilisticTextureManager * sStarTextures

◆ maxDrawDistance

- (GLfloat) maxDrawDistance
implementation

Reimplemented from OODrawable.

Definition at line 83 of file OOSkyDrawable.m.

250{
251 return INFINITY;
252}

◆ renderOpaqueParts

- (void) renderOpaqueParts
implementation

Reimplemented from OODrawable.

Definition at line 83 of file OOSkyDrawable.m.

195{
196 // While technically translucent, the sky doesn't need to be depth-sorted
197 // since it'll be behind everything else anyway.
198
201
202 OOGL(glDisable(GL_DEPTH_TEST)); // don't read the depth buffer
203 OOGL(glEnable(GL_TEXTURE_2D));
204
205 // Make stars dim in atmosphere. Note: works OK on night side because sky is dark blue, not black.
206 GLfloat fogColor[4] = {0.02, 0.02, 0.02, 1.0};
207 OOGL(glFogfv(GL_FOG_COLOR, fogColor));
208
209 if (_displayListName != 0)
210 {
211 OOGL(glCallList(_displayListName));
212 }
213 else
214 {
215 // Set up display list
216 [self ensureTexturesLoaded];
217 _displayListName = glGenLists(1);
218
219 OOGL(glNewList(_displayListName, GL_COMPILE));
220
221 OOGL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
222 OOGL(glEnableClientState(GL_COLOR_ARRAY));
223
224 [_quadSets makeObjectsPerformSelector:@selector(render)];
225
226 OOGL(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
227 OOGL(glDisableClientState(GL_COLOR_ARRAY));
228
229 OOGL(glEndList());
230 }
231
232 // Restore state
233 OOGL(glEnable(GL_DEPTH_TEST));
234 OOGL(glDisable(GL_TEXTURE_2D));
235
236 // Resetting fog is draw loop's responsibility.
237
239 OOCheckOpenGLErrors(@"OOSkyDrawable after rendering");
240}
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:125
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:136
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:39
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:135
#define OOGL(statement)
Definition OOOpenGL.h:251

◆ resetGraphicsState

- (void) resetGraphicsState
implementation

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 83 of file OOSkyDrawable.m.

500{
502
503 if (_displayListName != 0)
504 {
505 glDeleteLists(_displayListName, 1);
506 _displayListName = 0;
507 }
508}

◆ 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 83 of file OOSkyDrawable.m.

351 :(OOColor *)color1
352 color2:(OOColor *)color2
353 clusterFactor:(float)nebulaClusterFactor
354 nebulaHueFix:(BOOL)nebulaHueFix
355 alpha:(float)nebulaAlpha
356 scale:(float)nebulaScale
357{
358 OOSkyQuadDesc *quads = NULL, *currQuad = NULL;
359 unsigned i, actualCount = 0, clusters = 0;
360 OOColor *color;
361 Quaternion q;
362 Vector vi, vj, vk;
363 double size, r2;
364 Vector middle, offset;
365 int r1;
366
367 [self loadNebulaTextures];
368
369 quads = malloc(sizeof *quads * _nebulaCount);
370 if (quads == NULL) return;
371
372 currQuad = quads;
373 for (i = 0; i < _nebulaCount; ++i)
374 {
375 color = SaturatedColorInRange(color1, color2, nebulaHueFix);
376
377 // Select a direction and rotation.
378 q = OORandomQuaternion();
379
380 // Create a cluster of nebula quads.
381 while ((i < _nebulaCount) && (randf() < nebulaClusterFactor))
382 {
383 // Select size.
384 r1 = 1 + (ranrot_rand() & 15);
385 size = nebulaScale * r1 * SKY_ELEMENT_SCALE_FACTOR;
386
387 // Calculate centre position and offset to first corner.
388 basis_vectors_from_quaternion(q, &vi, &vj, &vk);
389
390 // Select colour and texture. Smaller nebula quads are dimmer.
391#if DEBUG_COLORS
392 currQuad->color = DebugColor(vk);
393#else
394 currQuad->color = [color colorWithBrightnessFactor:nebulaAlpha * (0.5f + (float)r1 / 32.0f)];
395#endif
396 currQuad->texture = [sNebulaTextures selectTexture]; // Not retained, since sStarTextures is never released.
397
398 middle = vector_multiply_scalar(vk, BILLBOARD_DEPTH);
399 offset = vector_multiply_scalar(vector_add(vi, vj), 0.5f * size);
400
401 // Rotate vi and vj by a random angle
402 r2 = randf() * M_PI * 2.0;
406
407 // Scale the "side" vectors.
408 vj = vector_multiply_scalar(vj, size);
409 vi = vector_multiply_scalar(vi, size);
410
411 // Set up corners.
412 currQuad->corners[0] = vector_subtract(middle, offset);
413 currQuad->corners[1] = vector_add(currQuad->corners[0], vj);
414 currQuad->corners[2] = vector_add(currQuad->corners[1], vi);
415 currQuad->corners[3] = vector_add(currQuad->corners[0], vi);
416
417 // Shuffle direction quat around a bit to spread the cluster out.
419 q.x += size * (randf() - 0.5);
420 q.y += size * (randf() - 0.5);
421 q.z += size * (randf() - 0.5);
422 q.w += size * (randf() - 0.5);
423 quaternion_normalize(&q);
424
425 ++i;
426 ++currQuad;
427 ++actualCount;
428 }
429 ++clusters;
430 }
431
432 /* The above code generates less than _nebulaCount quads, because i is
433 incremented once in the outer loop as well as in the inner loop. To
434 keep skies looking the same, we leave the bug in and fill in the
435 actual generated count here.
436 */
437 _nebulaCount = actualCount;
438
439 [self addQuads:quads count:_nebulaCount];
440 free(quads);
441}
#define M_PI
Definition OOMaths.h:73
Vector vector_up_from_quaternion(Quaternion quat)
Vector vector_right_from_quaternion(Quaternion quat)
void basis_vectors_from_quaternion(Quaternion quat, Vector *outRight, Vector *outUp, Vector *outForward)
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle)
#define SKY_ELEMENT_SCALE_FACTOR
#define NEBULA_SHUFFLE_FACTOR
static OOColor * SaturatedColorInRange(OOColor *color1, OOColor *color2, BOOL hueFix)
#define BILLBOARD_DEPTH
Definition Universe.h:163
OOColor * colorWithBrightnessFactor:(float factor)
Definition OOColor.m:502
voidpf void uLong size
Definition ioapi.h:134
voidpf uLong offset
Definition ioapi.h:140
float randf(void)
#define ranrot_rand()

◆ setUpStarsWithColor1:color2:

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

Provided by category OOSkyDrawable(OOPrivate).

Definition at line 83 of file OOSkyDrawable.m.

299 :(OOColor *)color1 color2:(OOColor *)color2
300{
301 OOSkyQuadDesc *quads = NULL, *currQuad = NULL;
302 unsigned i;
303 Quaternion q;
304 Vector vi, vj, vk;
305 float size;
306 Vector middle, offset;
307
308 [self loadStarTextures];
309
310 quads = malloc(sizeof *quads * _starCount);
311 if (quads == NULL) return;
312
313 currQuad = quads;
314 for (i = 0; i != _starCount; ++i)
315 {
316 // Select a direction and rotation.
317 q = OORandomQuaternion();
318 basis_vectors_from_quaternion(q, &vi, &vj, &vk);
319
320 // Select colour and texture.
321#if DEBUG_COLORS
322 currQuad->color = DebugColor(vk);
323#else
324 currQuad->color = [color1 blendedColorWithFraction:randf() ofColor:color2];
325#endif
326 currQuad->texture = [sStarTextures selectTexture]; // Not retained, since sStarTextures is never released.
327
328 // Select scale; calculate centre position and offset to first corner.
329 size = (1 + (ranrot_rand() % 6)) * SKY_ELEMENT_SCALE_FACTOR;
330 middle = vector_multiply_scalar(vk, BILLBOARD_DEPTH);
331 offset = vector_multiply_scalar(vector_add(vi, vj), 0.5f * size);
332
333 // Scale the "side" vectors.
334 Vector vj2 = vector_multiply_scalar(vj, size);
335 Vector vi2 = vector_multiply_scalar(vi, size);
336
337 // Set up corners.
338 currQuad->corners[0] = vector_subtract(middle, offset);
339 currQuad->corners[1] = vector_add(currQuad->corners[0], vj2);
340 currQuad->corners[2] = vector_add(currQuad->corners[1], vi2);
341 currQuad->corners[3] = vector_add(currQuad->corners[0], vi2);
342
343 ++currQuad;
344 }
345
346 [self addQuads:quads count:_starCount];
347 free(quads);
348}
OOColor * blendedColorWithFraction:ofColor:(float fraction,[ofColor] OOColor *color)
Definition OOColor.m:328

◆ totalSize

- (size_t) totalSize
implementation

Reimplemented from OODrawable.

Definition at line 83 of file OOSkyDrawable.m.

271{
272 size_t result = [super totalSize];
273
274 NSEnumerator *quadSetEnum = nil;
275 OOSkyQuadSet *quadSet = nil;
276 for (quadSetEnum = [_quadSets objectEnumerator]; (quadSet = [quadSetEnum nextObject]); )
277 {
278 result += [quadSet totalSize];
279 }
280
281 return result;
282}

Member Data Documentation

◆ _displayListName

- (GLint) _displayListName
private

Definition at line 44 of file OOSkyDrawable.h.

◆ _nebulaCount

- (unsigned) _nebulaCount
private

Definition at line 40 of file OOSkyDrawable.h.

◆ _quadSets

- (NSMutableArray*) _quadSets
private

Definition at line 42 of file OOSkyDrawable.h.

◆ _starCount

- (unsigned) _starCount
private

Definition at line 39 of file OOSkyDrawable.h.


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