|
@@ -6,7 +6,10 @@
|
|
|
|
|
|
#include <Tests/Vehicle/VehicleConstraintTest.h>
|
|
#include <Tests/Vehicle/VehicleConstraintTest.h>
|
|
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
|
|
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
|
|
|
|
+#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
|
#include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
|
|
#include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
|
|
|
|
+#include <Jolt/Physics/Collision/ShapeCast.h>
|
|
|
|
+#include <Jolt/Physics/Collision/CollisionCollectorImpl.h>
|
|
#include <Jolt/Physics/Vehicle/WheeledVehicleController.h>
|
|
#include <Jolt/Physics/Vehicle/WheeledVehicleController.h>
|
|
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
|
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
|
#include <Application/DebugUI.h>
|
|
#include <Application/DebugUI.h>
|
|
@@ -241,6 +244,21 @@ void VehicleConstraintTest::PrePhysicsUpdate(const PreUpdateParams &inParams)
|
|
// Set the collision tester
|
|
// Set the collision tester
|
|
mVehicleConstraint->SetVehicleCollisionTester(mTesters[sCollisionMode]);
|
|
mVehicleConstraint->SetVehicleCollisionTester(mTesters[sCollisionMode]);
|
|
|
|
|
|
|
|
+ if (sOverrideGravity)
|
|
|
|
+ {
|
|
|
|
+ // When overriding gravity is requested, we cast a sphere downwards (opposite to the previous up position) and use the contact normal as the new gravity direction
|
|
|
|
+ SphereShape sphere(0.5f);
|
|
|
|
+ sphere.SetEmbedded();
|
|
|
|
+ RShapeCast shape_cast(&sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(mCarBody->GetPosition()), -3.0f * mVehicleConstraint->GetWorldUp());
|
|
|
|
+ ShapeCastSettings settings;
|
|
|
|
+ ClosestHitCollisionCollector<CastShapeCollector> collector;
|
|
|
|
+ mPhysicsSystem->GetNarrowPhaseQuery().CastShape(shape_cast, settings, mCarBody->GetPosition(), collector, SpecifiedBroadPhaseLayerFilter(BroadPhaseLayers::NON_MOVING), SpecifiedObjectLayerFilter(Layers::NON_MOVING));
|
|
|
|
+ if (collector.HadHit())
|
|
|
|
+ mVehicleConstraint->OverrideGravity(9.81f * collector.mHit.mPenetrationAxis.Normalized());
|
|
|
|
+ else
|
|
|
|
+ mVehicleConstraint->ResetGravityOverride();
|
|
|
|
+ }
|
|
|
|
+
|
|
// Draw our wheels (this needs to be done in the pre update since we draw the bodies too in the state before the step)
|
|
// Draw our wheels (this needs to be done in the pre update since we draw the bodies too in the state before the step)
|
|
for (uint w = 0; w < 4; ++w)
|
|
for (uint w = 0; w < 4; ++w)
|
|
{
|
|
{
|
|
@@ -302,6 +320,7 @@ void VehicleConstraintTest::CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMe
|
|
inUI->CreateCheckBox(inSubMenu, "4 Wheel Drive", sFourWheelDrive, [](UICheckBox::EState inState) { sFourWheelDrive = inState == UICheckBox::STATE_CHECKED; });
|
|
inUI->CreateCheckBox(inSubMenu, "4 Wheel Drive", sFourWheelDrive, [](UICheckBox::EState inState) { sFourWheelDrive = inState == UICheckBox::STATE_CHECKED; });
|
|
inUI->CreateCheckBox(inSubMenu, "Anti Rollbars", sAntiRollbar, [](UICheckBox::EState inState) { sAntiRollbar = inState == UICheckBox::STATE_CHECKED; });
|
|
inUI->CreateCheckBox(inSubMenu, "Anti Rollbars", sAntiRollbar, [](UICheckBox::EState inState) { sAntiRollbar = inState == UICheckBox::STATE_CHECKED; });
|
|
inUI->CreateCheckBox(inSubMenu, "Limited Slip Differentials", sLimitedSlipDifferentials, [](UICheckBox::EState inState) { sLimitedSlipDifferentials = inState == UICheckBox::STATE_CHECKED; });
|
|
inUI->CreateCheckBox(inSubMenu, "Limited Slip Differentials", sLimitedSlipDifferentials, [](UICheckBox::EState inState) { sLimitedSlipDifferentials = inState == UICheckBox::STATE_CHECKED; });
|
|
|
|
+ inUI->CreateCheckBox(inSubMenu, "Override Gravity", sOverrideGravity, [](UICheckBox::EState inState) { sOverrideGravity = inState == UICheckBox::STATE_CHECKED; });
|
|
inUI->CreateSlider(inSubMenu, "Max Engine Torque", float(sMaxEngineTorque), 100.0f, 2000.0f, 10.0f, [](float inValue) { sMaxEngineTorque = inValue; });
|
|
inUI->CreateSlider(inSubMenu, "Max Engine Torque", float(sMaxEngineTorque), 100.0f, 2000.0f, 10.0f, [](float inValue) { sMaxEngineTorque = inValue; });
|
|
inUI->CreateSlider(inSubMenu, "Clutch Strength", float(sClutchStrength), 1.0f, 40.0f, 1.0f, [](float inValue) { sClutchStrength = inValue; });
|
|
inUI->CreateSlider(inSubMenu, "Clutch Strength", float(sClutchStrength), 1.0f, 40.0f, 1.0f, [](float inValue) { sClutchStrength = inValue; });
|
|
inUI->CreateSlider(inSubMenu, "Front Caster Angle", RadiansToDegrees(sFrontCasterAngle), -89.0f, 89.0f, 1.0f, [](float inValue) { sFrontCasterAngle = DegreesToRadians(inValue); });
|
|
inUI->CreateSlider(inSubMenu, "Front Caster Angle", RadiansToDegrees(sFrontCasterAngle), -89.0f, 89.0f, 1.0f, [](float inValue) { sFrontCasterAngle = DegreesToRadians(inValue); });
|