CARLA
载入中...
搜索中...
未找到
Unreal
CarlaUE4
Plugins
Carla
Source
Carla
MapGen
SoilTypeManager.cpp
浏览该文件的文档.
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
3
#include "
MapGen/SoilTypeManager.h
"
4
5
#include "Kismet/GameplayStatics.h"
6
7
// Sets default values
8
ASoilTypeManager::ASoilTypeManager
()
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
15
void
ASoilTypeManager::BeginPlay
()
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
47
FSoilTerramechanicsProperties
ASoilTypeManager::GetGeneralTerrainProperties
()
48
{
49
return
GeneralTerrainProperties
;
50
}
51
52
FSoilTerramechanicsProperties
ASoilTypeManager::GetTerrainPropertiesAtGlobalLocation
(FVector VehicleLocation)
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
64
FSoilTerramechanicsProperties
ASoilTypeManager::GetTerrainPropertiesAtLocalLocation
(FVector VehicleLocation)
65
{
66
FVector GlobalVehiclePosition =
LargeMapManager
->
LocalToGlobalLocation
(VehicleLocation);
67
return
GetTerrainPropertiesAtGlobalLocation
(GlobalVehiclePosition);
68
}
69
70
void
ASoilTypeManager::SetGeneralTerrainProperties
(
FSoilTerramechanicsProperties
TerrainProperties)
71
{
72
const
FString TerrainPropertiesStr = TerrainProperties.
ToString
();
73
UE_LOG(LogCarla, Log, TEXT(
"Setting General Terrain Settings %s"
), *TerrainPropertiesStr);
74
GeneralTerrainProperties
= TerrainProperties;
75
}
76
77
void
ASoilTypeManager::AddTerrainPropertiesToTile
(
int
TileX,
int
TileY,
FSoilTerramechanicsProperties
TerrainProperties)
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
)
86
TilesTerrainProperties
.Add(TileVectorID,
GeneralTerrainProperties
);
87
else
88
TilesTerrainProperties
.Add(TileVectorID, TerrainProperties);
89
}
90
91
void
ASoilTypeManager::ClearTerrainPropertiesMap
()
92
{
93
TilesTerrainProperties
.Empty(
TilesTerrainProperties
.Num());
94
}
SoilTypeManager.h
NONE_SOIL
@ NONE_SOIL
Definition
SoilTypeManager.h:13
AActor
ALargeMapManager
Definition
LargeMapManager.h:62
ALargeMapManager::GetTileVectorID
FIntVector GetTileVectorID(FVector TileLocation) const
Definition
LargeMapManager.cpp:528
ALargeMapManager::GetTileID
TileID GetTileID(FVector TileLocation) const
From a given location it retrieves the TileID that covers that area
Definition
LargeMapManager.cpp:588
ALargeMapManager::LocalToGlobalLocation
FVector LocalToGlobalLocation(const FVector &InLocation) const
Definition
LargeMapManager.cpp:337
ASoilTypeManager::TilesTerrainProperties
TMap< FIntVector, FSoilTerramechanicsProperties > TilesTerrainProperties
Definition
SoilTypeManager.h:51
ASoilTypeManager::GeneralTerrainProperties
FSoilTerramechanicsProperties GeneralTerrainProperties
Definition
SoilTypeManager.h:48
ASoilTypeManager::ClearTerrainPropertiesMap
void ClearTerrainPropertiesMap()
Definition
SoilTypeManager.cpp:91
ASoilTypeManager::CarClass
TSubclassOf< AActor > CarClass
Definition
SoilTypeManager.h:61
ASoilTypeManager::GetTerrainPropertiesAtGlobalLocation
FSoilTerramechanicsProperties GetTerrainPropertiesAtGlobalLocation(FVector VehicleLocation)
Definition
SoilTypeManager.cpp:52
ASoilTypeManager::BeginPlay
virtual void BeginPlay() override
Definition
SoilTypeManager.cpp:15
ASoilTypeManager::LargeMapManager
ALargeMapManager * LargeMapManager
Definition
SoilTypeManager.h:54
ASoilTypeManager::GetTerrainPropertiesAtLocalLocation
FSoilTerramechanicsProperties GetTerrainPropertiesAtLocalLocation(FVector VehicleLocation)
Definition
SoilTypeManager.cpp:64
ASoilTypeManager::AddTerrainPropertiesToTile
void AddTerrainPropertiesToTile(int TileX, int TileY, FSoilTerramechanicsProperties TerrainProperties)
Definition
SoilTypeManager.cpp:77
ASoilTypeManager::GetGeneralTerrainProperties
FSoilTerramechanicsProperties GetGeneralTerrainProperties()
Definition
SoilTypeManager.cpp:47
ASoilTypeManager::Tick
virtual void Tick(float DeltaSeconds) override
Definition
SoilTypeManager.cpp:21
ASoilTypeManager::ASoilTypeManager
ASoilTypeManager()
Definition
SoilTypeManager.cpp:8
ASoilTypeManager::SetGeneralTerrainProperties
void SetGeneralTerrainProperties(FSoilTerramechanicsProperties TerrainProperties)
Definition
SoilTypeManager.cpp:70
FSoilTerramechanicsProperties
Definition
SoilTypeManager.h:20
FSoilTerramechanicsProperties::TerrainType
TEnumAsByte< ESoilTerramechanicsType > TerrainType
Definition
SoilTypeManager.h:24
FSoilTerramechanicsProperties::ToString
const FString ToString() const
Definition
SoilTypeManager.h:26
制作者
1.10.0