CARLA
CarlaHUD.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019 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 "CarlaHUD.h"
8 
9 #include "GameFramework/PlayerController.h"
10 
12 {
13  Super::DrawHUD();
14 
15  auto Player = GetOwningPlayerController();
16  if (Player == nullptr)
17  {
18  UE_LOG(LogCarla, Error, TEXT("Can't find player controller!"));
19  return;
20  }
21 
22  if(DebugVehicle) {
23  float YL = 1600.0f;
24  float Y0 = 0.0f;
25  DebugVehicle->DrawDebug(Canvas, YL, Y0);
26  }
27 
28  double Now = FPlatformTime::Seconds();
29  int i = 0;
30  while (i < StringList.Num())
31  {
32  // project position from camera
33  FVector2D Screen;
34  if (Player->ProjectWorldLocationToScreen(StringList[i].Location, Screen, true))
35  {
36  // draw text
37  DrawText(StringList[i].Str, StringList[i].Color, Screen.X, Screen.Y);
38  }
39 
40  // check to remove the string
41  if (Now >= StringList[i].TimeToDie)
42  {
43  StringList.RemoveAt(i);
44  }
45  else
46  ++i;
47  }
48 }
49 
50 void ACarlaHUD::AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime)
51 {
52  double Now = FPlatformTime::Seconds();
53  HUDString Obj { Str, Location, Color, Now + LifeTime };
54  StringList.Add(std::move(Obj));
55 }
void AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime)
Definition: CarlaHUD.cpp:50
sensor::data::Color Color
geom::Location Location
Definition: rpc/Location.h:14
TArray< HUDString > StringList
Definition: CarlaHUD.h:60
virtual void DrawHUD() override
Definition: CarlaHUD.cpp:11
UWheeledVehicleMovementComponent * DebugVehicle
Definition: CarlaHUD.h:54