#31 Add basic dynamic weather subclass
This commit is contained in:
parent
7613a505e1
commit
4d400256d8
|
@ -0,0 +1,83 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "DynamicWeather.h"
|
||||
|
||||
#include "Components/ArrowComponent.h"
|
||||
|
||||
ADynamicWeather::ADynamicWeather(const FObjectInitializer& ObjectInitializer)
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
|
||||
RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComponent0"));
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
ArrowComponent = CreateEditorOnlyDefaultSubobject<UArrowComponent>(TEXT("ArrowComponent0"));
|
||||
if (ArrowComponent) {
|
||||
ArrowComponent->ArrowColor = FColor(150, 200, 255);
|
||||
ArrowComponent->bTreatAsASprite = true;
|
||||
ArrowComponent->SpriteInfo.Category = TEXT("Lighting");
|
||||
ArrowComponent->SpriteInfo.DisplayName = NSLOCTEXT( "SpriteCategory", "Lighting", "Lighting" );
|
||||
ArrowComponent->SetupAttachment(RootComponent);
|
||||
ArrowComponent->bLightAttachment = true;
|
||||
ArrowComponent->bIsScreenSizeScaled = true;
|
||||
}
|
||||
#endif // WITH_EDITORONLY_DATA
|
||||
}
|
||||
|
||||
void ADynamicWeather::OnConstruction(const FTransform &Transform)
|
||||
{
|
||||
Super::OnConstruction(Transform);
|
||||
Update();
|
||||
}
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
void ADynamicWeather::PostEditChangeProperty(FPropertyChangedEvent &Event)
|
||||
{
|
||||
Super::PostEditChangeProperty(Event);
|
||||
const FName PropertyName = (Event.Property != NULL ? Event.Property->GetFName() : NAME_None);
|
||||
if (PropertyName == GET_MEMBER_NAME_CHECKED(ADynamicWeather, Weather)) {
|
||||
Update();
|
||||
} else {
|
||||
AdjustSunPositionBasedOnActorRotation();
|
||||
}
|
||||
}
|
||||
|
||||
void ADynamicWeather::EditorApplyRotation(
|
||||
const FRotator &DeltaRotation,
|
||||
bool bAltDown,
|
||||
bool bShiftDown,
|
||||
bool bCtrlDown)
|
||||
{
|
||||
Super::EditorApplyRotation(DeltaRotation, bAltDown, bShiftDown, bCtrlDown);
|
||||
AdjustSunPositionBasedOnActorRotation();
|
||||
}
|
||||
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
FVector ADynamicWeather::GetSunDirection() const
|
||||
{
|
||||
const FVector2D SphericalCoords(
|
||||
FMath::DegreesToRadians(Weather.SunPolarAngle),
|
||||
FMath::DegreesToRadians(Weather.SunAzimuthAngle));
|
||||
return - SphericalCoords.SphericalToUnitCartesian();
|
||||
}
|
||||
|
||||
void ADynamicWeather::Update()
|
||||
{
|
||||
// Modify this actor's rotation according to Sun position.
|
||||
if (!SetActorRotation(FQuat(GetSunDirection().Rotation()), ETeleportType::None)) {
|
||||
UE_LOG(LogCarla, Warning, TEXT("Unable to rotate actor"));
|
||||
}
|
||||
|
||||
RefreshWeather();
|
||||
}
|
||||
|
||||
void ADynamicWeather::AdjustSunPositionBasedOnActorRotation()
|
||||
{
|
||||
const FVector Direction = - GetActorQuat().GetForwardVector();
|
||||
const FVector2D SphericalCoords = Direction.UnitCartesianToSpherical();
|
||||
Weather.SunPolarAngle = FMath::RadiansToDegrees(SphericalCoords.X);
|
||||
Weather.SunAzimuthAngle = FMath::RadiansToDegrees(SphericalCoords.Y);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "WeatherDescription.h"
|
||||
#include "DynamicWeather.generated.h"
|
||||
|
||||
class UArrowComponent;
|
||||
|
||||
UCLASS(Abstract)
|
||||
class CARLA_API ADynamicWeather : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
ADynamicWeather(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
virtual void OnConstruction(const FTransform &Transform) override;
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
|
||||
|
||||
virtual void EditorApplyRotation(const FRotator & DeltaRotation, bool bAltDown, bool bShiftDown, bool bCtrlDown) override;
|
||||
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
void SetWeatherDescription(const FWeatherDescription &WeatherDescription)
|
||||
{
|
||||
Weather = WeatherDescription;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
const FWeatherDescription &GetWeatherDescription() const
|
||||
{
|
||||
return Weather;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void RefreshWeather();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FVector GetSunDirection() const;
|
||||
|
||||
private:
|
||||
|
||||
void Update();
|
||||
|
||||
void AdjustSunPositionBasedOnActorRotation();
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
UPROPERTY()
|
||||
UArrowComponent* ArrowComponent;
|
||||
#endif // WITH_EDITORONLY_DATA
|
||||
|
||||
UPROPERTY(Category = "Weather", EditAnywhere)
|
||||
FWeatherDescription Weather;
|
||||
};
|
|
@ -0,0 +1,118 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WeatherDescription.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class EPrecipitationType : uint8
|
||||
{
|
||||
Rain UMETA(DisplayName = "Rain"),
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FWeatherDescription
|
||||
{
|
||||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
// ===========================================================================
|
||||
/// @name Weather
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
|
||||
/** Display name of the current weather. */
|
||||
UPROPERTY(Category = "Weather", EditAnywhere, BlueprintReadWrite)
|
||||
FString Name;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Weather - Sun
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
|
||||
/** Polar angle of the Sun in degrees, with 0.0 at zenith, 90.0 at equator. */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0.0", ClampMax = "180.0"))
|
||||
float SunPolarAngle = 45.0f;
|
||||
|
||||
/** Azimuth angle of the Sun in degrees. */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "-180.0", ClampMax = "180.0"))
|
||||
float SunAzimuthAngle = 0.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SunBrightness;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SunDirectionalLightIntensity;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor SunDirectionalLightColor;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SunIndirectLightIntensity;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Weather - Sky
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float CloudOpacity;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float HorizontFalloff;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor ZenithColor;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor HorizonColor;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor CloudColor;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor OverallSkyColor;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float SkyLightIntensity;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
|
||||
FLinearColor SkyLightColor;
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Weather - Precipitation
|
||||
// ===========================================================================
|
||||
/// @{
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite)
|
||||
bool bPrecipitation = false;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation"))
|
||||
EPrecipitationType PrecipitationType = EPrecipitationType::Rain;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation", ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float PrecipitationAmount = 0.0f;
|
||||
|
||||
/** */
|
||||
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation", ClampMin = "0.0", ClampMax = "100.0"))
|
||||
float PrecipitationAccumulation = 0.0f;
|
||||
|
||||
/// @}
|
||||
};
|
Loading…
Reference in New Issue