Experimental sun glare effect when directly looking at the sun. Disabled for now, define SUN_DIRECT_VISION_GLARE in OOSunEntity.h to 1 to activate it. Actual direct viewing angle threshold can be maybe adjusted further.

This commit is contained in:
AnotherCommander 2014-02-12 17:15:30 +01:00
parent 748d3a8039
commit d2c5cec125
5 changed files with 85 additions and 1 deletions

View File

@ -35,6 +35,11 @@ MA 02110-1301, USA.
#define SUN_CORONA_SAMPLES 729 // Samples at half-degree intervals, with a bit of overlap.
#define MAX_CORONAFLARE 600000.0 // nova flare
#ifndef SUN_DIRECT_VISION_GLARE
#define SUN_DIRECT_VISION_GLARE 0
#define SUN_DIRECT_VISION_THRESHOLD_ANGLE_COS 0.9945f // 6 degrees
#endif
@class ShipEntity;
@ -80,6 +85,6 @@ MA 02110-1301, USA.
- (void) setGoingNova:(BOOL) yesno inTime:(double)interval;
- (void) drawStarGlare;
- (void) drawDirectVisionSunGlare;
@end

View File

@ -555,6 +555,39 @@ MA 02110-1301, USA.
}
#if SUN_DIRECT_VISION_GLARE
- (void) drawDirectVisionSunGlare
{
OO_ENTER_OPENGL();
OOSetOpenGLState(OPENGL_STATE_OVERLAY);
GLfloat directVisionSunGlare = [PLAYER lookingAtSunWithThresholdAngleCos:SUN_DIRECT_VISION_THRESHOLD_ANGLE_COS];
if (directVisionSunGlare)
{
NSSize siz = [[UNIVERSE gui] size];
GLfloat z = [[UNIVERSE gameView] display_z];
GLfloat directVisionSunGlareColor[4] = {discColor[0], discColor[1], discColor[2], directVisionSunGlare};
OOGL(glColor4fv(directVisionSunGlareColor));
OOGLBEGIN(GL_QUADS);
glVertex3f(siz.width, siz.height, z);
glVertex3f(siz.width, -siz.height, z);
glVertex3f(-siz.width, -siz.height, z);
glVertex3f(-siz.width, siz.height, z);
OOGLEND();
}
}
#else
- (void) drawDirectVisionSunGlare
{
// do nothing
}
#endif
- (void) drawStarGlare
{
OO_ENTER_OPENGL();

View File

@ -1004,6 +1004,14 @@ typedef enum
- (void) doGuiScreenResizeUpdates;
/* This method returns a value between 0.0f and 1.0f, depending on how directly our view point
faces the sun and is used for generating the "staring at the sun" glare effect. 0.0f means that
we are not facing the sun, 1.0f means that we are looking directly at it. The cosine of the
threshold angle between player view point and sun, below which we consider the player as looking
at the sun, is passed as parameter to the method.
*/
- (GLfloat) lookingAtSunWithThresholdAngleCos:(GLfloat) thresholdAngleCos;
@end

View File

@ -1966,6 +1966,43 @@ static GLfloat sBaseMass = 0.0;
}
- (GLfloat) lookingAtSunWithThresholdAngleCos:(GLfloat) thresholdAngleCos
{
OOSunEntity *sun = [UNIVERSE sun];
GLfloat measuredCos = 999.0f, measuredCosAbs, sunBrightness = 0.0f;
Vector relativePosition, unitRelativePosition;
if (!sun) return 0.0f;
relativePosition = HPVectorToVector(HPvector_subtract([self viewpointPosition], [sun position]));
unitRelativePosition = vector_normal_or_zbasis(relativePosition);
switch ([UNIVERSE viewDirection])
{
case VIEW_FORWARD:
measuredCos = -dot_product(unitRelativePosition, v_forward);
break;
case VIEW_AFT:
measuredCos = +dot_product(unitRelativePosition, v_forward);
break;
case VIEW_PORT:
measuredCos = +dot_product(unitRelativePosition, v_right);
break;
case VIEW_STARBOARD:
measuredCos = -dot_product(unitRelativePosition, v_right);
break;
default:
break;
}
measuredCosAbs = fabs(measuredCos);
if (thresholdAngleCos < measuredCosAbs && measuredCosAbs < 1.0f) // angle from viewpoint to sun < 10 deg
{
sunBrightness = (measuredCos - thresholdAngleCos) / (1.0f - thresholdAngleCos);
if (sunBrightness < 0.0f) sunBrightness = 0.0f;
}
return sunBrightness;
}
#ifndef NDEBUG
#define STAGE_TRACKING_BEGIN { \
NSString * volatile updateStage = @"initialisation"; \

View File

@ -4323,6 +4323,7 @@ static const OOMatrix starboard_matrix =
{
if (cachedSun)
{
[cachedSun drawDirectVisionSunGlare];
[cachedSun drawStarGlare];
}
}