Oolite 1.91.0.7644-241112-7f5034b
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 1 of file OOSunEntity.m.

483 :(GLfloat)inner_radius width:(GLfloat)width zDistance:(GLfloat)z_distance
484{
485// if (EXPECT_NOT(inner_radius >= z_distance)) return; // inside the sphere
486
487 GLfloat activity[8] = {0.84, 0.74, 0.64, 0.54,
488 0.3 , 0.4 , 0.7 , 0.8};
489
490 GLfloat si, ci;
491 GLfloat rv0, rv1, rv2, c0, c1, c2;
492 GLfloat pt0, pt1;
493
494 unsigned short i, j, k;
495 GLfloat theta = 0.0f, delta;
496 delta = M_PI / 180.0f; // Convert step from degrees to radians
497 pt0=(1.0 - corona_stage) * corona_blending;
498 pt1=corona_stage * corona_blending;
499
500 sunVertices[0] = 0.0;
501 sunVertices[1] = 0.0;
502 sunVertices[2] = 0.0;
503 k = 3;
504 for (j = 0 ; j <= 4 ; j++)
505 {
506 GLfloat r = inner_radius;
507 switch (j) {
508 case 4:
509 r += width;
510 break;
511 case 3:
512 r += width/1.5f;
513 break;
514 case 2:
515 r += width/3.0f;
516 break;
517 case 1:
518 r += width/15.0f;
519 break;
520 }
521 theta = 0.0;
522 for (i = 0 ; i < 360 ; i++)
523 {
524 GLfloat rm = 1.0;
525 if (j >= 1 && j < 4)
526 {
527 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;
528 }
529 GLfloat z = r * r * rm * rm / z_distance;
530 si = sinf(theta);
531 ci = cosf(theta);
532 theta += delta;
533 sunVertices[k++] = si * r * rm;
534 sunVertices[k++] = ci * r * rm;
535 sunVertices[k++] = -z;
536 }
537 }
538
539 GLfloat blackColor[4] = {0.0,0.0,0.0,0.0};
540 GLfloat *color = blackColor;
541 GLfloat alpha = 0.0;
542
543 k=0;
544 sunColors[k++] = discColor[0];
545 sunColors[k++] = discColor[1];
546 sunColors[k++] = discColor[2];
547 sunColors[k++] = discColor[3] * _sunCoronaAlphaFactor;
548
549 for (j = 0 ; j <= 4 ; j++)
550 {
551 switch (j) {
552 case 4:
553 color = blackColor;
554 alpha = 0.0;
555 break;
556 case 3:
557 color = outerCoronaColor;
558 alpha = 0.1;
559 break;
560 case 2:
561 color = outerCoronaColor;
562 alpha = 0.6;
563 break;
564 case 1:
565 color = discColor;
566 alpha = 0.95;
567 break;
568 case 0:
569 color = discColor;
570 alpha = 1.0;
571 break;
572 }
573 for (i = 0 ; i < 360 ; i++)
574 {
575 if (j == 0)
576 {
577 sunColors[k++] = color[0];
578 sunColors[k++] = color[1];
579 sunColors[k++] = color[2];
580 sunColors[k++] = alpha * _sunCoronaAlphaFactor;
581 }
582 else
583 {
584 rv0 = pt0 * rvalue[i] + pt1 * rvalue[i + 360];
585 rv1 = pt0 * rvalue[i + 1] + pt1 * rvalue[i + 361];
586 rv2 = pt0 * rvalue[i + 2] + pt1 * rvalue[i + 362];
587 c0 = color[0] * (activity[j-1] + rv0*activity[j+3]);
588 c1 = color[1] * (activity[j-1] + rv1*activity[j+3]);
589 c2 = color[2] * (activity[j-1] + rv2*activity[j+3]);
590 if (c1 > c2 && c1 > c0)
591 {
592 c1 = fmaxf(c0,c2);
593 }
594
595 sunColors[k++] = c0;
596 sunColors[k++] = c1;
597 sunColors[k++] = c2;
598 sunColors[k++] = alpha * _sunCoronaAlphaFactor;
599 }
600 }
601 }
602}
#define M_PI
Definition OOMaths.h:73

◆ drawOpaqueParts

- (void) drawOpaqueParts

Extends class OOSunEntity.

Definition at line 1 of file OOSunEntity.m.

