CARLA
 
载入中...
搜索中...
未找到
CarSimManagerComponent.h
浏览该文件的文档.
1// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3// Copyright (c) 2019 Intel Corporation
4//
5// This work is licensed under the terms of the MIT license.
6// For a copy, see <https://opensource.org/licenses/MIT>.
7
8#pragma once
9
10// 引入必要的头文件
11#include "BaseCarlaMovementComponent.h" // 基础移动组件的定义
12#include "Carla/Vehicle/VehicleControl.h" // 车辆控制相关定义
13
14#ifdef WITH_CARSIM
15#include "CarSimMovementComponent.h" // 只有启用 CarSim 时才包含的头文件
16#endif
17
18#include "CarSimManagerComponent.generated.h"
19
20// 前向声明 ACarlaWheeledVehicle 类
22
23// UCarSimManagerComponent 类声明
24// 该类继承自 UBaseCarlaMovementComponent,表示 CarSim 管理组件
25UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
27{
28 GENERATED_BODY()
29
30 #ifdef WITH_CARSIM
31 AActor* OffsetActor; // 用于存储偏移实体
32 UCarSimMovementComponent* CarSimMovementComponent; // CarSim 的移动组件指针
33 #endif
34
35public:
36
37 // 静态方法,用于为指定车辆创建 CarSim 组件
38 static void CreateCarsimComponent(
39 ACarlaWheeledVehicle* Vehicle, FString Simfile);
40
41 FString SimfilePath = ""; // 存储 Simfile 的路径
42
43 // 在游戏开始时调用
44 virtual void BeginPlay() override;
45
46 // 每帧调用,用于更新组件状态
47 virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
48
49 // 处理车辆控制输入
50 void ProcessControl(FVehicleControl &Control) override;
51
52 // 获取当前速度
53 FVector GetVelocity() const override;
54
55 // 在游戏结束时调用
56 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
57
58 // 开启或关闭 CarSim 道路模式
59 void UseCarSimRoad(bool bEnabled);
60
61 // 获取当前车辆的挡位
62 int32 GetVehicleCurrentGear() const override;
63
64 // 获取车辆当前的前向速度
65 float GetVehicleForwardSpeed() const override;
66
67 // 禁用 CarSim 物理模拟
68 void DisableCarSimPhysics();
69
70 // 禁用特殊物理模拟(覆盖基类方法)
71 virtual void DisableSpecialPhysics() override;
72
73private:
74
75 // 当车辆与其他物体发生碰撞时调用,仅在启用 CarSim 时生效
76 UFUNCTION()
77 void OnCarSimHit(AActor* Actor,
78 AActor* OtherActor,
79 FVector NormalImpulse,
80 const FHitResult& Hit);
81
82 // 当车辆与静态环境发生重叠时调用,仅在启用 CarSim 时生效
83 UFUNCTION()
84 void OnCarSimOverlap(UPrimitiveComponent* OverlappedComponent,
85 AActor* OtherActor,
86 UPrimitiveComponent* OtherComp,
87 int32 OtherBodyIndex,
88 bool bFromSweep,
89 const FHitResult& SweepResult);
90
91 // 当车辆与静态环境的重叠结束时调用,仅在启用 CarSim 时生效
92 UFUNCTION()
93 void OnCarSimEndOverlap(UPrimitiveComponent* OverlappedComponent,
94 AActor* OtherActor,
95 UPrimitiveComponent* OtherComp,
96 int32 OtherBodyIndex);
97};
FVehicleControl Control
Definition ActorData.h:119
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld Actor
Base class for CARLA wheeled vehicles.
virtual void BeginPlay() override
int32 GetVehicleCurrentGear() const
Active gear of the vehicle.
float GetVehicleForwardSpeed() const
Forward speed in cm/s. Might be negative if goes backwards.
virtual FVector GetVelocity() const override
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason)