CARLA
ActorAttacher.cpp
Go to the documentation of this file.
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(
46  SpringArm,
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(
88  SpringArm,
89  USpringArmComponent::SocketName);
90  Child->AttachToComponent(
91  ChildComp,
92  FAttachmentTransformRules::KeepRelativeTransform);
93  ChildComp->RegisterComponent();
94 }
95 
97  AActor *Child,
98  AActor *Parent,
100 {
101  check(Child != nullptr);
102  check(Parent != nullptr);
103 
104  switch (AttachmentType)
105  {
107  Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform);
108  break;
111  break;
114  break;
115  default:
116  UE_LOG(LogCarla, Fatal, TEXT("Invalid attachment type"));
117  }
118 
119  Child->SetOwner(Parent);
120 }
static void UActorAttacher_AttachActorsWithSpringArmGhost(AActor *Child, AActor *Parent)
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType)
EAttachmentType
Definition: ActorAttacher.h:20
static void UActorAttacher_AttachActorsWithSpringArm(AActor *Child, AActor *Parent)