376{
377 float sqrt_zero_distance = sqrt(cam_zero_distance);
378 float effective_radius = collision_radius;
379 float effective_cor16k = cor16k;
380
381 /* At very long ranges the floating point inaccuracies make a
382 * complete mess of the calculations, so if the sun is more than
383 * 1E9 away, draw it closer but smaller. Painter's algorithm
384 * should stop oddities with planets transiting it */
385 float large_distance_compensator = sqrt_zero_distance / 1000000000.0f; //1E9
386 if (large_distance_compensator > 1.0f)
387 {
388 sqrt_zero_distance /= large_distance_compensator;
389 effective_radius /= large_distance_compensator;
390 effective_cor16k /= large_distance_compensator;
391 }
392
394
396
397 if ([UNIVERSE reducedDetail])
398 {
399 int subdivideLevel = 2; // 4 is probably the maximum!
400 float drawFactor = [[UNIVERSE gameView] viewSize].width / 100.0;
401 float drawRatio2 = drawFactor * effective_radius / sqrt_zero_distance; // equivalent to size on screen in pixels
402
403 if (cam_zero_distance > 0.0f)
404 {
405 subdivideLevel = 2 + floorf(drawRatio2);
406 if (subdivideLevel > 4)
407 subdivideLevel = 4;
408 }
409
410 /*
411
412 The depth test gets disabled in parts of this and instead
413 we rely on the painters algorithm instead.
414
415 The depth buffer isn't granular enough to cope with huge objects at vast
416 distances.
417
418 */
419 BOOL ignoreDepthBuffer = cam_zero_distance > effective_radius * effective_radius * 25;
420
421 int steps = 2 * (MAX_SUBDIVIDE - subdivideLevel);
422
423 // Close enough not to draw flat?
424 if (ignoreDepthBuffer) OOGL(glDisable(GL_DEPTH_TEST));
425
426 OOGL(glColor3fv(discColor));
427 // FIXME: use vertex arrays
428 OOGL(glDisable(GL_BLEND));
429 OOGLBEGIN(GL_TRIANGLE_FAN);
430 GLDrawBallBillboard(effective_radius, steps, sqrt_zero_distance);
431 OOGLEND();
432 OOGL(glEnable(GL_BLEND));
433
434 if (ignoreDepthBuffer) OOGL(glEnable(GL_DEPTH_TEST));
435
436 }
437 else
438 {
439 [self calculateGLArrays:effective_radius
440 width:effective_cor16k
441 zDistance:sqrt_zero_distance];
442 OOGL(glDisable(GL_BLEND));
443 OOGL(glVertexPointer(3, GL_FLOAT, 0, sunVertices));
444
445 OOGL(glEnableClientState(GL_COLOR_ARRAY));
446 OOGL(glColorPointer(4, GL_FLOAT, 0, sunColors));
447
448 OOGL(glDrawElements(GL_TRIANGLES, 3*360, GL_UNSIGNED_INT, sunTriangles));
449
450 OOGL(glDisableClientState(GL_COLOR_ARRAY));
451 OOGL(glEnable(GL_BLEND));
452
453
454 }
455
457 OOCheckOpenGLErrors(@"SunEntity after drawing %@", self);
458}
#define OO_ENTER_OPENGL()
#define OOGLBEGIN
Definition OOOpenGL.h:253
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:125
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:136
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:39
void GLDrawBallBillboard(GLfloat radius, GLfloat step, GLfloat z_distance)
Definition OOOpenGL.m:111
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:135
#define OOGL(statement)
Definition OOOpenGL.h:251
#define OOGLEND
Definition OOOpenGL.h:254
#define MAX_SUBDIVIDE
#define UNIVERSE
Definition Universe.h:833

◆ drawTranslucentParts

- (void) drawTranslucentParts

Extends class OOSunEntity.

Definition at line 1 of file OOSunEntity.m.

462{
463 if ([UNIVERSE reducedDetail])
464 {
465 return;
466 }
467
469
471
472 OOGL(glVertexPointer(3, GL_FLOAT, 0, sunVertices));
473
474 OOGL(glEnableClientState(GL_COLOR_ARRAY));
475 OOGL(glColorPointer(4, GL_FLOAT, 0, sunColors));
476 OOGL(glDrawElements(GL_TRIANGLES, 24*360, GL_UNSIGNED_INT, sunTriangles+(3*360)));
477
478 OOGL(glDisableClientState(GL_COLOR_ARRAY));
479
480
481}

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