Oolite
Loading...
Searching...
No Matches
OOSunEntity.m
Go to the documentation of this file.
1/*
2
3OOSunEntity.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25#import "OOSunEntity.h"
26#import "OOMacroOpenGL.h"
28
29#import "AI.h"
30#import "MyOpenGLView.h"
31#import "OOCharacter.h"
33#import "OOColor.h"
34#import "OODebugFlags.h"
35#import "OOStringExpander.h"
36#import "OOStringParsing.h"
37#import "PlayerEntity.h"
38#import "ShipEntityAI.h"
39#import "Universe.h"
40
41@interface OOSunEntity (Private)
42
43- (void)calculateGLArrays:(GLfloat)inner_radius width:(GLfloat)width zDistance:(GLfloat)z_distance;
44- (void)drawOpaqueParts;
46
47@end
48
49@implementation OOSunEntity
50
51#ifndef NDEBUG
52- (id)init
53{
54 assert(0);
55 return nil;
56}
57#endif
58
59- (BOOL)setSunColor:(OOColor*)sun_color
60{
61 if (sun_color == nil)
62 return NO;
63
65
66 float hue, sat, bri, alf;
67 OOColor* color = nil;
68
69 // blend some white into the sun color to brighten it up
71
72 [sun_color getHue:&hue saturation:&sat brightness:&bri alpha:&alf];
73 hue /= 360;
74
75 /*
76 // FIXME: do away with hue_drift altogether?
77 // The following two lines are functionally identical to 1.73:
78 randf();randf(); // avoid ranrot dirft!
79 float hue_drift = 0.0f;
80 */
81
82 // anything more than a minimal hue drift will wipe out the original colour.
83 float hue_drift = 0.0038f * fabsf(randf() - randf());
84
85 // set the lighting color for the sun
86 GLfloat r, g, b, a;
87 [sun_color getRed:&r green:&g blue:&b alpha:&a];
88
89 GLfloat sun_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; // real ambient light inside gl_LightModel.ambient
90 sun_diffuse[0] = 0.5f * (1.0f + r); // paler
91 sun_diffuse[1] = 0.5f * (1.0f + g); // paler
92 sun_diffuse[2] = 0.5f * (1.0f + b); // paler
93 sun_diffuse[3] = 1.0;
94 sun_specular[0] = r;
95 sun_specular[1] = g;
96 sun_specular[2] = b;
97 sun_specular[3] = 1.0;
98
99 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient));
100 OOGL(glLightfv(GL_LIGHT1, GL_DIFFUSE, sun_diffuse));
101 OOGL(glLightfv(GL_LIGHT1, GL_SPECULAR, sun_specular));
102
103 // main disc less saturation (partially taken care of by the ACES tonemapper) more brightness
104 color = [OOColor colorWithHue:hue saturation:sat * 0.75f brightness:1.0f alpha:1.0f];
105 // our OpenGL color values are unclamped, so we can multiply the color components by
106 // any value we want, in order to make the sun a truly bright object in the sky
107 color = [OOColor colorWithRed:[color redComponent] * _sunBrightnessFactor green:[color greenComponent] * _sunBrightnessFactor blue:[color blueComponent] * _sunBrightnessFactor alpha:[color alphaComponent]];
108 [color getRed:&discColor[0] green:&discColor[1] blue:&discColor[2] alpha:&discColor[3]];
109
110 /* Two inner corona layers with low alpha and saturation are additively
111 blended with main corona. This produces something vaguely like a bloom
112 effect.
113 */
114 hue += hue_drift * 3;
115 // saturation = 1 would shift white to red
116 color = [OOColor colorWithHue:hue saturation:OOClamp_0_1_f(sat * 1.0f) brightness:bri * 0.75f alpha:0.45f];
117 color = [OOColor colorWithRed:[color redComponent] * _sunBrightnessFactor green:[color greenComponent] * _sunBrightnessFactor blue:[color blueComponent] * _sunBrightnessFactor alpha:[color alphaComponent]];
118 [color getRed:&outerCoronaColor[0] green:&outerCoronaColor[1] blue:&outerCoronaColor[2] alpha:&outerCoronaColor[3]];
119
120 return YES;
121}
122
123- (id)initSunWithColor:(OOColor*)sun_color andDictionary:(NSDictionary*)dict
124{
125 int i;
126
127 self = [super init];
128
129 collision_radius = 100000.0; // 100km across
130
131 scanClass = CLASS_NO_DRAW;
132
133 _sunBrightnessFactor = [[NSUserDefaults standardUserDefaults] oo_floatForKey:@"sbf" defaultValue:80.0f];
134 _sunCoronaAlphaFactor = [[NSUserDefaults standardUserDefaults] oo_floatForKey:@"scaf" defaultValue:0.005f];
135
136 [self setSunColor:sun_color];
137
138 [self setName:OOExpand([dict oo_stringForKey:KEY_SUNNAME defaultValue:@"[oolite-default-star-name]"])];
139
140 corona_blending = OOClamp_0_1_f([dict oo_floatForKey:@"corona_hues" defaultValue:1.0f]);
141 corona_speed_factor = [dict oo_floatForKey:@"corona_shimmer" defaultValue:-1.0];
142 if (corona_speed_factor < 0) {
143 // from .22222 to 2
144 corona_speed_factor = 1.0 / (0.5 + 2.0 * (randf() + randf()));
145 } else {
146 // on average: 0 = .25 , 1 = 2.25 - the same sun should give the same random component
148 }
149#ifdef OO_DUMP_PLANETINFO
150 OOLog(@"planetinfo.record", @"corona_shimmer = %f", corona_speed_factor);
151#endif
152
153 corona_stage = 0.0;
154 for (i = 0; i < SUN_CORONA_SAMPLES; i++)
155 rvalue[i] = randf();
156
157 // set up the radius properties
158 [self changeSunProperty:@"sun_radius" withDictionary:dict];
159
160 unsigned k = 0;
161 for (unsigned i = 0; i < 360; i++) {
162 unsigned j = (i + 1) % 360;
163 // disc
164 sunTriangles[k++] = 0;
165 sunTriangles[k++] = 1 + i;
166 sunTriangles[k++] = 1 + j;
167 }
168 for (unsigned i = 0; i < 360; i++) {
169 unsigned j = (i + 1) % 360;
170 // ring 1
171 sunTriangles[k++] = 1 + i;
172 sunTriangles[k++] = 1 + j;
173 sunTriangles[k++] = 361 + i;
174 sunTriangles[k++] = 1 + j;
175 sunTriangles[k++] = 361 + i;
176 sunTriangles[k++] = 361 + j;
177 // ring 2
178 sunTriangles[k++] = 361 + i;
179 sunTriangles[k++] = 361 + j;
180 sunTriangles[k++] = 721 + i;
181 sunTriangles[k++] = 361 + j;
182 sunTriangles[k++] = 721 + i;
183 sunTriangles[k++] = 721 + j;
184 // ring 3
185 sunTriangles[k++] = 721 + i;
186 sunTriangles[k++] = 721 + j;
187 sunTriangles[k++] = 1081 + i;
188 sunTriangles[k++] = 721 + j;
189 sunTriangles[k++] = 1081 + i;
190 sunTriangles[k++] = 1081 + j;
191 // ring 4
192 sunTriangles[k++] = 1081 + i;
193 sunTriangles[k++] = 1081 + j;
194 sunTriangles[k++] = 1441 + i;
195 sunTriangles[k++] = 1081 + j;
196 sunTriangles[k++] = 1441 + i;
197 sunTriangles[k++] = 1441 + j;
198 }
199
200 return self;
201}
202
203- (void)dealloc
204{
205 DESTROY(_name);
206 [super dealloc];
207}
208
210{
211 NSString* result = [NSString stringWithFormat:@"ID: %u position: %@ radius: %.3fkm", [self universalID], HPVectorDescription([self position]), 0.001 * [self radius]];
212 if ([self goneNova]) {
213 result = [result stringByAppendingString:@" (gone nova)"];
214 } else if ([self willGoNova]) {
215 result = [result stringByAppendingString:@" (will go nova)"];
216 }
217
218 return result;
219}
220
222{
223 return YES;
224}
225
226#ifdef OO_DEBUG_MONITOR_ENABLED
227- (BOOL)checkCloseCollisionWith:(Entity*)other
228{
230 OOLog(@"sun.collide", @"%@", @"SUN Collision!");
231 }
232
233 return [super checkCloseCollisionWith:other];
234}
235#endif
236
237- (void)update:(OOTimeDelta)delta_t
238{
239 [super update:delta_t];
240
241 PlayerEntity* player = PLAYER;
242 assert(player != nil);
243 rotMatrix = OOMatrixForBillboard(position, [player viewpointPosition]);
244
245 if (throw_sparks && _novaExpansionRate > 0.0f) // going NOVA!
246 {
247 if (_novaCountdown >= 0.0) // countdown
248 {
249 _novaCountdown -= delta_t;
250 if (corona_speed_factor < 5.0) {
251 corona_speed_factor += 0.75 * delta_t;
252 }
253 } else {
254 if (_novaExpansionTimer <= 60.0) // expand for a minute
255 {
256 double sky_bri = 1.0 - 1.5 * _novaExpansionTimer;
257 if (sky_bri < 0) {
258 [UNIVERSE setSkyColorRed:0.0f // back to black
259 green:0.0f
260 blue:0.0f
261 alpha:0.0f];
262 } else {
263 [UNIVERSE setSkyColorRed:sky_bri // whiteout
264 green:sky_bri
265 blue:sky_bri
266 alpha:1.0f];
267 }
268 if (sky_bri == 1.0) {
269 // This sun has now gone nova!
270 [UNIVERSE setSystemDataKey:@"sun_gone_nova" value:[NSNumber numberWithBool:YES] fromManifest:@"org.oolite.oolite"];
271 [UNIVERSE setSystemDataKey:@"corona_flare" value:[NSNumber numberWithFloat:0.3] fromManifest:@"org.oolite.oolite"];
272 [UNIVERSE setSystemDataKey:@"corona_hues" value:[NSNumber numberWithFloat:0.05] fromManifest:@"org.oolite.oolite"];
273 // Novas are stored under the core manifest if the
274 // player was there at the time. Default layer 2
275 // is fine.
276 OOLog(@"sun.nova.start", @"DEBUG: NOVA original radius %.1f", collision_radius);
277 }
281 _novaExpansionTimer += delta_t;
282 [UNIVERSE setSystemDataKey:@"sun_radius" value:[NSNumber numberWithFloat:collision_radius + delta_t * _novaExpansionRate] fromManifest:@"org.oolite.oolite"];
283 } else {
284 OOLog(@"sun.nova.end", @"DEBUG: NOVA final radius %.1f", collision_radius);
285
286 // reset at the new size
287 [self resetNova];
288 throw_sparks = YES; // keep throw_sparks at YES to indicate the higher temperature
289 }
290 }
291 }
292
293 // update corona
294 if (![UNIVERSE reducedDetail]) {
296 while (corona_stage > 1.0) {
297 int i;
298 corona_stage -= 1.0;
299 for (i = 0; i < 360; i++) {
300 rvalue[i] = rvalue[360 + i];
301 rvalue[360 + i] = randf();
302 }
303 }
304 }
305}
306
307- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
308{
309 if (![UNIVERSE breakPatternHide]) {
310 if (translucent) {
311 // nothing...
312 } else {
313 [self drawOpaqueParts];
314 /* Despite the side effects, we have to draw the translucent
315 * parts on the opaque pass. Planets, at long range, aren't
316 * depth-buffered. So if the translucent parts are drawn on the
317 * translucent pass, they appear in front of planets they are
318 * actually behind. Telabe in G3 is a good one to test with if
319 * you have any clever ideas.
320 *
321 * - CIM 8/7/2013 */
323 }
324 }
325}
326
328{
329 HPVector cr_temp = HPvector_subtract([self absolutePositionForSubentity], [PLAYER viewpointPosition]);
330 /* Special calculation as suns viewed over ~1E9 - and the bigger
331 * ones are still just about visible at this range - get floating
332 * point errors messing up the display */
333 if (EXPECT_NOT(HPmagnitude2(cr_temp) > 1E18)) {
334 cr_temp = HPvector_multiply_scalar(cr_temp, 1E9 / HPmagnitude(cr_temp));
335 }
337}
338
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}
418
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}
437
438- (void)calculateGLArrays:(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}
549
551{
552#if SUN_DIRECT_VISION_GLARE
554
556
557 GLfloat sunGlareAngularSize = atan([self radius] / HPdistance([PLAYER viewpointPosition], [self position])) * SUN_GLARE_MULT_FACTOR + (SUN_GLARE_ADD_FACTOR);
558
559 GLfloat directVisionSunGlare = [PLAYER lookingAtSunWithThresholdAngleCos:cosf(sunGlareAngularSize)];
560 if (directVisionSunGlare) {
561 NSSize siz = [[UNIVERSE gui] size];
562 MyOpenGLView* gameView = [UNIVERSE gameView];
563 GLfloat aspectRatio = ([gameView viewSize].width / [gameView viewSize].height);
564 GLfloat z = [gameView display_z] / (aspectRatio > 4.0f / 3.0f ? aspectRatio : 1.0f / aspectRatio);
565 GLfloat atmosphericReductionFactor = 1.0f - [PLAYER insideAtmosphereFraction];
566 // 182: square of ratio of radius to sun-witchpoint distance
567 // in default Lave
568 GLfloat distanceReductionFactor = OOClamp_0_1_f(([self radius] * [self radius] * 182.0) / HPdistance2([PLAYER position], [self position]));
569 GLfloat sunGlareFilterMultiplierLocal = [PLAYER sunGlareFilter];
570 GLfloat directVisionSunGlareColor[4] = { discColor[0], discColor[1], discColor[2], directVisionSunGlare * atmosphericReductionFactor * distanceReductionFactor * (1.0f - sunGlareFilterMultiplierLocal) * 0.0085f };
571
572 OOGL(glColor4fv(directVisionSunGlareColor));
573
574 OOGLBEGIN(GL_QUADS);
575 glVertex3f(siz.width, siz.height, z);
576 glVertex3f(siz.width, -siz.height, z);
577 glVertex3f(-siz.width, -siz.height, z);
578 glVertex3f(-siz.width, siz.height, z);
579 OOGLEND();
580 }
581#endif
582}
583
585{
587
589
590 float sqrt_zero_distance = sqrtf(cam_zero_distance);
591 float alt = sqrt_zero_distance - collision_radius;
592 if (EXPECT_NOT(alt < 0)) {
593 return;
594 }
595 float corona = cor16k / SUN_GLARE_CORONA_FACTOR;
596 if (corona > alt) {
597 float alpha = (1 - (alt / corona));
598 float alphaMult = _sunCoronaAlphaFactor * alpha;
599 alpha *= alphaMult;
600 GLfloat glareColor[4] = { discColor[0], discColor[1], discColor[2], alpha };
601 NSSize siz = [[UNIVERSE gui] size];
602 MyOpenGLView* gameView = [UNIVERSE gameView];
603 GLfloat aspectRatio = ([gameView viewSize].width / [gameView viewSize].height);
604 GLfloat z = [gameView display_z] / (aspectRatio > 4.0f / 3.0f ? aspectRatio : 1.0f / aspectRatio);
605 OOGL(glColor4fv(glareColor));
606
607 OOGLBEGIN(GL_QUADS);
608 glVertex3f(siz.width, siz.height, z);
609 glVertex3f(siz.width, -siz.height, z);
610 glVertex3f(-siz.width, -siz.height, z);
611 glVertex3f(-siz.width, siz.height, z);
612 OOGLEND();
613 }
614}
615
616- (BOOL)changeSunProperty:(NSString*)key withDictionary:(NSDictionary*)dict
617{
618 id object = [dict objectForKey:key];
619 static GLfloat oldRadius = 0.0;
620 if ([key isEqualToString:@"sun_radius"]) {
621 oldRadius = [object doubleValue]; // clamp corona_flare in case planetinfo.plist / savegame contains the wrong value
622 [self setRadius:oldRadius andCorona:[dict oo_floatForKey:@"corona_flare" defaultValue:0.0f]];
623 } else if ([key isEqualToString:KEY_SUNNAME]) {
624 [self setName:[dict oo_stringForKey:KEY_SUNNAME]];
625 } else if ([key isEqualToString:@"corona_flare"]) {
626 [self setRadius:collision_radius andCorona:[object floatValue]];
627 } else if ([key isEqualToString:@"corona_shimmer"]) {
628 corona_speed_factor = OOClamp_0_1_f([object floatValue]) * 2.0 + randf() * randf();
629 } else if ([key isEqualToString:@"corona_hues"]) {
630 corona_blending = OOClamp_0_1_f([object floatValue]);
631 } else if ([key isEqualToString:@"sun_gone_nova"]) {
632
633 if ([dict oo_boolForKey:key]) {
634 [self setGoingNova:YES inTime:0];
635 } else {
636 [self setGoingNova:NO inTime:0];
637 // oldRadius is always the radius we had before going nova...
638 [self setRadius:oldRadius andCorona:[dict oo_floatForKey:@"corona_flare" defaultValue:0.0f]];
639 }
640 } else {
641 OOLogWARN(@"script.warning", @"Change to property '%@' not applied, will apply only after leaving this system.", key);
642 return NO;
643 }
644 return YES;
645}
646
651
652- (void)getDiffuseComponents:(GLfloat[4])components
653{
654 NSParameterAssert(components != NULL);
655 memcpy(components, sun_diffuse, sizeof sun_diffuse);
656}
657
658- (void)getSpecularComponents:(GLfloat[4])components
659{
660 NSParameterAssert(components != NULL);
661 memcpy(components, sun_specular, sizeof sun_specular);
662}
663
664- (double)radius
665{
666 return collision_radius;
667}
668
669- (void)setRadius:(GLfloat)rad andCorona:(GLfloat)corona
670{
671 collision_radius = rad;
672 if (corona < 0.01f) {
673 corona = 0.01f;
674 }
675 cor16k = rad * 8 * corona;
676
677 GLfloat corouter = rad * (1 + (8 * corona));
678
680}
681
682- (void)setPosition:(HPVector)posn
683{
684 [super setPosition:posn];
685 [UNIVERSE setMainLightPosition:HPVectorToVector(posn)];
686}
687
689{
690 return throw_sparks;
691}
692
693- (BOOL)goneNova
694{
695 return throw_sparks && _novaCountdown <= 0;
696}
697
698- (void)setGoingNova:(BOOL)yesno inTime:(double)interval
699{
700 throw_sparks = yesno;
701 if (throw_sparks) {
702 _novaCountdown = fmax(interval, 0.0);
703 OOLog(@"script.debug.setSunNovaIn", @"NOVA activated! time until Nova : %.1f s", _novaCountdown);
704 }
705
707 _novaExpansionRate = 10000;
708}
709
711{
713 _novaExpansionRate = 0.0f;
714 _novaCountdown = 0.0;
715}
716
717- (BOOL)isSun
718{
719 return YES;
720}
721
723{
724 return YES;
725}
726
727- (NSString*)name
728{
729 return _name;
730}
731
732- (void)setName:(NSString*)name
733{
734 [_name release];
735 _name = [name retain];
736}
737
738@end
#define NO_DRAW_DISTANCE_FACTOR
Definition Entity.h:49
#define gDebugFlags
@ DEBUG_COLLISIONS
Definition OODebugFlags.h:6
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define DESTROY(x)
#define EXPECT_NOT(x)
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
Definition OOHPVector.h:198
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:260
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:255
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define OO_ENTER_OPENGL()
#define M_PI
Definition OOMaths.h:54
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos) CONST_FUNC
Definition OOMatrix.m:186
#define OOGLBEGIN
Definition OOOpenGL.h:269
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:123
@ OPENGL_STATE_OVERLAY
Definition OOOpenGL.h:124
#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
return nil
OOStellarBodyType
@ STELLAR_TYPE_SUN
#define MAX_SUBDIVIDE
#define SUN_GLARE_CORONA_FACTOR
Definition OOSunEntity.h:45
#define SUN_CORONA_SAMPLES
Definition OOSunEntity.h:33
double OOTimeDelta
Definition OOTypes.h:193
#define PLAYER
#define UNIVERSE
Definition Universe.h:827
#define KEY_SUNNAME
Definition Universe.h:122
unsigned throw_sparks
Definition Entity.h:97
GLfloat collision_radius
Definition Entity.h:107
OOUniversalID universalID
Definition Entity.m:522
HPVector absolutePositionForSubentity()
Definition Entity.m:627
void update:(OOTimeDelta delta_t)
Definition Entity.m:850
OOScanClass scanClass
Definition Entity.m:743
Vector cameraRelativePosition
Definition Entity.m:581
GLfloat cam_zero_distance
Definition Entity.h:105
HPVector position
Definition Entity.m:576
OOMatrix rotMatrix
Definition Entity.h:134
id init()
Definition Entity.m:64
void dealloc()
Definition Entity.m:98
void setPosition:(HPVector posn)
Definition Entity.m:608
GLfloat display_z
void getHue:saturation:brightness:alpha:(float *hue,[saturation] float *saturation,[brightness] float *brightness,[alpha] float *alpha)
Definition OOColor.m:403
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:107
float alphaComponent()
Definition OOColor.m:442
float blueComponent()
Definition OOColor.m:339
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344
OOColor * whiteColor()
Definition OOColor.m:249
OOColor * colorWithHue:saturation:brightness:alpha:(float hue,[saturation] float saturation,[brightness] float brightness,[alpha] float alpha)
Definition OOColor.m:100
float redComponent()
Definition OOColor.m:329
OOColor * blendedColorWithFraction:ofColor:(float fraction,[ofColor] OOColor *color)
Definition OOColor.m:309
float greenComponent()
Definition OOColor.m:334
void setRadius:andCorona:(GLfloat rad,[andCorona] GLfloat corona)
void setGoingNova:inTime:(BOOL yesno,[inTime] double interval)
GLfloat sun_specular[4]
Definition OOSunEntity.h:53
float _sunCoronaAlphaFactor
Definition OOSunEntity.h:74
void drawDirectVisionSunGlare()
void setName:(NSString *name)
double corona_speed_factor
Definition OOSunEntity.h:60
double radius()
GLfloat sun_diffuse[4]
Definition OOSunEntity.h:52
BOOL changeSunProperty:withDictionary:(NSString *key,[withDictionary] NSDictionary *dict)
GLfloat rvalue[SUN_CORONA_SAMPLES]
Definition OOSunEntity.h:62
void drawTranslucentParts()
GLfloat lim16k
Definition OOSunEntity.h:58
float corona_blending
Definition OOSunEntity.h:63
void updateCameraRelativePosition()
double corona_stage
Definition OOSunEntity.h:61
BOOL willGoNova()
OOStellarBodyType planetType()
NSString * name()
void drawOpaqueParts()
NSString * _name
Definition OOSunEntity.h:76
BOOL canCollide()
NSString * descriptionComponents()
float _novaExpansionRate
Definition OOSunEntity.h:71
GLuint sunTriangles[3240 *3]
Definition OOSunEntity.h:65
OOTimeDelta _novaCountdown
Definition OOSunEntity.h:69
GLfloat discColor[4]
Definition OOSunEntity.h:55
void drawStarGlare()
void calculateGLArrays:width:zDistance:(GLfloat inner_radius, [width] GLfloat width, [zDistance] GLfloat z_distance)
GLfloat cor16k
Definition OOSunEntity.h:58
OOTimeDelta _novaExpansionTimer
Definition OOSunEntity.h:70
float _sunBrightnessFactor
Definition OOSunEntity.h:73
BOOL setSunColor:(OOColor *sun_color)
Definition OOSunEntity.m:59
float randf(void)