CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Game
CarlaHUD.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 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 <util/ue-header-guard-begin.h>
10
#include "Engine/Engine.h"
11
#include "Engine/Canvas.h"
12
#include "CanvasItem.h"
13
#include "PhysicalMaterials/PhysicalMaterial.h"
14
#include "GameFramework/PlayerController.h"
15
#include <util/ue-header-guard-end.h>
16
17
void
ACarlaHUD::DrawHUD
()
18
{
19
Super::DrawHUD();
20
21
auto
Player = GetOwningPlayerController();
22
if
(Player ==
nullptr
)
23
{
24
UE_LOG(LogCarla, Error, TEXT(
"Can't find player controller!"
));
25
return
;
26
}
27
28
if
(
DebugVehicle
) {
29
float
YL = 1600.0f;
30
float
Y0 = 0.0f;
31
DrawDebug
(YL, Y0);
32
}
33
34
double
Now = FPlatformTime::Seconds();
35
int
i = 0;
36
while
(i <
StringList
.Num())
37
{
38
// project position from camera
39
FVector2D Screen;
40
if
(Player->ProjectWorldLocationToScreen(
StringList
[i].Location, Screen,
true
))
41
{
42
// draw text
43
DrawText(
StringList
[i].Str,
StringList
[i].Color, Screen.X, Screen.Y);
44
}
45
46
// check to remove the string
47
if
(Now >=
StringList
[i].TimeToDie)
48
{
49
StringList
.RemoveAt(i);
50
}
51
else
52
++i;
53
}
54
}
55
56
void
ACarlaHUD::AddHUDString
(
const
FString Str,
const
FVector
Location
,
const
FColor Color,
double
LifeTime)
57
{
58
double
Now = FPlatformTime::Seconds();
59
HUDString
Obj { Str,
Location
, Color, Now + LifeTime };
60
StringList
.Add(std::move(Obj));
61
}
62
63
// Debug
64
void
ACarlaHUD::DrawDebug
(
float
& YL,
float
& YPos)
65
{
66
using namespace
Chaos;
67
68
ensure(IsInGameThread());
69
70
if
(!
DebugVehicle
->HasValidPhysicsState()){
71
UE_LOG(LogCarla, Log, TEXT(
"Invalid state"
));
72
return
;
73
}
74
75
UFont* RenderFont = GEngine->GetMediumFont();
76
// draw drive data
77
{
78
Canvas->SetDrawColor(FColor::White);
79
80
YPos += 16;
81
for
(
int
i = 0; i <
DebugVehicle
->GetNumWheels(); i++)
82
{
83
YPos += Canvas->DrawText(RenderFont, FString::Printf(TEXT(
"WheelLoad: [%d] %1.f N"
), i, CmToM(
DebugVehicle
->GetWheelState(i).SpringForce)), 4, YPos);
84
}
85
86
YPos += 16;
87
for
(
int
i = 0; i <
DebugVehicle
->GetNumWheels(); i++)
88
{
89
if
(
DebugVehicle
->GetWheelState(i).PhysMaterial.IsValid())
90
{
91
YPos += Canvas->DrawText(RenderFont, FString::Printf(TEXT(
"SurfaceFriction: [%d] %.2f"
), i,
DebugVehicle
->GetWheelState(i).PhysMaterial->Friction), 4, YPos);
92
}
93
}
94
}
95
}
CarlaHUD.h
ACarlaHUD::DrawHUD
virtual void DrawHUD() override
Definition
CarlaHUD.cpp:17
ACarlaHUD::DrawDebug
void DrawDebug(float &YL, float &YPos)
Draw 2D debug text graphs on UI for the wheels, suspension and other systems.
Definition
CarlaHUD.cpp:64
ACarlaHUD::StringList
TArray< HUDString > StringList
Definition
CarlaHUD.h:76
ACarlaHUD::DebugVehicle
UChaosWheeledVehicleMovementComponent * DebugVehicle
Definition
CarlaHUD.h:61
ACarlaHUD::AddHUDString
void AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime)
Definition
CarlaHUD.cpp:56
HUDString
Definition
CarlaHUD.h:35
Location
Definition
geom/Location.h:23
Generated by
1.18.0