Oolite
Loading...
Searching...
No Matches
OOSunEntity(Private) Category Reference

Instance Methods

(void) - calculateGLArrays:width:zDistance:
(void) - drawOpaqueParts
(void) - drawTranslucentParts

Detailed Description

Definition at line 41 of file OOSunEntity.m.

Method Documentation

◆ calculateGLArrays:width:zDistance:

- (void) calculateGLArrays: (GLfloat) inner_radius
width: (GLfloat) width
zDistance: (GLfloat) z_distance 

Extends class OOSunEntity.

Definition at line 438 of file OOSunEntity.m.

438 :(GLfloat)inner_radius width:(GLfloat)width zDistance:(GLfloat)z_distance
439{
440 // if (EXPECT_NOT(inner_radius >= z_distance)) return; // inside the sphere
441
442 GLfloat activity[8] = { 0.84, 0.74, 0.64, 0.54,
443 0.3, 0.4, 0.7, 0.8 };
444
445 GLfloat si, ci;
446 GLfloat rv0, rv1, rv2, c0, c1, c2;
447 GLfloat pt0, pt1;
448
449 unsigned short i, j, k;
450 GLfloat theta = 0.0f, delta;
451 delta = M_PI / 180.0f; // Convert step from degrees to radians
452 pt0 = (1.0 - corona_stage) * corona_blending;
453 pt1 = corona_stage * corona_blending;
454
455 sunVertices[0] = 0.0;
456 sunVertices[1] = 0.0;
457 sunVertices[2] = 0.0;
458 k = 3;
459 for (j = 0; j <= 4; j++) {
460 GLfloat r = inner_radius;
461 switch (j) {
462 case 4:
463 r += width;
464 break;
465 case 3:
466 r += width / 1.5f;
467 break;
468 case 2:
469 r += width / 3.0f;
470 break;
471 case 1:
472 r += width / 15.0f;
473 break;
474 }
475 theta = 0.0;
476 for (i = 0; i < 360; i++) {
477 GLfloat rm = 1.0;
478 if (j >= 1 && j < 4) {
479 rm = 1.0 + ((0.04 / j) * (pt0 * (rvalue[i] + rvalue[i + 1] + rvalue[i + 2]) + pt1 * (rvalue[i + 360] + rvalue[i + 361] + rvalue[i + 362]))) / 3;
480 }
481 GLfloat z = r * r * rm * rm / z_distance;
482 si = sinf(theta);
483 ci = cosf(theta);
484 theta += delta;
485 sunVertices[k++] = si * r * rm;
486 sunVertices[k++] = ci * r * rm;
487 sunVertices[k++] = -z;
488 }
489 }
490
491 GLfloat blackColor[4] = { 0.0, 0.0, 0.0, 0.0 };
492 GLfloat* color = blackColor;
493 GLfloat alpha = 0.0;
494
495 k = 0;
496 sunColors[k++] = discColor[0];
497 sunColors[k++] = discColor[1];
498 sunColors[k++] = discColor[2];
499 sunColors[k++] = discColor[3] * _sunCoronaAlphaFactor;
500
501 for (j = 0; j <= 4; j++) {
502 switch (j) {
503 case 4:
504 color = blackColor;
505 alpha = 0.0;
506 break;
507 case 3:
508 color = outerCoronaColor;
509 alpha = 0.1;
510 break;
511 case 2:
512 color = outerCoronaColor;
513 alpha = 0.6;
514 break;
515 case 1:
516 color = discColor;
517 alpha = 0.95;
518 break;
519 case 0:
520 color = discColor;
521 alpha = 1.0;
522 break;
523 }
524 for (i = 0; i < 360; i++) {
525 if (j == 0) {
526 sunColors[k++] = color[0];
527 sunColors[k++] = color[1];
528 sunColors[k++] = color[2];
529 sunColors[k++] = alpha * _sunCoronaAlphaFactor;
530 } else {
531 rv0 = pt0 * rvalue[i] + pt1 * rvalue[i + 360];
532 rv1 = pt0 * rvalue[i + 1] + pt1 * rvalue[i + 361];
533 rv2 = pt0 * rvalue[i + 2] + pt1 * rvalue[i + 362];
534 c0 = color[0] * (activity[j - 1] + rv0 * activity[j + 3]);
535 c1 = color[1] * (activity[j - 1] + rv1 * activity[j + 3]);
536 c2 = color[2] * (activity[j - 1] + rv2 * activity[j + 3]);
537 if (c1 > c2 && c1 > c0) {
538 c1 = fmaxf(c0, c2);
539 }
540
541 sunColors[k++] = c0;
542 sunColors[k++] = c1;
543 sunColors[k++] = c2;
544 sunColors[k++] = alpha * _sunCoronaAlphaFactor;
545 }
546 }
547 }
548}
#define M_PI
Definition OOMaths.h:54

References M_PI.

Referenced by drawOpaqueParts.

Here is the caller graph for this function:

◆ drawOpaqueParts

- (void) drawOpaqueParts

Extends class OOSunEntity.

Definition at line 339 of file OOSunEntity.m.

