Use center of bounding box as vehicle position

This commit is contained in:
nsubiron 2018-03-06 15:00:05 +01:00
parent 957d44bb38
commit b1e517fd95
4 changed files with 18 additions and 4 deletions

View File

@ -132,7 +132,6 @@ void FCarlaEncoder::Encode(
void FCarlaEncoder::Encode(const UAgentComponent &AgentComponent, carla_agent &AgentData)
{
AgentData.id = AgentComponent.GetId();
::Encode(AgentComponent.GetComponentTransform(), AgentData.transform);
FCarlaEncoder Encoder(AgentData);
AgentComponent.AcceptVisitor(Encoder);
}
@ -145,6 +144,7 @@ FCarlaEncoder::FCarlaEncoder(carla_agent &InData) : Data(InData) {}
void FCarlaEncoder::Visit(const UTrafficSignAgentComponent &Agent)
{
::Encode(Agent.GetComponentTransform(), Data.transform);
auto &TrafficSign = Agent.GetTrafficSign();
switch (TrafficSign.GetTrafficSignState()) {
case ETrafficSignState::TrafficLightRed:
@ -196,6 +196,7 @@ void FCarlaEncoder::Visit(const UTrafficSignAgentComponent &Agent)
void FCarlaEncoder::Visit(const UVehicleAgentComponent &Agent)
{
auto &Vehicle = Agent.GetVehicle();
::Encode(Vehicle.GetVehicleTransform(), Data.transform);
Data.type = CARLA_SERVER_AGENT_VEHICLE;
Data.forward_speed = Vehicle.GetVehicleForwardSpeed();
::Encode(Vehicle.GetVehicleBoundsExtent(), Data.box_extent);
@ -203,6 +204,7 @@ void FCarlaEncoder::Visit(const UVehicleAgentComponent &Agent)
void FCarlaEncoder::Visit(const UWalkerAgentComponent &Agent)
{
::Encode(Agent.GetComponentTransform(), Data.transform);
Data.type = CARLA_SERVER_AGENT_PEDESTRIAN;
Data.forward_speed = Agent.GetForwardSpeed();
::Encode(Agent.GetBoundingBoxExtent(), Data.box_extent);

View File

@ -64,7 +64,7 @@ void ACarlaVehicleController::Tick(float DeltaTime)
auto Vehicle = GetPossessedVehicle();
CarlaPlayerState->UpdateTimeStamp(DeltaTime);
const FVector PreviousSpeed = CarlaPlayerState->ForwardSpeed * CarlaPlayerState->GetOrientation();
CarlaPlayerState->Transform = Vehicle->GetActorTransform();
CarlaPlayerState->Transform = Vehicle->GetVehicleTransform();
CarlaPlayerState->ForwardSpeed = Vehicle->GetVehicleForwardSpeed();
const FVector CurrentSpeed = CarlaPlayerState->ForwardSpeed * CarlaPlayerState->GetOrientation();
CarlaPlayerState->Acceleration = (CurrentSpeed - PreviousSpeed) / DeltaTime;
@ -113,7 +113,7 @@ void ACarlaVehicleController::IntersectPlayerWithRoadMap()
auto Vehicle = GetPossessedVehicle();
constexpr float ChecksPerCentimeter = 0.1f;
auto Result = RoadMap->Intersect(
Vehicle->GetActorTransform(),
Vehicle->GetVehicleTransform(),
Vehicle->GetVehicleBoundsExtent(),
ChecksPerCentimeter);

View File

@ -37,6 +37,13 @@ ACarlaWheeledVehicle::~ACarlaWheeledVehicle() {}
// -- Get functions ------------------------------------------------------------
// =============================================================================
FTransform ACarlaWheeledVehicle::GetVehicleTransform() const
{
FTransform Transform = VehicleBounds->GetComponentTransform();
Transform.SetScale3D(GetActorTransform().GetScale3D());
return Transform;
}
float ACarlaWheeledVehicle::GetVehicleForwardSpeed() const
{
return GetVehicleMovementComponent()->GetForwardSpeed() * 0.036f;
@ -44,7 +51,7 @@ float ACarlaWheeledVehicle::GetVehicleForwardSpeed() const
FVector ACarlaWheeledVehicle::GetVehicleOrientation() const
{
return GetActorTransform().GetRotation().GetForwardVector();
return GetVehicleTransform().GetRotation().GetForwardVector();
}
int32 ACarlaWheeledVehicle::GetVehicleCurrentGear() const

View File

@ -41,6 +41,11 @@ public:
/// @{
public:
/// Transform of the vehicle. Location is shifted so it matches center of the
/// vehicle bounds rather than the actor's location.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FTransform GetVehicleTransform() const;
/// Forward speed in km/h. Might be negative if goes backwards.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
float GetVehicleForwardSpeed() const;