NPCs now affected by sun glare as well
This commit is contained in:
parent
e608bcb8c3
commit
6552c3d8a1
@ -1004,14 +1004,6 @@ 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;
|
||||
|
||||
/* Fractional expression of amount of entry inside a planet's atmosphere. 0.0f is out of atmosphere,
|
||||
1.0f is fully in and is normally associated with the point of ship destruct due to altitude.
|
||||
*/
|
||||
|
@ -990,6 +990,14 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
|
||||
- (double) rangeToSecondaryTarget:(Entity *)target;
|
||||
- (BOOL) hasProximityAlertIgnoringTarget:(BOOL)ignore_target;
|
||||
- (GLfloat) currentAimTolerance;
|
||||
/* 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 view point and sun, below which we consider the ship as looking
|
||||
at the sun, is passed as parameter to the method.
|
||||
*/
|
||||
- (GLfloat) lookingAtSunWithThresholdAngleCos:(GLfloat) thresholdAngleCos;
|
||||
|
||||
- (BOOL) onTarget:(OOWeaponFacing)direction withWeapon:(OOWeaponType)weapon;
|
||||
|
||||
- (OOTimeDelta) shotTime;
|
||||
|
@ -10271,6 +10271,28 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
|
||||
basic_aim *= 1.3;
|
||||
}
|
||||
}
|
||||
// only apply glare if ship is not shadowed
|
||||
if (isSunlit) {
|
||||
OOSunEntity *sun = [UNIVERSE sun];
|
||||
if (sun)
|
||||
{
|
||||
GLfloat sunGlareAngularSize = atan([sun radius]/HPdistance([self position], [sun position])) * SUN_GLARE_MULT_FACTOR + (SUN_GLARE_ADD_FACTOR);
|
||||
GLfloat glareLevel = [self lookingAtSunWithThresholdAngleCos:cos(sunGlareAngularSize)];
|
||||
if (glareLevel > 0.1f)
|
||||
{
|
||||
// looking towards sun can seriously mess up aim (glareLevel 0..1)
|
||||
basic_aim *= (1.0 + glareLevel*3.0);
|
||||
// OOLog(@"aim.debug",@"Sun glare affecting aim: %f for %@",glareLevel,self);
|
||||
if (glareLevel > 0.5f)
|
||||
{
|
||||
// strong glare makes precise targeting impossible
|
||||
best_cos = 0.99999;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GLfloat max_cos = sqrt(1-(basic_aim * basic_aim / 100000000.0));
|
||||
|
||||
if (max_cos < best_cos)
|
||||
@ -10281,6 +10303,45 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
|
||||
}
|
||||
|
||||
|
||||
// much simpler than player version
|
||||
- (GLfloat) lookingAtSunWithThresholdAngleCos:(GLfloat) thresholdAngleCos
|
||||
{
|
||||
OOSunEntity *sun = [UNIVERSE sun];
|
||||
GLfloat measuredCos = 999.0f, measuredCosAbs;
|
||||
GLfloat sunBrightness = 0.0f;
|
||||
Vector relativePosition, unitRelativePosition;
|
||||
|
||||
if (EXPECT_NOT(!sun)) return 0.0f;
|
||||
|
||||
relativePosition = HPVectorToVector(HPvector_subtract([self position], [sun position]));
|
||||
unitRelativePosition = vector_normal_or_zbasis(relativePosition);
|
||||
switch (currentWeaponFacing)
|
||||
{
|
||||
case WEAPON_FACING_FORWARD:
|
||||
measuredCos = -dot_product(unitRelativePosition, v_forward);
|
||||
break;
|
||||
case WEAPON_FACING_AFT:
|
||||
measuredCos = +dot_product(unitRelativePosition, v_forward);
|
||||
break;
|
||||
case WEAPON_FACING_PORT:
|
||||
measuredCos = +dot_product(unitRelativePosition, v_right);
|
||||
break;
|
||||
case WEAPON_FACING_STARBOARD:
|
||||
measuredCos = -dot_product(unitRelativePosition, v_right);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
measuredCosAbs = fabs(measuredCos);
|
||||
if (thresholdAngleCos <= measuredCosAbs && measuredCosAbs <= 1.0f) // angle from viewpoint to sun <= desired threshold
|
||||
{
|
||||
sunBrightness = (measuredCos - thresholdAngleCos) / (1.0f - thresholdAngleCos);
|
||||
if (sunBrightness < 0.0f) sunBrightness = 0.0f;
|
||||
}
|
||||
return sunBrightness * sunBrightness * sunBrightness;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) onTarget:(OOWeaponFacing)direction withWeapon:(OOWeaponType)weapon_type
|
||||
{
|
||||
// initialize dq to a value that would normally return NO; dq is handled inside the defaultless switch(direction) statement
|
||||
|
Loading…
x
Reference in New Issue
Block a user