340{
341 float sqrt_zero_distance = sqrt(cam_zero_distance);
342 float effective_radius = collision_radius;
343 float effective_cor16k = cor16k;
344
345 /* At very long ranges the floating point inaccuracies make a
346 * complete mess of the calculations, so if the sun is more than
347 * 1E9 away, draw it closer but smaller. Painter's algorithm
348 * should stop oddities with planets transiting it */
349 float large_distance_compensator = sqrt_zero_distance / 1000000000.0f; // 1E9
350 if (large_distance_compensator > 1.0f) {
351 sqrt_zero_distance /= large_distance_compensator;
352 effective_radius /= large_distance_compensator;
353 effective_cor16k /= large_distance_compensator;
354 }
355
357
359
360 if ([UNIVERSE reducedDetail]) {
361 int subdivideLevel = 2; // 4 is probably the maximum!
362 float drawFactor = [[UNIVERSE gameView] viewSize].width / 100.0;
363 float drawRatio2 = drawFactor * effective_radius / sqrt_zero_distance; // equivalent to size on screen in pixels
364
365 if (cam_zero_distance > 0.0f) {
366 subdivideLevel = 2 + floorf(drawRatio2);
367 if (subdivideLevel > 4)
368 subdivideLevel = 4;
369 }
370
371 /*
372
373 The depth test gets disabled in parts of this and instead
374 we rely on the painters algorithm instead.
375
376 The depth buffer isn't granular enough to cope with huge objects at vast
377 distances.
378
379 */
380 BOOL ignoreDepthBuffer = cam_zero_distance > effective_radius * effective_radius * 25;
381
382 int steps = 2 * (MAX_SUBDIVIDE - subdivideLevel);
383
384 // Close enough not to draw flat?
385 if (ignoreDepthBuffer)
386 OOGL(glDisable(GL_DEPTH_TEST));
387
388 OOGL(glColor3fv(discColor));
389 // FIXME: use vertex arrays
390 OOGL(glDisable(GL_BLEND));
391 OOGLBEGIN(GL_TRIANGLE_FAN);
392 GLDrawBallBillboard(effective_radius, steps, sqrt_zero_distance);
393 OOGLEND();
394 OOGL(glEnable(GL_BLEND));
395
396 if (ignoreDepthBuffer)
397 OOGL(glEnable(GL_DEPTH_TEST));
398
399 } else {
400 [self calculateGLArrays:effective_radius
401 width:effective_cor16k
402 zDistance:sqrt_zero_distance];
403 OOGL(glDisable(GL_BLEND));
404 OOGL(glVertexPointer(3, GL_FLOAT, 0, sunVertices));
405
406 OOGL(glEnableClientState(GL_COLOR_ARRAY));
407 OOGL(glColorPointer(4, GL_FLOAT, 0, sunColors));
408
409 OOGL(glDrawElements(GL_TRIANGLES, 3 * 360, GL_UNSIGNED_INT, sunTriangles));
410
411 OOGL(glDisableClientState(GL_COLOR_ARRAY));
412 OOGL(glEnable(GL_BLEND));
413 }
414
416 OOCheckOpenGLErrors(@"SunEntity after drawing %@", self);
417}
#define OO_ENTER_OPENGL()
#define OOGLBEGIN
Definition OOOpenGL.h:269
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:123
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
void GLDrawBallBillboard(GLfloat radius, GLfloat step, GLfloat z_distance)
Definition OOOpenGL.m:107
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
#define OOGLEND
Definition OOOpenGL.h:270
#define MAX_SUBDIVIDE
#define UNIVERSE
Definition Universe.h:827

References OOSunEntity::calculateGLArrays:width:zDistance:, drawOpaqueParts, GLDrawBallBillboard(), MAX_SUBDIVIDE, OO_ENTER_OPENGL, OOCheckOpenGLErrors(), OOGL, OOGLBEGIN, OOGLEND, OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_ADDITIVE_BLENDING, and UNIVERSE.

Referenced by OOSunEntity::drawImmediate:translucent:, and drawOpaqueParts.

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

◆ drawTranslucentParts

- (void) drawTranslucentParts

Extends class OOSunEntity.

Definition at line 419 of file OOSunEntity.m.

420{
421 if ([UNIVERSE reducedDetail]) {
422 return;
423 }
424
426
428
429 OOGL(glVertexPointer(3, GL_FLOAT, 0, sunVertices));
430
431 OOGL(glEnableClientState(GL_COLOR_ARRAY));
432 OOGL(glColorPointer(4, GL_FLOAT, 0, sunColors));
433 OOGL(glDrawElements(GL_TRIANGLES, 24 * 360, GL_UNSIGNED_INT, sunTriangles + (3 * 360)));
434
435 OOGL(glDisableClientState(GL_COLOR_ARRAY));
436}

References drawTranslucentParts, OO_ENTER_OPENGL, OOGL, OOSetOpenGLState, OPENGL_STATE_ADDITIVE_BLENDING, and UNIVERSE.

Referenced by OOSunEntity::drawImmediate:translucent:, and drawTranslucentParts.

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

The documentation for this category was generated from the following file: