CARLA
client/Actor.h
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 #pragma once
8 
9 #include "carla/Debug.h"
10 #include "carla/Memory.h"
13 
14 namespace carla {
15 namespace client {
16 
17  /// Represents an actor in the simulation.
18  class Actor
19  : public EnableSharedFromThis<Actor>,
21  public detail::ActorState {
23  public:
24 
25  explicit Actor(ActorInitializer init)
27  Super(std::move(init)) {}
28 
29  using ActorState::GetBoundingBox;
30 
31  virtual ~Actor() = default;
32 
33  /// Return the current location of the actor.
34  ///
35  /// @note This function does not call the simulator, it returns the location
36  /// received in the last tick.
38 
39  /// Return the current transform of the actor.
40  ///
41  /// @note This function does not call the simulator, it returns the
42  /// transform received in the last tick.
44 
45  /// Return the current 3D velocity of the actor.
46  ///
47  /// @note This function does not call the simulator, it returns the
48  /// velocity received in the last tick.
50 
51  /// Return the current 3D angular velocity of the actor.
52  ///
53  /// @note This function does not call the simulator, it returns the
54  /// angular velocity received in the last tick.
56 
57  /// Return the current 3D acceleration of the actor.
58  ///
59  /// @note This function does not call the simulator, it returns the
60  /// acceleration calculated after the actor's velocity.
62 
63  /// Teleport the actor to @a location.
64  void SetLocation(const geom::Location &location);
65 
66  /// Teleport and rotate the actor to @a transform.
67  void SetTransform(const geom::Transform &transform);
68 
69  /// Set the actor velocity before applying physics.
70  void SetTargetVelocity(const geom::Vector3D &vector);
71 
72  /// Set the angular velocity of the actor before applying physics.
73  void SetTargetAngularVelocity(const geom::Vector3D &vector);
74 
75  /// Enable a constant velocity mode
76  void EnableConstantVelocity(const geom::Vector3D &vector);
77 
78  /// Disable the constant velocity mode
80 
81  /// Add impulse to the actor at its center of mass.
82  void AddImpulse(const geom::Vector3D &vector);
83 
84  /// Add impulse to the actor at certain location.
85  void AddImpulse(const geom::Vector3D &impulse, const geom::Vector3D &location);
86 
87  /// Add force to the actor at its center of mass.
88  void AddForce(const geom::Vector3D &force);
89 
90  /// Add force to the actor at certain location.
91  void AddForce(const geom::Vector3D &force, const geom::Vector3D &location);
92 
93  /// Add angular impulse to the actor.
94  void AddAngularImpulse(const geom::Vector3D &vector);
95 
96  /// Add a torque to the actor.
97  void AddTorque(const geom::Vector3D &vector);
98 
99  /// Enable or disable physics simulation on this actor.
100  void SetSimulatePhysics(bool enabled = true);
101 
102  /// Enable or disable collisions on this actor.
103  void SetCollisions(bool enabled = true);
104 
105  /// Set actor as dead and starts his life span
106  void SetActorDead();
107 
108  /// Enable or disable gravity on this actor.
109  void SetEnableGravity(bool enabled = true);
110 
112 
113  bool IsAlive() const {
115  }
116 
117  bool IsDormant() const {
119  }
120 
121  bool IsActive() const {
123  }
124 
125  /// Tell the simulator to destroy this Actor, and return whether the actor
126  /// was successfully destroyed.
127  ///
128  /// @note It has no effect if the Actor was already successfully destroyed.
129  ///
130  /// @warning This function blocks until the destruction operation is
131  /// completed by the simulator.
132  virtual bool Destroy();
133 
134  const auto &Serialize() const {
135  return Super::GetActorDescription();
136  }
137 
138  };
139 
140 } // namespace client
141 } // namespace carla
void SetSimulatePhysics(bool enabled=true)
Enable or disable physics simulation on this actor.
Definition: Actor.cpp:83
void SetActorDead()
Set actor as dead and starts his life span.
Definition: Actor.cpp:91
rpc::ActorState GetActorState() const
Definition: Actor.cpp:99
geom::Vector3D GetAcceleration() const
Return the current 3D acceleration of the actor.
Definition: Actor.cpp:31
bool IsDormant() const
Definition: client/Actor.h:117
void SetCollisions(bool enabled=true)
Enable or disable collisions on this actor.
Definition: Actor.cpp:87
const auto & Serialize() const
Definition: client/Actor.h:134
void AddForce(const geom::Vector3D &force)
Add force to the actor at its center of mass.
Definition: Actor.cpp:67
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void SetTransform(const geom::Transform &transform)
Teleport and rotate the actor to transform.
Definition: Actor.cpp:39
void AddAngularImpulse(const geom::Vector3D &vector)
Add angular impulse to the actor.
Definition: Actor.cpp:75
const std::string & GetDisplayId() const
void AddImpulse(const geom::Vector3D &vector)
Add impulse to the actor at its center of mass.
Definition: Actor.cpp:59
virtual ~Actor()=default
Used to initialize Actor classes.
#define LIBCARLA_INITIALIZE_LIFETIME_PROFILER(display_name)
virtual bool Destroy()
Tell the simulator to destroy this Actor, and return whether the actor was successfully destroyed...
Definition: Actor.cpp:103
bool IsActive() const
Definition: client/Actor.h:121
geom::Vector3D GetAngularVelocity() const
Return the current 3D angular velocity of the actor.
Definition: Actor.cpp:27
geom::Transform GetTransform() const
Return the current transform of the actor.
Definition: Actor.cpp:19
void SetTargetAngularVelocity(const geom::Vector3D &vector)
Set the angular velocity of the actor before applying physics.
Definition: Actor.cpp:47
geom::Location GetLocation() const
Return the current location of the actor.
Definition: Actor.cpp:15
void SetLocation(const geom::Location &location)
Teleport the actor to location.
Definition: Actor.cpp:35
void SetTargetVelocity(const geom::Vector3D &vector)
Set the actor velocity before applying physics.
Definition: Actor.cpp:43
Represents an actor in the simulation.
Definition: client/Actor.h:18
geom::Vector3D GetVelocity() const
Return the current 3D velocity of the actor.
Definition: Actor.cpp:23
void EnableConstantVelocity(const geom::Vector3D &vector)
Enable a constant velocity mode.
Definition: Actor.cpp:51
Actor(ActorInitializer init)
Definition: client/Actor.h:25
void SetEnableGravity(bool enabled=true)
Enable or disable gravity on this actor.
Definition: Actor.cpp:95
bool IsAlive() const
Definition: client/Actor.h:113
void AddTorque(const geom::Vector3D &vector)
Add a torque to the actor.
Definition: Actor.cpp:79
void DisableConstantVelocity()
Disable the constant velocity mode.
Definition: Actor.cpp:55