Add functions to set actor location and transform
This commit is contained in:
parent
2253877405
commit
7d1f51e9cc
|
@ -10,6 +10,14 @@
|
|||
namespace carla {
|
||||
namespace client {
|
||||
|
||||
bool Actor::SetLocation(const Location &location) {
|
||||
return GetWorld()->GetClient().SetActorLocation(*this, location);
|
||||
}
|
||||
|
||||
bool Actor::SetTransform(const Transform &transform) {
|
||||
return GetWorld()->GetClient().SetActorTransform(*this, transform);
|
||||
}
|
||||
|
||||
void Actor::Destroy() {
|
||||
GetWorld()->GetClient().DestroyActor(*this);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ namespace client {
|
|||
return _world;
|
||||
}
|
||||
|
||||
bool SetLocation(const Location &location);
|
||||
|
||||
bool SetTransform(const Transform &transform);
|
||||
|
||||
const auto &Serialize() const {
|
||||
return _actor;
|
||||
}
|
||||
|
|
|
@ -47,14 +47,22 @@ namespace client {
|
|||
_client.call("destroy_actor", actor.Serialize());
|
||||
}
|
||||
|
||||
bool Client::SetActorLocation(Actor &actor, const Location &location) {
|
||||
return Call<bool>("set_actor_location", actor.Serialize(), location);
|
||||
}
|
||||
|
||||
bool Client::SetActorTransform(Actor &actor, const Transform &transform) {
|
||||
return Call<bool>("set_actor_transform", actor.Serialize(), transform);
|
||||
}
|
||||
|
||||
void Client::ApplyControlToActor(
|
||||
const Actor &actor,
|
||||
Actor &actor,
|
||||
const VehicleControl &control) {
|
||||
_client.call("apply_control_to_actor", actor.Serialize(), control);
|
||||
}
|
||||
|
||||
void Client::SetActorAutopilot(
|
||||
const Actor &actor,
|
||||
Actor &actor,
|
||||
const bool enabled) {
|
||||
_client.call("set_actor_autopilot", actor.Serialize(), enabled);
|
||||
}
|
||||
|
|
|
@ -80,13 +80,17 @@ namespace client {
|
|||
|
||||
void DestroyActor(Actor &actor);
|
||||
|
||||
bool SetActorLocation(Actor &actor, const Location &location);
|
||||
|
||||
bool SetActorTransform(Actor &actor, const Transform &transform);
|
||||
|
||||
void ApplyControlToActor(
|
||||
const Actor &actor,
|
||||
Actor &actor,
|
||||
const VehicleControl &control);
|
||||
|
||||
void SetActorAutopilot(
|
||||
const Actor &actor,
|
||||
bool enabled);
|
||||
Actor &actor,
|
||||
bool enabled = true);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -79,6 +79,8 @@ void export_actor() {
|
|||
return self.GetTypeId();
|
||||
})
|
||||
.def("get_world", &cc::Actor::GetWorld)
|
||||
.def("set_location", &cc::Actor::SetLocation, (arg("location")))
|
||||
.def("set_transform", &cc::Actor::SetTransform, (arg("transform")))
|
||||
.def("destroy", &cc::Actor::Destroy)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
|
|
@ -200,6 +200,40 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
AttachActors(Registry.Find(Child.id), Registry.Find(Parent.id));
|
||||
});
|
||||
|
||||
Server.BindSync("set_actor_location", [this](
|
||||
cr::Actor Actor,
|
||||
cr::Location Location) -> bool {
|
||||
RequireEpisode();
|
||||
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
|
||||
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
|
||||
RespondErrorStr("unable to set actor location: actor not found");
|
||||
}
|
||||
// This function only works with teleport physics, to reset speeds we need
|
||||
// another method.
|
||||
return ActorView.GetActor()->SetActorLocation(
|
||||
Location,
|
||||
false,
|
||||
nullptr,
|
||||
ETeleportType::TeleportPhysics);
|
||||
});
|
||||
|
||||
Server.BindSync("set_actor_transform", [this](
|
||||
cr::Actor Actor,
|
||||
cr::Transform Transform) -> bool {
|
||||
RequireEpisode();
|
||||
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
|
||||
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
|
||||
RespondErrorStr("unable to set actor transform: actor not found");
|
||||
}
|
||||
// This function only works with teleport physics, to reset speeds we need
|
||||
// another method.
|
||||
return ActorView.GetActor()->SetActorTransform(
|
||||
Transform,
|
||||
false,
|
||||
nullptr,
|
||||
ETeleportType::TeleportPhysics);
|
||||
});
|
||||
|
||||
Server.BindSync("apply_control_to_actor", [this](cr::Actor Actor, cr::VehicleControl Control) {
|
||||
RequireEpisode();
|
||||
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
|
||||
|
|
Loading…
Reference in New Issue