9#include "Math/UnrealMathUtility.h"
20 const float RandomValue = FMath::FRandRange(0.0, 1.0f);
22 FVector MaxDistance = EndTrace;
23 FVector StartPoint = LidarLocation;
27 if (HitInfo.bBlockingHit)
29 MaxDistance = HitInfo.ImpactPoint;
32 FVector DirectionVector = EndTrace - StartPoint;
33 FVector NewStartPoint = StartPoint + 0.01 * DirectionVector;
34 FVector NewVector = MaxDistance - NewStartPoint;
35 FVector NewHitpoint = NewStartPoint + RandomValue * NewVector;
37 float Distance = FVector::Dist(StartPoint, NewHitpoint) / 100;
40 const float ProbabilityFormula = PrecipitationClass / 10 * exp(-pow(Distance - (4 + 0.2 * PrecipitationClass), 2.0)
41 / pow(2, 2.0)) + 0.2 * PrecipitationClass / 10 * exp(-pow(Distance - (7 + 0.2 * PrecipitationClass), 2.0) / pow(1, 2.0));
44 bool HitSnowflake = RandomValue < ProbabilityFormula;
48 HitInfo.ImpactPoint = NewHitpoint;
51 HitInfo.Component =
nullptr;
59 float PrecipitationClass = 0;
62 if (ParticleSize < 1.0f) ParticleSize = 1.0f;
63 if (ParticleSize > 3.0f) ParticleSize = 3.0f;
65 if (PrecipitationAmount > 0 && PrecipitationAmount <= 33.33f) PrecipitationClass = 1 + ParticleSize;
66 else if (PrecipitationAmount > 33.33 && PrecipitationAmount <= 66.66f) PrecipitationClass = 2 + ParticleSize;
67 else if (PrecipitationAmount > 66.66 && PrecipitationAmount <= 100.00f) PrecipitationClass = 3 + ParticleSize;
69 return PrecipitationClass;
static float CalculatePrecipitationClass(const float PrecipitationAmount, float ParticleSize)
static bool CheckSnowflakeHitWinterSim(FHitResult &HitInfo, const float PrecipitationAmount, const float ParticleSize, const FVector EndTrace, const FVector LidarLocation)
static bool CheckSnowflakeHit(FHitResult &HitInfo, const FVector EndTrace, const FVector LidarLocation, const FWeatherParameters &WeatherParameters)
float PrecipitationParticleSize