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,
58 {
59  check(Child != nullptr);
60  check(Parent != nullptr);
61 
62  switch (AttachmentType)
63  {
65  Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform);
66  break;
69  break;
70  default:
71  UE_LOG(LogCarla, Fatal, TEXT("Invalid attachment type"));
72  }
73 
74  Child->SetOwner(Parent);
75 }
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType)
EAttachmentType
Definition: ActorAttacher.h:20
static void UActorAttacher_AttachActorsWithSpringArm(AActor *Child, AActor *Parent)