CARLA
SoilTypeManager.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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 "Kismet/GameplayStatics.h"
6 
7 // Sets default values
9 {
10  // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
11  PrimaryActorTick.bCanEverTick = false;
12 }
13 
14 // Called when the game starts or when spawned
16 {
17  Super::BeginPlay();
18 
19 }
20 
21 void ASoilTypeManager::Tick(float DeltaTime)
22 {
23 #if WITH_EDITOR // Only for debugging purposes. Requires to activate tick in contructor
24  if((int)DeltaTime % 2000 == 0)
25  {
26  ALargeMapManager* LargeMapManager = (ALargeMapManager*) UGameplayStatics::GetActorOfClass(GetWorld(), ALargeMapManager::StaticClass());
27  AActor* Car = UGameplayStatics::GetActorOfClass(GetWorld(), CarClass);
28 
29  if(Car != nullptr)
30  {
31  FVector CarPos = Car->GetActorLocation();
32 
33  FVector GlobalCarPos = LargeMapManager->LocalToGlobalLocation(CarPos);
34  FIntVector TileVector = LargeMapManager->GetTileVectorID(GlobalCarPos);
35  uint64 TileIndex = LargeMapManager->GetTileID(GlobalCarPos);
36 
37  FString TypeStr = GetTerrainPropertiesAtGlobalLocation(GlobalCarPos).ToString();
38 
39  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"),
40  TileIndex, TileVector.X, TileVector.Y, TileVector.Z, CarPos.X, CarPos.Y, CarPos.Z, GlobalCarPos.X, GlobalCarPos.Y, GlobalCarPos.Z,
41  *TypeStr);
42  }
43  }
44 #endif
45 }
46 
48 {
50 }
51 
53 {
54  // Get Indexes from location
55  FIntVector TileVectorID = LargeMapManager->GetTileVectorID(VehicleLocation);
56 
57  // Query the map, if not in map, return general
58  if(TilesTerrainProperties.Contains(TileVectorID))
59  return TilesTerrainProperties[TileVectorID]; // Tile properties
60  else
61  return GeneralTerrainProperties; // General properties
62 }
63 
65 {
66  FVector GlobalVehiclePosition = LargeMapManager->LocalToGlobalLocation(VehicleLocation);
67  return GetTerrainPropertiesAtGlobalLocation(GlobalVehiclePosition);
68 }
69 
71 {
72  const FString TerrainPropertiesStr = TerrainProperties.ToString();
73  UE_LOG(LogCarla, Log, TEXT("Setting General Terrain Settings %s"), *TerrainPropertiesStr);
74  GeneralTerrainProperties = TerrainProperties;
75 }
76 
78 {
79  // Compute ID from X,Y coords
80  check(LargeMapManager != nullptr)
81 
82  FIntVector TileVectorID(TileX, TileY, 0);
83 
84  // Add to map
85  if(TerrainProperties.TerrainType == ESoilTerramechanicsType::NONE_SOIL)
87  else
88  TilesTerrainProperties.Add(TileVectorID, TerrainProperties);
89 }
90 
92 {
94 }
TileID GetTileID(FVector TileLocation) const
From a given location it retrieves the TileID that covers that area.
TSubclassOf< AActor > CarClass
void AddTerrainPropertiesToTile(int TileX, int TileY, FSoilTerramechanicsProperties TerrainProperties)
TMap< FIntVector, FSoilTerramechanicsProperties > TilesTerrainProperties
FSoilTerramechanicsProperties GetTerrainPropertiesAtGlobalLocation(FVector VehicleLocation)
TEnumAsByte< ESoilTerramechanicsType > TerrainType
void SetGeneralTerrainProperties(FSoilTerramechanicsProperties TerrainProperties)
void ClearTerrainPropertiesMap()
ALargeMapManager * LargeMapManager
const FString ToString() const
virtual void Tick(float DeltaSeconds) override
FSoilTerramechanicsProperties GeneralTerrainProperties
FSoilTerramechanicsProperties GetTerrainPropertiesAtLocalLocation(FVector VehicleLocation)
FSoilTerramechanicsProperties GetGeneralTerrainProperties()
FVector LocalToGlobalLocation(const FVector &InLocation) const
FIntVector GetTileVectorID(FVector TileLocation) const
virtual void BeginPlay() override