Added world pos for wheels + working on using physx to fix a bug
This commit is contained in:
parent
b4f7ecc5ea
commit
1f8eb1ead1
|
@ -21,18 +21,21 @@ namespace rpc {
|
|||
float in_damping_rate,
|
||||
float in_max_steer_angle,
|
||||
bool in_is_steerable,
|
||||
float in_radius)
|
||||
float in_radius,
|
||||
geom::Vector3D in_position)
|
||||
: tire_friction(in_tire_friction),
|
||||
damping_rate(in_damping_rate),
|
||||
max_steer_angle(in_max_steer_angle),
|
||||
is_steerable(in_is_steerable),
|
||||
radius(in_radius) {}
|
||||
radius(in_radius),
|
||||
position(in_position) {}
|
||||
|
||||
float tire_friction = 2.0f;
|
||||
float damping_rate = 0.25f;
|
||||
float max_steer_angle = 70.0f;
|
||||
bool is_steerable = true;
|
||||
float radius = 30.0f;
|
||||
geom::Vector3D position = {0.0f, 0.0f, 0.0f};
|
||||
|
||||
bool operator!=(const WheelPhysicsControl &rhs) const {
|
||||
return
|
||||
|
@ -40,7 +43,8 @@ namespace rpc {
|
|||
damping_rate != rhs.damping_rate ||
|
||||
max_steer_angle != rhs.max_steer_angle ||
|
||||
is_steerable != rhs.is_steerable ||
|
||||
radius != rhs.radius;
|
||||
radius != rhs.radius ||
|
||||
position != rhs.position;
|
||||
}
|
||||
|
||||
bool operator==(const WheelPhysicsControl &rhs) const {
|
||||
|
@ -53,7 +57,8 @@ namespace rpc {
|
|||
damping_rate(Wheel.DampingRate),
|
||||
max_steer_angle(Wheel.MaxSteerAngle),
|
||||
is_steerable(Wheel.IsSteerable),
|
||||
radius(Wheel.Radius) {}
|
||||
radius(Wheel.Radius),
|
||||
position(Wheel.Position.X, Wheel.Position.Y, Wheel.Position.Z) {}
|
||||
|
||||
operator FWheelPhysicsControl() const {
|
||||
FWheelPhysicsControl Wheel;
|
||||
|
@ -62,6 +67,7 @@ namespace rpc {
|
|||
Wheel.MaxSteerAngle = max_steer_angle;
|
||||
Wheel.IsSteerable = is_steerable;
|
||||
Wheel.Radius = radius;
|
||||
Wheel.Position = {position.x, position.y, position.z};
|
||||
return Wheel;
|
||||
}
|
||||
#endif
|
||||
|
@ -70,7 +76,8 @@ namespace rpc {
|
|||
damping_rate,
|
||||
max_steer_angle,
|
||||
is_steerable,
|
||||
radius)
|
||||
radius,
|
||||
position)
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -207,17 +207,19 @@ void export_control() {
|
|||
;
|
||||
|
||||
class_<cr::WheelPhysicsControl>("WheelPhysicsControl")
|
||||
.def(init<float, float, float, bool, float>(
|
||||
.def(init<float, float, float, bool, float, cg::Vector3D>(
|
||||
(arg("tire_friction")=2.0f,
|
||||
arg("damping_rate")=0.25f,
|
||||
arg("max_steer_angle")=70.0f,
|
||||
arg("is_steerable")=false,
|
||||
arg("radius")=30.0f)))
|
||||
arg("radius")=30.0f,
|
||||
arg("position")=cg::Vector3D{0.0f, 0.0f, 0.0f})))
|
||||
.def_readwrite("tire_friction", &cr::WheelPhysicsControl::tire_friction)
|
||||
.def_readwrite("damping_rate", &cr::WheelPhysicsControl::damping_rate)
|
||||
.def_readwrite("max_steer_angle", &cr::WheelPhysicsControl::max_steer_angle)
|
||||
.def_readwrite("is_steerable", &cr::WheelPhysicsControl::is_steerable)
|
||||
.def_readwrite("radius", &cr::WheelPhysicsControl::radius)
|
||||
.def_readwrite("position", &cr::WheelPhysicsControl::position)
|
||||
.def("__eq__", &cr::WheelPhysicsControl::operator==)
|
||||
.def("__ne__", &cr::WheelPhysicsControl::operator!=)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "Components/BoxComponent.h"
|
||||
#include "Engine/CollisionProfile.h"
|
||||
#include "PhysXVehicleManager.h"
|
||||
#include "PhysXPublic.h"
|
||||
#include "TireConfig.h"
|
||||
#include "VehicleWheel.h"
|
||||
|
||||
|
@ -247,11 +249,14 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl()
|
|||
UVehicleWheel *Wheel = Vehicle4W->WheelSetups[i].WheelClass.GetDefaultObject();
|
||||
check(Wheel != nullptr);
|
||||
|
||||
PhysicsWheel.TireFriction = Wheel->TireConfig->GetFrictionScale();
|
||||
PhysicsWheel.DampingRate = Wheel->DampingRate;
|
||||
PhysicsWheel.MaxSteerAngle = Wheel->SteerAngle;
|
||||
PxVehicleWheelData PWheelData = Vehicle4W->PVehicle->mWheelsSimData.getWheelData(i);
|
||||
|
||||
PhysicsWheel.TireFriction = Vehicle4W->Wheels[i]->TireConfig->GetFrictionScale();
|
||||
PhysicsWheel.DampingRate = Cm2ToM2(PWheelData.mDampingRate);
|
||||
PhysicsWheel.MaxSteerAngle = PWheelData.mMaxSteer;
|
||||
PhysicsWheel.IsSteerable = !Vehicle4W->WheelSetups[i].bDisableSteering;
|
||||
PhysicsWheel.Radius = Wheel->ShapeRadius;
|
||||
PhysicsWheel.Radius = PWheelData.mRadius;
|
||||
PhysicsWheel.Position = Vehicle4W->Wheels[i]->Location;
|
||||
|
||||
Wheels.Add(PhysicsWheel);
|
||||
}
|
||||
|
@ -308,20 +313,25 @@ void ACarlaWheeledVehicle::ApplyVehiclePhysicsControl(const FVehiclePhysicsContr
|
|||
for (auto i = 0u; i < PhysicsWheelsNum; ++i)
|
||||
{
|
||||
FWheelSetup WheelSetup = Vehicle4W->WheelSetups[i];
|
||||
|
||||
UVehicleWheel *Wheel = WheelSetup.WheelClass.GetDefaultObject();
|
||||
check(Wheel != nullptr);
|
||||
|
||||
Wheel->DampingRate = PhysicsControl.Wheels[i].DampingRate;
|
||||
Wheel->SteerAngle = PhysicsControl.Wheels[i].MaxSteerAngle;
|
||||
Wheel->TireConfig->SetFrictionScale(PhysicsControl.Wheels[i].TireFriction);
|
||||
Wheel->ShapeRadius = PhysicsControl.Wheels[i].Radius;
|
||||
UVehicleWheel *Wheel = Vehicle4W->Wheels[i];
|
||||
|
||||
WheelSetup.bDisableSteering = !PhysicsControl.Wheels[i].IsSteerable;
|
||||
|
||||
PxVehicleWheelData PWheelData = Vehicle4W->PVehicle->mWheelsSimData.getWheelData(i);
|
||||
PWheelData.mRadius = PhysicsControl.Wheels[i].Radius;
|
||||
PWheelData.mMaxSteer = PhysicsControl.Wheels[i].MaxSteerAngle;
|
||||
PWheelData.mDampingRate = M2ToCm2(PhysicsControl.Wheels[i].DampingRate);
|
||||
|
||||
Vehicle4W->PVehicle->mWheelsSimData.setWheelData(i, PWheelData);
|
||||
|
||||
NewWheelSetups.Add(std::move(WheelSetup));
|
||||
}
|
||||
|
||||
Vehicle4W->WheelSetups = NewWheelSetups;
|
||||
Vehicle4W->RecreatePhysicsState();
|
||||
// Vehicle4W->VehicleSetupTag++;
|
||||
|
||||
for (auto i = 0u; i < PhysicsWheelsNum; ++i)
|
||||
{
|
||||
Vehicle4W->Wheels[i]->TireConfig->SetFrictionScale(PhysicsControl.Wheels[i].TireFriction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,7 @@ struct CARLA_API FWheelPhysicsControl
|
|||
|
||||
UPROPERTY(Category = "Wheel Shape Radius", EditAnywhere, BlueprintReadWrite)
|
||||
float Radius = 30.0f;
|
||||
|
||||
UPROPERTY(Category = "Wheel Position", EditAnywhere, BlueprintReadWrite)
|
||||
FVector Position = FVector::ZeroVector;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue