|
@@ -76,17 +76,18 @@ void VehicleConstraintSettings::RestoreBinaryState(StreamIn &inStream)
|
|
|
}
|
|
|
|
|
|
VehicleConstraint::VehicleConstraint(Body &inVehicleBody, const VehicleConstraintSettings &inSettings) :
|
|
|
- Constraint(inSettings)
|
|
|
+ Constraint(inSettings),
|
|
|
+ mBody(&inVehicleBody),
|
|
|
+ mForward(inSettings.mForward),
|
|
|
+ mUp(inSettings.mUp),
|
|
|
+ mWorldUp(inSettings.mUp)
|
|
|
{
|
|
|
// Check sanity of incoming settings
|
|
|
- JPH_ASSERT(inSettings.mForward.IsNormalized());
|
|
|
JPH_ASSERT(inSettings.mUp.IsNormalized());
|
|
|
+ JPH_ASSERT(inSettings.mForward.IsNormalized());
|
|
|
JPH_ASSERT(!inSettings.mWheels.empty());
|
|
|
|
|
|
- // Store general properties
|
|
|
- mBody = &inVehicleBody;
|
|
|
- mUp = inSettings.mUp;
|
|
|
- mForward = inSettings.mForward;
|
|
|
+ // Store max pitch/roll angle
|
|
|
SetMaxPitchRollAngle(inSettings.mMaxPitchRollAngle);
|
|
|
|
|
|
// Copy anti-rollbar settings
|
|
@@ -157,6 +158,9 @@ void VehicleConstraint::OnStep(float inDeltaTime, PhysicsSystem &inPhysicsSystem
|
|
|
{
|
|
|
JPH_PROFILE_FUNCTION();
|
|
|
|
|
|
+ // Calculate new world up vector by inverting gravity
|
|
|
+ mWorldUp = (-inPhysicsSystem.GetGravity()).NormalizedOr(mWorldUp);
|
|
|
+
|
|
|
// Callback on our controller
|
|
|
mController->PreCollide(inDeltaTime, inPhysicsSystem);
|
|
|
|
|
@@ -320,15 +324,15 @@ void VehicleConstraint::CalculateWheelContactPoint(const Wheel &inWheel, Vec3 &o
|
|
|
void VehicleConstraint::CalculatePitchRollConstraintProperties(float inDeltaTime, RMat44Arg inBodyTransform)
|
|
|
{
|
|
|
// Check if a limit was specified
|
|
|
- if (mCosMaxPitchRollAngle < JPH_PI)
|
|
|
+ if (mCosMaxPitchRollAngle > -1.0f)
|
|
|
{
|
|
|
// Calculate cos of angle between world up vector and vehicle up vector
|
|
|
Vec3 vehicle_up = inBodyTransform.Multiply3x3(mUp);
|
|
|
- mCosPitchRollAngle = mUp.Dot(vehicle_up);
|
|
|
+ mCosPitchRollAngle = mWorldUp.Dot(vehicle_up);
|
|
|
if (mCosPitchRollAngle < mCosMaxPitchRollAngle)
|
|
|
{
|
|
|
// Calculate rotation axis to rotate vehicle towards up
|
|
|
- Vec3 rotation_axis = mUp.Cross(vehicle_up);
|
|
|
+ Vec3 rotation_axis = mWorldUp.Cross(vehicle_up);
|
|
|
float len = rotation_axis.Length();
|
|
|
if (len > 0.0f)
|
|
|
mPitchRollRotationAxis = rotation_axis / len;
|