CARLA
 
载入中...
搜索中...
未找到
ActorAttacher.cpp
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "Carla.h"
9
10#include "GameFramework/SpringArmComponent.h"
11
13 AActor *Child,
14 AActor *Parent)
15{
16 auto SpringArm = NewObject<USpringArmComponent>(Parent);
17
18 // Child location negated to compensate for the spring arm rotation (rotated
19 // from the "other end" of the arm).
20 const auto ChildLocation = -Child->GetActorLocation();
21 Child->SetActorLocation(FVector::ZeroVector);
22
23 // Adding Z-offset to avoid colliding against the ground on bumpy terrain.
24 SpringArm->TargetOffset = FVector(0.0f, 0.0f, 30.0f);
25 SpringArm->bDoCollisionTest = true;
26
27 FRotator LookAt = FRotationMatrix::MakeFromX(ChildLocation).Rotator();
28 SpringArm->SetRelativeRotation(LookAt);
29 SpringArm->SetupAttachment(Parent->GetRootComponent());
30
31 SpringArm->TargetArmLength = ChildLocation.Size();
32 SpringArm->bEnableCameraRotationLag = true;
33 SpringArm->CameraRotationLagSpeed = 8.0f;
34
35 SpringArm->bInheritPitch = false;
36 SpringArm->bInheritRoll = false;
37 SpringArm->bInheritYaw = true;
38
39 SpringArm->AttachToComponent(
40 Parent->GetRootComponent(),
41 FAttachmentTransformRules::KeepRelativeTransform);
42 SpringArm->RegisterComponent();
43
44 auto ChildComp = NewObject<UChildActorComponent>(Parent);
45 ChildComp->SetupAttachment(
47 USpringArmComponent::SocketName);
48 Child->AttachToComponent(
49 ChildComp,
50 FAttachmentTransformRules::KeepRelativeTransform);
51 ChildComp->RegisterComponent();
52}
53
55 AActor *Child,
56 AActor *Parent)
57{
58 auto SpringArm = NewObject<USpringArmComponent>(Parent);
59
60 // Child location negated to compensate for the spring arm rotation (rotated
61 // from the "other end" of the arm).
62 const auto ChildLocation = -Child->GetActorLocation();
63 Child->SetActorLocation(FVector::ZeroVector);
64
65 // Adding Z-offset to avoid colliding against the ground on bumpy terrain.
66 SpringArm->TargetOffset = FVector(0.0f, 0.0f, 0.0f);
67 SpringArm->bDoCollisionTest = false;
68
69 FRotator LookAt = FRotationMatrix::MakeFromX(ChildLocation).Rotator();
70 SpringArm->SetRelativeRotation(LookAt);
71 SpringArm->SetupAttachment(Parent->GetRootComponent());
72
73 SpringArm->TargetArmLength = ChildLocation.Size();
74 SpringArm->bEnableCameraRotationLag = true;
75 SpringArm->CameraRotationLagSpeed = 8.0f;
76
77 SpringArm->bInheritPitch = false;
78 SpringArm->bInheritRoll = false;
79 SpringArm->bInheritYaw = true;
80
81 SpringArm->AttachToComponent(
82 Parent->GetRootComponent(),
83 FAttachmentTransformRules::KeepRelativeTransform);
84 SpringArm->RegisterComponent();
85
86 auto ChildComp = NewObject<UChildActorComponent>(Parent);
87 ChildComp->SetupAttachment(
89 USpringArmComponent::SocketName);
90 Child->AttachToComponent(
91 ChildComp,
92 FAttachmentTransformRules::KeepRelativeTransform);
93 ChildComp->RegisterComponent();
94}
95
97 AActor *Child,
98 AActor *Parent,
99 const EAttachmentType AttachmentType,
100 const FString& SocketName)
101{
102 // 根据AttachmentType的值,选择不同的方式将Child对象附加到Parent对象上
103 switch (AttachmentType)
104 {
105 // FName(*SocketName)是一个名称,用于指定Parent上的一个附着点
107 Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform, FName(*SocketName));
108 break;
109 // 这个函数可能是用来以弹簧臂的方式将Child附加到Parent上,弹簧臂通常用于相机,以提供一个动态且平滑的视角
112 break;
113 // 这个函数的行为可能与SpringArm类似,但可能有一些特殊的用途或行为,例如在不渲染弹簧臂本身的情况下提供视角
116 break;
117 // Fatal表示这是一个严重的错误,可能会导致程序崩溃
118 default:
119 UE_LOG(LogCarla, Fatal, TEXT("Invalid attachment type"));
120 }
121
122 Child->SetOwner(Parent);
123}
static void UActorAttacher_AttachActorsWithSpringArmGhost(AActor *Child, AActor *Parent)
static void UActorAttacher_AttachActorsWithSpringArm(AActor *Child, AActor *Parent)
EAttachmentType
UE_LOG(LogCarla, Log, TEXT("UActorDispatcher::Destroying actor: '%s' %x"), *Id, Actor)
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType, const FString &SocketName="")