Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ For breaking API changes see [this document](https://github.com/jrouwe/JoltPhysi
* Added an epsilon to the `CastRay` / `CastShape` early out condition to avoid dividing by a very small number and overflowing to INF. This can cause a float overflow exception.
* Fixed Samples requiring Vulkan extension `VK_EXT_device_address_binding_report` without checking if it is available.
* Fixed Vulkan warning in Samples: VkSemaphore is being signaled by VkQueue but it may still be in use by VkSwapchainKHR.
* Fixed incorrect RTTI definition of MotorcycleControllerSettings which led to the members of WheeledVehicleControllerSettings not being serialized.
* Implemented missing VehicleConstraint::GetConstraintSettings function.

## v5.3.0

Expand Down
15 changes: 14 additions & 1 deletion Jolt/Physics/Vehicle/MotorcycleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ JPH_NAMESPACE_BEGIN

JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(MotorcycleControllerSettings)
{
JPH_ADD_BASE_CLASS(MotorcycleControllerSettings, VehicleControllerSettings)
JPH_ADD_BASE_CLASS(MotorcycleControllerSettings, WheeledVehicleControllerSettings)

JPH_ADD_ATTRIBUTE(MotorcycleControllerSettings, mMaxLeanAngle)
JPH_ADD_ATTRIBUTE(MotorcycleControllerSettings, mLeanSpringConstant)
Expand Down Expand Up @@ -290,4 +290,17 @@ void MotorcycleController::Draw(DebugRenderer *inRenderer) const

#endif // JPH_DEBUG_RENDERER

Ref<VehicleControllerSettings> MotorcycleController::GetSettings() const
{
MotorcycleControllerSettings *settings = new MotorcycleControllerSettings;
ToSettings(*settings);
settings->mMaxLeanAngle = mMaxLeanAngle;
settings->mLeanSpringConstant = mLeanSpringConstant;
settings->mLeanSpringDamping = settings->mLeanSpringDamping;
settings->mLeanSpringIntegrationCoefficient = mLeanSpringIntegrationCoefficient;
settings->mLeanSpringIntegrationCoefficientDecay = mLeanSpringIntegrationCoefficientDecay;
settings->mLeanSmoothingFactor = mLeanSmoothingFactor;
return settings;
}

JPH_NAMESPACE_END
3 changes: 3 additions & 0 deletions Jolt/Physics/Vehicle/MotorcycleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class JPH_EXPORT MotorcycleController : public WheeledVehicleController
void SetLeanSmoothingFactor(float inFactor) { mLeanSmoothingFactor = inFactor; }
float GetLeanSmoothingFactor() const { return mLeanSmoothingFactor; }

// See: VehicleController
virtual Ref<VehicleControllerSettings> GetSettings() const override;

protected:
// See: VehicleController
virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override;
Expand Down
10 changes: 10 additions & 0 deletions Jolt/Physics/Vehicle/TrackedVehicleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,14 @@ void TrackedVehicleController::RestoreState(StateRecorder &inStream)
t.RestoreState(inStream);
}

Ref<VehicleControllerSettings> TrackedVehicleController::GetSettings() const
{
TrackedVehicleControllerSettings *settings = new TrackedVehicleControllerSettings;
settings->mEngine = static_cast<const VehicleEngineSettings &>(mEngine);
settings->mTransmission = static_cast<const VehicleTransmissionSettings &>(mTransmission);
for (size_t i = 0; i < std::size(mTracks); ++i)
settings->mTracks[i] = static_cast<const VehicleTrackSettings &>(mTracks[i]);
return settings;
}

JPH_NAMESPACE_END
3 changes: 3 additions & 0 deletions Jolt/Physics/Vehicle/TrackedVehicleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class JPH_EXPORT TrackedVehicleController : public VehicleController
void SetRPMMeter(Vec3Arg inPosition, float inSize) { mRPMMeterPosition = inPosition; mRPMMeterSize = inSize; }
#endif // JPH_DEBUG_RENDERER

// See: VehicleController
virtual Ref<VehicleControllerSettings> GetSettings() const override;

protected:
/// Synchronize angular velocities of left and right tracks according to their ratios
void SyncLeftRightTracks();
Expand Down
13 changes: 11 additions & 2 deletions Jolt/Physics/Vehicle/VehicleConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,17 @@ void VehicleConstraint::RestoreState(StateRecorder &inStream)

Ref<ConstraintSettings> VehicleConstraint::GetConstraintSettings() const
{
JPH_ASSERT(false); // Not implemented yet
return nullptr;
VehicleConstraintSettings *settings = new VehicleConstraintSettings;
ToConstraintSettings(*settings);
settings->mUp = mUp;
settings->mForward = mForward;
settings->mMaxPitchRollAngle = ACos(mCosMaxPitchRollAngle);
settings->mWheels.resize(mWheels.size());
for (Wheels::size_type w = 0; w < mWheels.size(); ++w)
settings->mWheels[w] = const_cast<WheelSettings *>(mWheels[w]->mSettings.GetPtr());
settings->mAntiRollBars = mAntiRollBars;
settings->mController = mController->GetSettings();
return settings;
}

JPH_NAMESPACE_END
3 changes: 3 additions & 0 deletions Jolt/Physics/Vehicle/VehicleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class JPH_EXPORT VehicleController : public NonCopyable
VehicleConstraint & GetConstraint() { return mConstraint; }
const VehicleConstraint & GetConstraint() const { return mConstraint; }

/// Recreate the settings for this controller
virtual Ref<VehicleControllerSettings> GetSettings() const = 0;

protected:
// The functions below are only for the VehicleConstraint
friend class VehicleConstraint;
Expand Down
15 changes: 15 additions & 0 deletions Jolt/Physics/Vehicle/WheeledVehicleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,4 +848,19 @@ void WheeledVehicleController::RestoreState(StateRecorder &inStream)
mTransmission.RestoreState(inStream);
}

void WheeledVehicleController::ToSettings(WheeledVehicleControllerSettings &outSettings) const
{
outSettings.mEngine = static_cast<const VehicleEngineSettings &>(mEngine);
outSettings.mTransmission = static_cast<const VehicleTransmissionSettings &>(mTransmission);
outSettings.mDifferentials = mDifferentials;
outSettings.mDifferentialLimitedSlipRatio = mDifferentialLimitedSlipRatio;
}

Ref<VehicleControllerSettings> WheeledVehicleController::GetSettings() const
{
WheeledVehicleControllerSettings *settings = new WheeledVehicleControllerSettings;
ToSettings(*settings);
return settings;
}

JPH_NAMESPACE_END
6 changes: 6 additions & 0 deletions Jolt/Physics/Vehicle/WheeledVehicleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ class JPH_EXPORT WheeledVehicleController : public VehicleController
void SetRPMMeter(Vec3Arg inPosition, float inSize) { mRPMMeterPosition = inPosition; mRPMMeterSize = inSize; }
#endif // JPH_DEBUG_RENDERER

// See: VehicleController
virtual Ref<VehicleControllerSettings> GetSettings() const override;

protected:
/// Convert controller back to settings
void ToSettings(WheeledVehicleControllerSettings &outSettings) const;

// See: VehicleController
virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const override { JPH_ASSERT(IsKindOf(&inWheel, JPH_RTTI(WheelSettingsWV))); return new WheelWV(static_cast<const WheelSettingsWV &>(inWheel)); }
virtual bool AllowSleep() const override;
Expand Down
Loading