diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3971470bd..0475512ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
* make PythonAPI Windows: Fixed incompatibility issue with Anaconda due `py` command.
* Added function to get actor' sockets names
* Fixed bug in python agents when vehicle list was empty causing a check on all vehicles (BasicAgent.py) and detected pedestrians as vehicles if no pedestrains are present (BehaviourAgent.py)
+ * Extended debug drawing functions to allow drawing primitives on HUD layer
* Added possibility to change gravity variable in imui sensor for the accelerometer
* Fixed ROS2 native extension build error when ROS2 is installed in the system.
* ROS2Native: Force fast-dds dependencies download to avoid build crash when boost_asio and tinyxml2 are not installed in Linux.
diff --git a/Docs/python_api.md b/Docs/python_api.md
index 617d8518e..88c0ae748 100644
--- a/Docs/python_api.md
+++ b/Docs/python_api.md
@@ -722,13 +722,45 @@ Draws an arrow from `begin` to `end` pointing in that direction.
- `color` (_[carla.Color](#carla.Color)_) - RGB code to color the object. Red by default.
- `life_time` (_float - seconds_) - Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
- **draw_box**(**self**, **box**, **rotation**, **thickness**=0.1, **color**=(255,0,0), **life_time**=-1.0)
-Draws a box, ussually to act for object colliders.
+Draws a box, usually to act for object colliders.
- **Parameters:**
- `box` (_[carla.BoundingBox](#carla.BoundingBox)_) - Object containing a location and the length of a box for every axis.
- `rotation` (_[carla.Rotation](#carla.Rotation) - degrees (pitch,yaw,roll)_) - Orientation of the box according to Unreal Engine's axis system.
- `thickness` (_float - meters_) - Density of the lines that define the box.
- `color` (_[carla.Color](#carla.Color)_) - RGB code to color the object. Red by default.
- `life_time` (_float - seconds_) - Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+- **draw_hud_arrow**(**self**, **begin**, **end**, **thickness**=0.1, **arrow_size**=0.1, **color**=(255,0,0), **life_time**=-1.0)
+Draws an arrow on the HUD from `begin` to `end` which can only be seen server-side.
+ - **Parameters:**
+ - `begin` (_[carla.Location](#carla.Location) - meters_) - Point in the coordinate system where the arrow starts.
+ - `end` (_[carla.Location](#carla.Location) - meters_) - Point in the coordinate system where the arrow ends and points towards to.
+ - `thickness` (_float - meters_) - Density of the line.
+ - `arrow_size` (_float - meters_) - Size of the tip of the arrow.
+ - `color` (_[carla.Color](#carla.Color)_) - RGB code to color the object. Red by default.
+ - `life_time` (_float - seconds_) - Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+- **draw_hud_box**(**self**, **box**, **rotation**, **thickness**=0.1, **color**=(255,0,0), **life_time**=-1.0)
+Draws a box on the HUD, usually to act for object colliders. The box can only be seen server-side.
+ - **Parameters:**
+ - `box` (_[carla.BoundingBox](#carla.BoundingBox)_) - Object containing a location and the length of a box for every axis.
+ - `rotation` (_[carla.Rotation](#carla.Rotation) - degrees (pitch,yaw,roll)_) - Orientation of the box according to Unreal Engine's axis system.
+ - `thickness` (_float - meters_) - Density of the lines that define the box.
+ - `color` (_[carla.Color](#carla.Color)_) - RGB code to color the object. Red by default.
+ - `life_time` (_float - seconds_) - Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+- **draw_hud_line**(**self**, **begin**, **end**, **thickness**=0.1, **color**=(255,0,0), **life_time**=-1.0)
+Draws a line on the HUD in between `begin` and `end`. The line can only be seen server-side.
+ - **Parameters:**
+ - `begin` (_[carla.Location](#carla.Location) - meters_) - Point in the coordinate system where the line starts.
+ - `end` (_[carla.Location](#carla.Location) - meters_) - Spot in the coordinate system where the line ends.
+ - `thickness` (_float - meters_) - Density of the line.
+ - `color` (_[carla.Color](#carla.Color)_) - RGB code to color the object. Red by default.
+ - `life_time` (_float - seconds_) - Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+- **draw_hud_point**(**self**, **location**, **size**=0.1, **color**=(255,0,0), **life_time**=-1.0)
+Draws a point on the HUD at `location`. The point can only be seen server-side.
+ - **Parameters:**
+ - `location` (_[carla.Location](#carla.Location) - meters_) - Spot in the coordinate system to center the object.
+ - `size` (_float - meters_) - Density of the point.
+ - `color` (_[carla.Color](#carla.Color)_) - RGB code to color the object. Red by default.
+ - `life_time` (_float - seconds_) - Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
- **draw_line**(**self**, **begin**, **end**, **thickness**=0.1, **color**=(255,0,0), **life_time**=-1.0)
Draws a line in between `begin` and `end`.
- **Parameters:**
@@ -4194,71 +4226,6 @@ document.getElementById("snipets-container").innerHTML = null;
}
-
-Snippet for carla.World.unload_map_layer -
--Snippet for carla.DebugHelper.draw_string -
-Snippet for carla.ActorBlueprint.set_attribute @@ -4293,247 +4260,6 @@ camera_bp.set_attribute('image_size_y', 600)
-Snippet for carla.World.get_spectator -
--Snippet for carla.Sensor.listen -
--Snippet for carla.World.load_map_layer -
--Snippet for carla.Map.get_waypoint -
--Snippet for carla.TrafficLight.set_state -
--Snippet for carla.Vehicle.set_wheel_steer_direction -
--Snippet for carla.DebugHelper.draw_box -
--Snippet for carla.WalkerAIController.stop -
-Snippet for carla.Client.apply_batch_sync @@ -4607,36 +4333,6 @@ for i in range(0, len(all_actors), 2):
-Snippet for carla.World.enable_environment_objects -
-Snippet for carla.Client.__init__ @@ -4682,6 +4378,316 @@ Snippet for carla.Client.__init__
+Snippet for carla.DebugHelper.draw_box +
++Snippet for carla.DebugHelper.draw_string +
++Snippet for carla.Map.get_waypoint +
++Snippet for carla.Sensor.listen +
++Snippet for carla.TrafficLight.set_state +
++Snippet for carla.Vehicle.set_wheel_steer_direction +
++Snippet for carla.WalkerAIController.stop +
++Snippet for carla.World.enable_environment_objects +
++Snippet for carla.World.get_spectator +
++Snippet for carla.World.load_map_layer +
+Snippet for carla.World.spawn_actor @@ -4707,6 +4713,32 @@ lane_invasion_sensor = world.spawn_actor(sensor_lane_invasion_bp, transform, att
+Snippet for carla.World.unload_map_layer +
+0
for permanent shapes.
doc: >
- Draws a box, ussually to act for object colliders.
-
+ Draws a box, usually to act for object colliders.
+
+ # --------------------------------------
+ - def_name: draw_hud_arrow
+ params:
+ - param_name: begin
+ type: carla.Location
+ param_units: meters
+ doc: >
+ Point in the coordinate system where the arrow starts.
+ - param_name: end
+ type: carla.Location
+ param_units: meters
+ doc: >
+ Point in the coordinate system where the arrow ends and points towards to.
+ - param_name: thickness
+ type: float
+ default: 0.1
+ param_units: meters
+ doc: >
+ Density of the line.
+ - param_name: arrow_size
+ type: float
+ default: 0.1
+ param_units: meters
+ doc: >
+ Size of the tip of the arrow.
+ - param_name: color
+ type: carla.Color
+ default: (255,0,0)
+ doc: >
+ RGB code to color the object. Red by default.
+ - param_name: life_time
+ type: float
+ default: -1.0
+ param_units: seconds
+ doc: >
+ Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+ doc: >
+ Draws an arrow on the HUD from `begin` to `end` which can only be seen server-side.
+
+ # --------------------------------------
+ - def_name: draw_hud_box
+ params:
+ - param_name: box
+ type: carla.BoundingBox
+ doc: >
+ Object containing a location and the length of a box for every axis.
+ - param_name: rotation
+ type: carla.Rotation
+ param_units: degrees (pitch,yaw,roll)
+ doc: >
+ Orientation of the box according to Unreal Engine's axis system.
+ - param_name: thickness
+ type: float
+ default: 0.1
+ param_units: meters
+ doc: >
+ Density of the lines that define the box.
+ - param_name: color
+ type: carla.Color
+ default: (255,0,0)
+ doc: >
+ RGB code to color the object. Red by default.
+ - param_name: life_time
+ type: float
+ default: -1.0
+ param_units: seconds
+ doc: >
+ Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+ doc: >
+ Draws a box on the HUD, usually to act for object colliders. The box can only be seen server-side.
+
+ # --------------------------------------
+ - def_name: draw_hud_line
+ params:
+ - param_name: begin
+ type: carla.Location
+ param_units: meters
+ doc: >
+ Point in the coordinate system where the line starts.
+ - param_name: end
+ type: carla.Location
+ param_units: meters
+ doc: >
+ Spot in the coordinate system where the line ends.
+ - param_name: thickness
+ type: float
+ default: 0.1
+ param_units: meters
+ doc: >
+ Density of the line.
+ - param_name: color
+ type: carla.Color
+ default: (255,0,0)
+ doc: >
+ RGB code to color the object. Red by default.
+ - param_name: life_time
+ type: float
+ default: -1.0
+ param_units: seconds
+ doc: >
+ Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+ doc: >
+ Draws a line on the HUD in between `begin` and `end`. The line can only be seen server-side.
+
+ # --------------------------------------
+ - def_name: draw_hud_point
+ params:
+ - param_name: location
+ type: carla.Location
+ param_units: meters
+ doc: >
+ Spot in the coordinate system to center the object.
+ - param_name: size
+ type: float
+ default: 0.1
+ param_units: meters
+ doc: >
+ Density of the point.
+ - param_name: color
+ type: carla.Color
+ default: (255,0,0)
+ doc: >
+ RGB code to color the object. Red by default.
+ - param_name: life_time
+ type: float
+ default: -1.0
+ param_units: seconds
+ doc: >
+ Shape's lifespan. By default it only lasts one frame. Set this to 0
for permanent shapes.
+ doc: >
+ Draws a point on the HUD at `location`. The point can only be seen server-side.
+
# --------------------------------------
- def_name: draw_line
params:
diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.cpp
index a6b04c072..c1f041f67 100644
--- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.cpp
+++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.cpp
@@ -33,7 +33,6 @@ void ACarlaHUD::DrawHUD()
FVector2D Screen;
if (Player->ProjectWorldLocationToScreen(StringList[i].Location, Screen, true))
{
- // draw text
DrawText(StringList[i].Str, StringList[i].Color, Screen.X, Screen.Y);
}
@@ -45,6 +44,25 @@ void ACarlaHUD::DrawHUD()
else
++i;
}
+
+ while (i < LineList.Num())
+ {
+ // project position from camera
+ FVector2D Begin, End;
+ if (Player->ProjectWorldLocationToScreen(LineList[i].Begin, Begin, true) &&
+ Player->ProjectWorldLocationToScreen(LineList[i].End, End, true))
+ {
+ DrawLine(Begin.X, Begin.Y, End.X, End.Y, LineList[i].Color, LineList[i].Thickness);
+ }
+
+ // check to remove the string
+ if (Now >= LineList[i].TimeToDie)
+ {
+ LineList.RemoveAt(i);
+ }
+ else
+ ++i;
+ }
}
void ACarlaHUD::AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime)
@@ -53,3 +71,10 @@ void ACarlaHUD::AddHUDString(const FString Str, const FVector Location, const FC
HUDString Obj { Str, Location, Color, Now + LifeTime };
StringList.Add(std::move(Obj));
}
+
+void ACarlaHUD::AddHUDLine(const FVector Begin, const FVector End, const float Thickness, const FColor Color, double LifeTime)
+{
+ double Now = FPlatformTime::Seconds();
+ HUDLine Obj { Begin, End, Thickness, Color, Now + LifeTime };
+ LineList.Add(std::move(Obj));
+}
diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.h
index 79a3edc70..c76b5bc0e 100644
--- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.h
+++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaHUD.h
@@ -35,6 +35,15 @@ struct HUDString
double TimeToDie;
};
+struct HUDLine
+{
+ FVector Begin;
+ FVector End;
+ float Thickness;
+ FColor Color;
+ double TimeToDie;
+};
+
/// Class to draw on HUD
UCLASS()
class CARLA_API ACarlaHUD : public AHUD
@@ -55,7 +64,9 @@ public:
void AddDebugVehicleForTelemetry(UWheeledVehicleMovementComponent* Veh) { DebugVehicle = Veh; }
void AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime);
+ void AddHUDLine(const FVector Begin, const FVector End, const float Thickness, const FColor Color, double LifeTime);
private:
TArray