Add functions to get actor location and transform

This commit is contained in:
nsubiron 2018-07-28 17:46:26 +02:00
parent 1b69494772
commit 12243aa84e
7 changed files with 65 additions and 1 deletions

View File

@ -10,6 +10,14 @@
namespace carla {
namespace client {
Location Actor::GetLocation() {
return GetWorld()->GetClient().GetActorLocation(*this);
}
Transform Actor::GetTransform() {
return GetWorld()->GetClient().GetActorTransform(*this);
}
bool Actor::SetLocation(const Location &location) {
return GetWorld()->GetClient().SetActorLocation(*this, location);
}

View File

@ -39,6 +39,10 @@ namespace client {
return _world;
}
Location GetLocation();
Transform GetTransform();
bool SetLocation(const Location &location);
bool SetTransform(const Transform &transform);

View File

@ -47,6 +47,14 @@ namespace client {
_client.call("destroy_actor", actor.Serialize());
}
Location Client::GetActorLocation(Actor &actor) {
return Call<Location>("get_actor_location", actor.Serialize());
}
Transform Client::GetActorTransform(Actor &actor) {
return Call<Transform>("get_actor_transform", actor.Serialize());
}
bool Client::SetActorLocation(Actor &actor, const Location &location) {
return Call<bool>("set_actor_location", actor.Serialize(), location);
}

View File

@ -80,6 +80,10 @@ namespace client {
void DestroyActor(Actor &actor);
Location GetActorLocation(Actor &actor);
Transform GetActorTransform(Actor &actor);
bool SetActorLocation(Actor &actor, const Location &location);
bool SetActorTransform(Actor &actor, const Transform &transform);

View File

@ -40,7 +40,27 @@ namespace rpc {
#endif // LIBCARLA_INCLUDED_FROM_UE4
MSGPACK_DEFINE_ARRAY(x, y, z);
// =========================================================================
/// @todo The following is copy-pasted from MSGPACK_DEFINE_ARRAY.
/// This is a workaround for an issue in msgpack library. The
/// MSGPACK_DEFINE_ARRAY macro is shadowing our `z` variable.
/// https://github.com/msgpack/msgpack-c/issues/709
// =========================================================================
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_pack(pk);
}
void msgpack_unpack(clmdep_msgpack::object const& o)
{
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_unpack(o);
}
template <typename MSGPACK_OBJECT>
void msgpack_object(MSGPACK_OBJECT* o, clmdep_msgpack::zone& sneaky_variable_that_shadows_z) const
{
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_object(o, sneaky_variable_that_shadows_z);
}
// =========================================================================
};
class Rotation {

View File

@ -79,6 +79,8 @@ void export_actor() {
return self.GetTypeId();
})
.def("get_world", &cc::Actor::GetWorld)
.def("get_location", &cc::Actor::GetLocation)
.def("get_transform", &cc::Actor::GetTransform)
.def("set_location", &cc::Actor::SetLocation, (arg("location")))
.def("set_transform", &cc::Actor::SetTransform, (arg("transform")))
.def("destroy", &cc::Actor::Destroy)

View File

@ -200,6 +200,24 @@ void FTheNewCarlaServer::FPimpl::BindActions()
AttachActors(Registry.Find(Child.id), Registry.Find(Parent.id));
});
Server.BindSync("get_actor_location", [this](cr::Actor Actor) -> cr::Location {
RequireEpisode();
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
RespondErrorStr("unable to get actor location: actor not found");
}
return {ActorView.GetActor()->GetActorLocation()};
});
Server.BindSync("get_actor_transform", [this](cr::Actor Actor) -> cr::Transform {
RequireEpisode();
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
RespondErrorStr("unable to get actor transform: actor not found");
}
return {ActorView.GetActor()->GetActorTransform()};
});
Server.BindSync("set_actor_location", [this](
cr::Actor Actor,
cr::Location Location) -> bool {