Files
2025-07-04 02:33:40 -07:00

71 lines
2.4 KiB
C++

// Copyright 2016 Mookie. All Rights Reserved.
#include "EBBullet.h"
FVector AEBBullet::GetWind_Implementation(UWorld* World, FVector Location) const{
return Wind;
}
float AEBBullet::GetAirDensity_Implementation(UWorld* World, FVector Location) const{
switch (AtmosphereType) {
case (EEBAtmosphereType::AT_Curve): {
float airmp = SeaLevelAirDensity / GetCurveValue(AirDensityCurve, 0, SeaLevelAirDensity);
return GetCurveValue(AirDensityCurve, GetAltitude(World, Location) / WorldScale, SeaLevelAirDensity)* airmp;
}
case (EEBAtmosphereType::AT_Earth): {
return GetAltitudeDensity(GetAltitude(World, Location) / WorldScale / 100.0f);
}
default:{
return SeaLevelAirDensity;
}
}
}
float AEBBullet::GetSpeedOfSound_Implementation(UWorld* World, FVector Location) const{
// Safety check: Ensure WorldScale is valid
float SafeWorldScale = FMath::Max(WorldScale, 0.01f);
if (!SpeedOfSoundVariesWithAltitude) {
return FMath::Max(SeaLevelSpeedOfSound * SafeWorldScale, 1.0f);
}
float Altitude = GetAltitude(World, Location);
float CurveValueAtSeaLevel = GetCurveValue(SpeedOfSoundCurve, 0, SeaLevelSpeedOfSound);
// Safety check: Prevent division by zero
if (FMath::IsNearlyZero(CurveValueAtSeaLevel, 0.01f)) {
return FMath::Max(SeaLevelSpeedOfSound * SafeWorldScale, 1.0f);
}
float soundvmp = SeaLevelSpeedOfSound / CurveValueAtSeaLevel;
float result = GetCurveValue(SpeedOfSoundCurve, Altitude, SeaLevelSpeedOfSound) * SafeWorldScale * soundvmp;
// Safety check: Ensure result is never zero or negative
return FMath::Max(result, 1.0f);
}
float AEBBullet::GetAltitudePressure(float AltitudeMeter) const {
return FMath::Max(SeaLevelAirPressure * FMath::Pow((1 - (0.0000225577 * AltitudeMeter)), 5.25588), 0.0f);
}
float AEBBullet::GetAltitudeTemperature(float AltitudeMeter) const {
return SeaLevelAirTemperature - (TemperatureLapseRate * FMath::Min(AltitudeMeter, TropopauseAltitude));
}
float AEBBullet::GetAltitudeDensity(float AltitudeMeter) const {
float Temperature = GetAltitudeTemperature(AltitudeMeter);
float Pressure = GetAltitudePressure(AltitudeMeter);
return Pressure * 100.0f / ((Temperature + 273.15) * SpecificGasConstant);
}
float AEBBullet::GetAltitude(UWorld* World, FVector Location) const{
FVector DistanceFromOrigin = (Location - WorldCenterLocation + FVector(World->OriginLocation));
if (SphericalAltitude)
{
return (DistanceFromOrigin.Size() - SeaLevelRadius);
}
else {
return DistanceFromOrigin.Z;
}
}