CARLA
 
载入中...
搜索中...
未找到
CarlaLight.cpp
浏览该文件的文档.
1// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "CarlaLight.h"
10
11UCarlaLight::UCarlaLight()
12{
13 PrimaryComponentTick.bCanEverTick = false;
14}
15
16void UCarlaLight::BeginPlay()
17{
18 Super::BeginPlay();
19
20 RegisterLight();
21}
22
23void UCarlaLight::RegisterLight()
24{
25 if(bRegistered)
26 {
27 return;
28 }
29
30 UWorld *World = GetWorld();
31 if(World)
32 {
33 UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
34 CarlaLightSubsystem->RegisterLight(this);
35 }
36 RegisterLightWithWeather();
37 bRegistered = true;
38}
39
40void UCarlaLight::OnComponentDestroyed(bool bDestroyingHierarchy)
41{
42 Super::OnComponentDestroyed(bDestroyingHierarchy);
43}
44
45void UCarlaLight::EndPlay(const EEndPlayReason::Type EndPlayReason)
46{
47 UWorld *World = GetWorld();
48 if(World)
49 {
50 UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
51 CarlaLightSubsystem->UnregisterLight(this);
52 }
53 Super::EndPlay(EndPlayReason);
54}
55
56void UCarlaLight::SetLightIntensity(float Intensity)
57{
58 LightIntensity = Intensity;
59 UpdateLights();
60}
61
62float UCarlaLight::GetLightIntensity() const
63{
64 return LightIntensity;
65}
66
67void UCarlaLight::SetLightColor(FLinearColor Color)
68{
69 LightColor = Color;
70 UpdateLights();
71 RecordLightChange();
72}
73
74FLinearColor UCarlaLight::GetLightColor() const
75{
76 return LightColor;
77}
78
79void UCarlaLight::SetLightOn(bool bOn)
80{
81 bLightOn = bOn;
82 UpdateLights();
83 RecordLightChange();
84}
85
86bool UCarlaLight::GetLightOn() const
87{
88 return bLightOn;
89}
90
91void UCarlaLight::SetLightType(ELightType Type)
92{
93 LightType = Type;
94}
95
96ELightType UCarlaLight::GetLightType() const
97{
98 return LightType;
99}
100
101carla::rpc::LightState UCarlaLight::GetLightState()
102{
104 GetLocation(),
105 LightIntensity,
106 static_cast<carla::rpc::LightState::LightGroup>(LightType),
107 LightColor,
108 bLightOn
109 );
110
111 state._id = GetId();
112
113 return state;
114}
115
116void UCarlaLight::SetLightState(carla::rpc::LightState LightState)
117{
118 LightIntensity = LightState._intensity;
119 LightColor = LightState._color;
120 LightType = static_cast<ELightType>(LightState._group);
121 bLightOn = LightState._active;
122 UpdateLights();
123 RecordLightChange();
124}
125
126FVector UCarlaLight::GetLocation() const
127{
128 auto Location = GetOwner()->GetActorLocation();
129 ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(GetWorld());
130 ALargeMapManager* LargeMap = GameMode->GetLMManager();
131 if (LargeMap)
132 {
133 Location = LargeMap->LocalToGlobalLocation(Location);
134 }
135 return Location;
136}
137
138int UCarlaLight::GetId() const
139{
140 return Id;
141}
142
143void UCarlaLight::SetId(int InId)
144{
145 Id = InId;
146}
147
148void UCarlaLight::RecordLightChange() const
149{
150 auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
151 if (Episode)
152 {
153 auto* Recorder = Episode->GetRecorder();
154 if (Recorder && Recorder->IsEnabled())
155 {
156 Recorder->AddEventLightSceneChanged(this);
157 }
158 }
159}
ELightType
Definition CarlaLight.h:23
Base class for the CARLA Game Mode.
ALargeMapManager * GetLMManager() const
FVector LocalToGlobalLocation(const FVector &InLocation) const
void RegisterLight(UCarlaLight *CarlaLight)
void UnregisterLight(UCarlaLight *CarlaLight)
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
geom::Location Location