31#import "MyOpenGLView.h"
41@interface OOSunEntity (Private)
43- (void) calculateGLArrays:(GLfloat)inner_radius width:(GLfloat)width zDistance:(GLfloat)z_distance;
63 if (sun_color ==
nil)
return NO;
67 float hue, sat, bri, alf;
84 float hue_drift = 0.0038f * fabsf(
randf() -
randf());
90 GLfloat sun_ambient[] = { 0.0, 0.0, 0.0, 1.0};
100 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient));
115 hue += hue_drift * 3;
125- (id) initSunWithColor:(
OOColor *)sun_color andDictionary:(NSDictionary *) dict
140 [
self setName:OOExpand([
dict oo_stringForKey:KEY_SUNNAME defaultValue:@"[oolite-default-star-name]"])];
142 corona_blending=OOClamp_0_1_f([dict oo_floatForKey:
@"corona_hues" defaultValue:1.0f]);
154#ifdef OO_DUMP_PLANETINFO
166 for (
unsigned i=0 ; i < 360 ; i++)
168 unsigned j = (i+1)%360;
174 for (
unsigned i=0 ; i < 360 ; i++)
176 unsigned j = (i+1)%360;
125- (id) initSunWithColor:(
OOColor *)sun_color andDictionary:(NSDictionary *) dict {
…}
220 NSString *result = [
NSString stringWithFormat:@"ID: %u position: %@ radius: %.3fkm", [
self universalID], HPVectorDescription([
self position]), 0.001 * [
self radius]];
223 result = [
result stringByAppendingString:@" (gone nova)"];
227 result = [
result stringByAppendingString:@" (will go nova)"];
241- (BOOL) checkCloseCollisionWith:(
Entity *)other
245 OOLog(
@"sun.collide",
@"%@",
@"SUN Collision!");
241- (BOOL) checkCloseCollisionWith:(
Entity *)other {
…}
258 assert(player !=
nil);
278 [UNIVERSE setSkyColorRed:0.0f
285 [UNIVERSE setSkyColorRed:sky_bri
293 [UNIVERSE setSystemDataKey:@"sun_gone_nova" value:[
NSNumber numberWithBool:YES] fromManifest:@"org.oolite.oolite"];
294 [UNIVERSE setSystemDataKey:@"corona_flare" value:[
NSNumber numberWithFloat:0.3] fromManifest:@"org.oolite.oolite"];
295 [UNIVERSE setSystemDataKey:@"corona_hues" value:[
NSNumber numberWithFloat:0.05] fromManifest:@"org.oolite.oolite"];
303 [UNIVERSE setSystemDataKey:@"sun_radius" value:[
NSNumber numberWithFloat:collision_radius + delta_t * _novaExpansionRate] fromManifest:@"org.oolite.oolite"];
324 for (i = 0; i < 360; i++)
336- (void) drawImmediate:(
bool)immediate translucent:(
bool)translucent
336- (void) drawImmediate:(
bool)immediate translucent:(
bool)translucent {
…}
369 cr_temp = HPvector_multiply_scalar(cr_temp,1E9/HPmagnitude(cr_temp));
377 float sqrt_zero_distance = sqrt(cam_zero_distance);
378 float effective_radius = collision_radius;
379 float effective_cor16k = cor16k;
385 float large_distance_compensator = sqrt_zero_distance / 1000000000.0f;
386 if (large_distance_compensator > 1.0f)
388 sqrt_zero_distance /= large_distance_compensator;
389 effective_radius /= large_distance_compensator;
390 effective_cor16k /= large_distance_compensator;
399 int subdivideLevel = 2;
400 float drawFactor = [[UNIVERSE gameView] viewSize].width / 100.0;
401 float drawRatio2 = drawFactor * effective_radius / sqrt_zero_distance;
403 if (cam_zero_distance > 0.0f)
405 subdivideLevel = 2 + floorf(drawRatio2);
406 if (subdivideLevel > 4)
419 BOOL ignoreDepthBuffer = cam_zero_distance > effective_radius * effective_radius * 25;
424 if (ignoreDepthBuffer)
OOGL(glDisable(GL_DEPTH_TEST));
426 OOGL(glColor3fv(discColor));
428 OOGL(glDisable(GL_BLEND));
432 OOGL(glEnable(GL_BLEND));
434 if (ignoreDepthBuffer)
OOGL(glEnable(GL_DEPTH_TEST));
440 width:effective_cor16k
442 OOGL(glDisable(GL_BLEND));
443 OOGL(glVertexPointer(3, GL_FLOAT, 0, sunVertices));
445 OOGL(glEnableClientState(GL_COLOR_ARRAY));
446 OOGL(glColorPointer(4, GL_FLOAT, 0, sunColors));
448 OOGL(glDrawElements(GL_TRIANGLES, 3*360, GL_UNSIGNED_INT, sunTriangles));
450 OOGL(glDisableClientState(GL_COLOR_ARRAY));
451 OOGL(glEnable(GL_BLEND));
472 OOGL(glVertexPointer(3, GL_FLOAT, 0, sunVertices));
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)));
478 OOGL(glDisableClientState(GL_COLOR_ARRAY));
483- (void) calculateGLArrays:(GLfloat)inner_radius width:(GLfloat)width zDistance:(GLfloat)z_distance
487 GLfloat activity[8] = {0.84, 0.74, 0.64, 0.54,
488 0.3 , 0.4 , 0.7 , 0.8};
491 GLfloat rv0, rv1, rv2, c0, c1, c2;
494 unsigned short i, j, k;
495 GLfloat theta = 0.0f, delta;
496 delta =
M_PI / 180.0f;
497 pt0=(1.0 - corona_stage) * corona_blending;
498 pt1=corona_stage * corona_blending;
500 sunVertices[0] = 0.0;
501 sunVertices[1] = 0.0;
502 sunVertices[2] = 0.0;
504 for (j = 0 ; j <= 4 ; j++)
506 GLfloat r = inner_radius;
522 for (i = 0 ; i < 360 ; i++)
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;
529 GLfloat z = r * r * rm * rm / z_distance;
533 sunVertices[
k++] = si * r * rm;
534 sunVertices[
k++] = ci * r * rm;
535 sunVertices[
k++] = -z;
539 GLfloat blackColor[4] = {0.0,0.0,0.0,0.0};
540 GLfloat *color = blackColor;
544 sunColors[
k++] = discColor[0];
545 sunColors[
k++] = discColor[1];
546 sunColors[
k++] = discColor[2];
547 sunColors[
k++] = discColor[3] * _sunCoronaAlphaFactor;
549 for (j = 0 ; j <= 4 ; j++)
557 color = outerCoronaColor;
561 color = outerCoronaColor;
573 for (i = 0 ; i < 360 ; i++)
577 sunColors[
k++] = color[0];
578 sunColors[
k++] = color[1];
579 sunColors[
k++] = color[2];
580 sunColors[
k++] = alpha * _sunCoronaAlphaFactor;
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)
598 sunColors[
k++] = alpha * _sunCoronaAlphaFactor;
483- (void) calculateGLArrays:(GLfloat)inner_radius width:(GLfloat)width zDistance:(GLfloat)z_distance {
…}
607#if SUN_DIRECT_VISION_GLARE
612 GLfloat sunGlareAngularSize = atan([
self radius]/HPdistance([
PLAYER viewpointPosition], [
self position])) * SUN_GLARE_MULT_FACTOR + (SUN_GLARE_ADD_FACTOR);
614 GLfloat directVisionSunGlare = [PLAYER lookingAtSunWithThresholdAngleCos:cosf(sunGlareAngularSize)];
615 if (directVisionSunGlare)
617 NSSize siz = [[UNIVERSE gui] size];
620 GLfloat z = [
gameView display_z] / (aspectRatio > 4.0f/3.0f ? aspectRatio : 1.0f / aspectRatio);
621 GLfloat atmosphericReductionFactor = 1.0f - [PLAYER insideAtmosphereFraction];
625 GLfloat sunGlareFilterMultiplierLocal = [PLAYER sunGlareFilter];
627 atmosphericReductionFactor * distanceReductionFactor *
628 (1.0f - sunGlareFilterMultiplierLocal) * 0.0085f};
630 OOGL(glColor4fv(directVisionSunGlareColor));
633 glVertex3f(siz.width, siz.height, z);
634 glVertex3f(siz.width, -siz.height, z);
635 glVertex3f(-siz.width, -siz.height, z);
636 glVertex3f(-siz.width, siz.height, z);
658 float alpha = (1-(alt/corona));
662 NSSize siz = [[UNIVERSE gui] size];
665 GLfloat z = [
gameView display_z] / (aspectRatio > 4.0f/3.0f ? aspectRatio : 1.0f / aspectRatio);
666 OOGL(glColor4fv(glareColor));
669 glVertex3f(siz.width, siz.height, z);
670 glVertex3f(siz.width, -siz.height, z);
671 glVertex3f(-siz.width, -siz.height, z);
672 glVertex3f(-siz.width, siz.height, z);
680- (BOOL) changeSunProperty:(NSString *)key withDictionary:(NSDictionary*) dict
682 id object = [
dict objectForKey:key];
683 static GLfloat oldRadius = 0.0;
684 if ([key isEqualToString:
@"sun_radius"])
686 oldRadius = [
object doubleValue];
693 else if ([key isEqualToString:
@"corona_flare"])
697 else if ([key isEqualToString:
@"corona_shimmer"])
701 else if ([key isEqualToString:
@"corona_hues"])
705 else if ([key isEqualToString:
@"sun_gone_nova"])
708 if ([dict oo_boolForKey:key])
722 OOLogWARN(
@"script.warning",
@"Change to property '%@' not applied, will apply only after leaving this system.",key);
680- (BOOL) changeSunProperty:(NSString *)key withDictionary:(NSDictionary*) dict {
…}
735- (void) getDiffuseComponents:(GLfloat[4])components
737 NSParameterAssert(components != NULL);
735- (void) getDiffuseComponents:(GLfloat[4])components {
…}
742- (void) getSpecularComponents:(GLfloat[4])components
744 NSParameterAssert(components != NULL);
742- (void) getSpecularComponents:(GLfloat[4])components {
…}
755- (void) setRadius:(GLfloat) rad andCorona:(GLfloat)corona
758 if (corona < 0.01f) {
761 cor16k = rad * 8 * corona;
763 GLfloat corouter = rad * (1+(8*corona));
755- (void) setRadius:(GLfloat) rad andCorona:(GLfloat)corona {
…}
769- (void) setPosition:(HPVector) posn
772 [UNIVERSE setMainLightPosition: HPVectorToVector(posn)];
769- (void) setPosition:(HPVector) posn {
…}
788- (void) setGoingNova:(BOOL) yesno inTime:(
double)interval
794 OOLog(
@"script.debug.setSunNovaIn",
@"NOVA activated! time until Nova : %.1f s",
_novaCountdown);
788- (void) setGoingNova:(BOOL) yesno inTime:(
double)interval {
…}
828- (void) setName:(NSString *)name
831 _name = [name retain];
828- (void) setName:(NSString *)name {
…}
#define NO_DRAW_DISTANCE_FACTOR
#define OOLogWARN(class, format,...)
#define OOLog(class, format,...)
#define OO_ENTER_OPENGL()
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos)
@ OPENGL_STATE_ADDITIVE_BLENDING
#define OOVerifyOpenGLState()
BOOL OOCheckOpenGLErrors(NSString *format,...)
void GLDrawBallBillboard(GLfloat radius, GLfloat step, GLfloat z_distance)
#define OOSetOpenGLState(STATE)
#define SUN_GLARE_CORONA_FACTOR
#define SUN_CORONA_SAMPLES
void drawTranslucentParts()
OOUniversalID universalID
HPVector absolutePositionForSubentity()
void update:(OOTimeDelta delta_t)
Vector cameraRelativePosition
GLfloat cam_zero_distance
BOOL checkCloseCollisionWith:(Entity *other)
void setPosition:(HPVector posn)
void getHue:saturation:brightness:alpha:(float *hue,[saturation] float *saturation,[brightness] float *brightness,[alpha] float *alpha)
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
OOColor * colorWithHue:saturation:brightness:alpha:(float hue,[saturation] float saturation,[brightness] float brightness,[alpha] float alpha)
OOColor * blendedColorWithFraction:ofColor:(float fraction,[ofColor] OOColor *color)
void setRadius:andCorona:(GLfloat rad,[andCorona] GLfloat corona)
void setGoingNova:inTime:(BOOL yesno,[inTime] double interval)
float _sunCoronaAlphaFactor
void drawDirectVisionSunGlare()
void setName:(NSString *name)
double corona_speed_factor
BOOL changeSunProperty:withDictionary:(NSString *key,[withDictionary] NSDictionary *dict)
GLfloat rvalue[SUN_CORONA_SAMPLES]
void drawTranslucentParts()
void updateCameraRelativePosition()
OOStellarBodyType planetType()
NSString * descriptionComponents()
GLuint sunTriangles[3240 *3]
OOTimeDelta _novaCountdown
void calculateGLArrays:width:zDistance:(GLfloat inner_radius, [width] GLfloat width, [zDistance] GLfloat z_distance)
OOTimeDelta _novaExpansionTimer
float _sunBrightnessFactor
BOOL setSunColor:(OOColor *sun_color)