CARLA
 
载入中...
搜索中...
未找到
CarlaHUD.cpp
浏览该文件的文档.
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 DrawText(StringList[i].Str, StringList[i].Color, Screen.X, Screen.Y);
37 }
38
39 // check to remove the string
40 if (Now >= StringList[i].TimeToDie)
41 {
42 StringList.RemoveAt(i);
43 }
44 else
45 ++i;
46 }
47
48 while (i < LineList.Num())
49 {
50 // project position from camera
51 FVector2D Begin, End;
52 if (Player->ProjectWorldLocationToScreen(LineList[i].Begin, Begin, true) &&
53 Player->ProjectWorldLocationToScreen(LineList[i].End, End, true))
54 {
55 DrawLine(Begin.X, Begin.Y, End.X, End.Y, LineList[i].Color, LineList[i].Thickness);
56 }
57
58 // check to remove the string
59 if (Now >= LineList[i].TimeToDie)
60 {
61 LineList.RemoveAt(i);
62 }
63 else
64 ++i;
65 }
66}
67
68void ACarlaHUD::AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime)
69{
70 double Now = FPlatformTime::Seconds();
71 HUDString Obj { Str, Location, Color, Now + LifeTime };
72 StringList.Add(std::move(Obj));
73}
74
75void ACarlaHUD::AddHUDLine(const FVector Begin, const FVector End, const float Thickness, const FColor Color, double LifeTime)
76{
77 double Now = FPlatformTime::Seconds();
78 HUDLine Obj { Begin, End, Thickness, Color, Now + LifeTime };
79 LineList.Add(std::move(Obj));
80}
TArray< HUDLine > LineList
Definition CarlaHUD.h:71
UWheeledVehicleMovementComponent * DebugVehicle
Definition CarlaHUD.h:63
virtual void DrawHUD() override
Definition CarlaHUD.cpp:11
TArray< HUDString > StringList
Definition CarlaHUD.h:70
void AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime)
Definition CarlaHUD.cpp:68
void AddHUDLine(const FVector Begin, const FVector End, const float Thickness, const FColor Color, double LifeTime)
Definition CarlaHUD.cpp:75