CARLA
Loading...
Searching...
No Matches
SoilTypeManager.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB). This work is licensed under the terms of the MIT license. For a copy, see <https://opensource.org/licenses/MIT>.
2
4
5#include <util/ue-header-guard-begin.h>
6#include "Kismet/GameplayStatics.h"
7#include <util/ue-header-guard-end.h>
8
9// Sets default values
11{
12 // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
13 PrimaryActorTick.bCanEverTick = false;
14}
15
16// Called when the game starts or when spawned
18{
19 Super::BeginPlay();
20
21}
22
23void ASoilTypeManager::Tick(float DeltaTime)
24{
25 TRACE_CPUPROFILER_EVENT_SCOPE(ASoilTypeManager::Tick);
26 Super::Tick(DeltaTime);
27#if WITH_EDITOR // Only for debugging purposes. Requires to activate tick in contructor
28 if((int)DeltaTime % 2000 == 0)
29 {
30 ALargeMapManager* LMManager = (ALargeMapManager*) UGameplayStatics::GetActorOfClass(GetWorld(), ALargeMapManager::StaticClass());
31 AActor* Car = UGameplayStatics::GetActorOfClass(GetWorld(), CarClass);
32
33 if(Car != nullptr)
34 {
35 FVector CarPos = Car->GetActorLocation();
36
37 FVector GlobalCarPos = LMManager->LocalToGlobalLocation(CarPos);
38 FIntVector TileVector = LMManager->GetTileVectorID(GlobalCarPos);
39 uint64 TileIndex = LMManager->GetTileID(GlobalCarPos);
40
41 FString TypeStr = GetTerrainPropertiesAtGlobalLocation(GlobalCarPos).ToString();
42
43 UE_LOG(LogCarla, Log, TEXT("Current Tile Index %d ----> (%d, %d, %d) with position L[%f, %f, %f] G[%f, %f, %f] Terrain Type: %s"),
44 TileIndex, TileVector.X, TileVector.Y, TileVector.Z, CarPos.X, CarPos.Y, CarPos.Z, GlobalCarPos.X, GlobalCarPos.Y, GlobalCarPos.Z,
45 *TypeStr);
46 }
47 }
48#endif
49}
50
55
57{
58 // Get Indexes from location
59 FIntVector TileVectorID = LargeMapManager->GetTileVectorID(VehicleLocation);
60
61 // Query the map, if not in map, return general
62 if(TilesTerrainProperties.Contains(TileVectorID))
63 return TilesTerrainProperties[TileVectorID]; // Tile properties
64 else
65 return GeneralTerrainProperties; // General properties
66}
67
69{
70 FVector GlobalVehiclePosition = LargeMapManager->LocalToGlobalLocation(VehicleLocation);
71 return GetTerrainPropertiesAtGlobalLocation(GlobalVehiclePosition);
72}
73
75{
76 const FString TerrainPropertiesStr = TerrainProperties.ToString();
77 UE_LOG(LogCarla, Log, TEXT("Setting General Terrain Settings %s"), *TerrainPropertiesStr);
78 GeneralTerrainProperties = TerrainProperties;
79}
80
82{
83 // Compute ID from X,Y coords
84 check(LargeMapManager != nullptr)
85
86 FIntVector TileVectorID(TileX, TileY, 0);
87
88 // Add to map
89 if(TerrainProperties.TerrainType == ESoilTerramechanicsType::NONE_SOIL)
91 else
92 TilesTerrainProperties.Add(TileVectorID, TerrainProperties);
93}
94
@ NONE_SOIL
FIntVector GetTileVectorID(FVector TileLocation) const
TileID GetTileID(FVector TileLocation) const
From a given location it retrieves the TileID that covers that area.
FVector LocalToGlobalLocation(const FVector &InLocation) const
TMap< FIntVector, FSoilTerramechanicsProperties > TilesTerrainProperties
FSoilTerramechanicsProperties GeneralTerrainProperties
TSubclassOf< AActor > CarClass
FSoilTerramechanicsProperties GetTerrainPropertiesAtGlobalLocation(FVector VehicleLocation)
virtual void BeginPlay() override
ALargeMapManager * LargeMapManager
FSoilTerramechanicsProperties GetTerrainPropertiesAtLocalLocation(FVector VehicleLocation)
void AddTerrainPropertiesToTile(int TileX, int TileY, FSoilTerramechanicsProperties TerrainProperties)
FSoilTerramechanicsProperties GetGeneralTerrainProperties()
virtual void Tick(float DeltaSeconds) override
void SetGeneralTerrainProperties(FSoilTerramechanicsProperties TerrainProperties)
TEnumAsByte< ESoilTerramechanicsType > TerrainType
const FString ToString() const