CARLA
Loading...
Searching...
No Matches
Actor.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 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
8
9#include "carla/Logging.h"
11
12namespace carla {
13namespace client {
14
15 geom::Location Actor::GetLocation() const {
16 return GetEpisode().Lock()->GetActorLocation(*this);
17 }
18
19 geom::Transform Actor::GetTransform() const {
20 return GetEpisode().Lock()->GetActorTransform(*this);
21 }
22
23 geom::Vector3D Actor::GetVelocity() const {
24 return GetEpisode().Lock()->GetActorVelocity(*this);
25 }
26
27 geom::Vector3D Actor::GetAngularVelocity() const {
28 return GetEpisode().Lock()->GetActorAngularVelocity(*this);
29 }
30
31 geom::Vector3D Actor::GetAcceleration() const {
32 return GetEpisode().Lock()->GetActorAcceleration(*this);
33 }
34
35 geom::Transform Actor::GetComponentWorldTransform(const std::string &component_name) const {
36 return GetEpisode().Lock()->GetActorComponentWorldTransform(*this, component_name);
37 }
38
39 geom::Transform Actor::GetComponentRelativeTransform(const std::string &component_name) const {
40 return GetEpisode().Lock()->GetActorComponentRelativeTransform(*this, component_name);
41 }
42
43 std::vector<geom::Transform> Actor::GetBoneWorldTransforms() const {
44 return GetEpisode().Lock()->GetActorBoneWorldTransforms(*this);
45 }
46
47 std::vector<geom::Transform> Actor::GetBoneRelativeTransforms() const {
48 return GetEpisode().Lock()->GetActorBoneRelativeTransforms(*this);
49 }
50
51 std::vector<std::string> Actor::GetComponentNames() const {
52 return GetEpisode().Lock()->GetActorComponentNames(*this);
53 }
54
55 std::vector<std::string> Actor::GetBoneNames() const {
56 return GetEpisode().Lock()->GetActorBoneNames(*this);
57 }
58
59 std::vector<geom::Transform> Actor::GetSocketWorldTransforms() const {
60 return GetEpisode().Lock()->GetActorSocketWorldTransforms(*this);
61 }
62
63 std::vector<geom::Transform> Actor::GetSocketRelativeTransforms() const {
64 return GetEpisode().Lock()->GetActorSocketRelativeTransforms(*this);
65 }
66
67 std::vector<std::string> Actor::GetSocketNames() const {
68 return GetEpisode().Lock()->GetActorSocketNames(*this);
69 }
70
71 std::string Actor::GetActorName() const
72 {
73 return GetEpisode().Lock()->GetActorName(*this);
74 }
75
76 std::string Actor::GetActorClassName() const
77 {
78 return GetEpisode().Lock()->GetActorClassName(*this);
79 }
80
81 void Actor::SetLocation(const geom::Location &location) {
82 GetEpisode().Lock()->SetActorLocation(*this, location);
83 }
84
85 void Actor::SetTransform(const geom::Transform &transform) {
86 GetEpisode().Lock()->SetActorTransform(*this, transform);
87 }
88
89 void Actor::SetTargetVelocity(const geom::Vector3D &vector) {
90 GetEpisode().Lock()->SetActorTargetVelocity(*this, vector);
91 }
92
93 void Actor::SetTargetAngularVelocity(const geom::Vector3D &vector) {
94 GetEpisode().Lock()->SetActorTargetAngularVelocity(*this, vector);
95 }
96
97 void Actor::EnableConstantVelocity(const geom::Vector3D &vector) {
98 GetEpisode().Lock()->EnableActorConstantVelocity(*this, vector);
99 }
100
101 void Actor::DisableConstantVelocity() {
102 GetEpisode().Lock()->DisableActorConstantVelocity(*this);
103 }
104
105 void Actor::EnableConstantAcceleration(const geom::Vector3D &vector) {
106 GetEpisode().Lock()->EnableActorConstantAcceleration(*this, vector);
107 }
108
109 void Actor::DisableConstantAcceleration() {
110 GetEpisode().Lock()->DisableActorConstantAcceleration(*this);
111 }
112
113 void Actor::AddImpulse(const geom::Vector3D &impulse) {
114 GetEpisode().Lock()->AddActorImpulse(*this, impulse);
115 }
116
117 void Actor::AddImpulse(const geom::Vector3D &impulse, const geom::Vector3D &location) {
118 GetEpisode().Lock()->AddActorImpulse(*this, impulse, location);
119 }
120
121 void Actor::AddForce(const geom::Vector3D &force) {
122 GetEpisode().Lock()->AddActorForce(*this, force);
123 }
124
125 void Actor::AddForce(const geom::Vector3D &force, const geom::Vector3D &location) {
126 GetEpisode().Lock()->AddActorForce(*this, force, location);
127 }
128
129 void Actor::AddAngularImpulse(const geom::Vector3D &vector) {
130 GetEpisode().Lock()->AddActorAngularImpulse(*this, vector);
131 }
132
133 void Actor::AddTorque(const geom::Vector3D &torque) {
134 GetEpisode().Lock()->AddActorTorque(*this, torque);
135 }
136
137 void Actor::SetSimulatePhysics(const bool enabled) {
138 GetEpisode().Lock()->SetActorSimulatePhysics(*this, enabled);
139 }
140
141 void Actor::SetCollisions(const bool enabled) {
142 GetEpisode().Lock()->SetActorCollisions(*this, enabled);
143 }
144
145 void Actor::SetActorDead() {
146 GetEpisode().Lock()->SetActorDead(*this);
147 }
148
149 void Actor::SetEnableGravity(const bool enabled) {
150 GetEpisode().Lock()->SetActorEnableGravity(*this, enabled);
151 }
152
153 void Actor::ApplyTexture(
154 const rpc::MaterialParameter& MaterialParameter,
155 const rpc::TextureColor& Texture)
156 {
157 GetEpisode().Lock()->ApplyTextureToActor(*this, MaterialParameter, Texture);
158 }
159
160 void Actor::ApplyTexture(
161 const rpc::MaterialParameter& MaterialParameter,
162 const rpc::TextureFloatColor& Texture)
163 {
164 GetEpisode().Lock()->ApplyTextureToActor(*this, MaterialParameter, Texture);
165 }
166
167 rpc::ActorState Actor::GetActorState() const {
168 return GetEpisode().Lock()->GetActorState(*this);
169 }
170
171 bool Actor::Destroy() {
172 // The actor state known to the client comes from the last world snapshot
173 // received, which cannot list an actor spawned after it was taken (until
174 // the next frame in asynchronous mode, until the next tick in synchronous
175 // mode). A missing entry is therefore indistinguishable from a dead actor
176 // here, so the server decides: it rejects unknown ids with "unable to
177 // destroy actor: not found" and this returns false.
178 //
179 // A handle whose own Destroy() already succeeded has had its episode
180 // cleared (Simulator::DestroyActor); asking the server again is pointless
181 // and Lock() would throw, so a repeated Destroy() is simply false.
182 auto episode = GetEpisode().TryLock();
183 if (episode == nullptr) {
184 log_debug(GetDisplayId(), "already destroyed through this handle.");
185 return false;
186 }
187 return episode->DestroyActor(*this);
188 }
189
190} // namespace client
191} // namespace carla
const std::string & GetDisplayId() const
SharedPtrType TryLock() const noexcept
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
Texture< sensor::data::Color > TextureColor
Definition Texture.h:66
Texture< FloatColor > TextureFloatColor
Definition Texture.h:67
This file contains definitions of common data structures used in traffic manager.