MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / computeTankDiff

Function computeTankDiff

physx/source/physxvehicle/src/PxVehicleUpdate.cpp:1675–1751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1673///////////////////////////////////////////////////////
1674
1675void computeTankDiff
1676(const PxF32 thrustLeft, const PxF32 thrustRight,
1677 const PxU32 numActiveWheels, const bool* activeWheelStates,
1678 PxF32* aveWheelSpeedContributions, PxF32* diffTorqueRatios, PxF32* wheelGearings)
1679{
1680 const PxF32 thrustLeftAbs=PxAbs(thrustLeft);
1681 const PxF32 thrustRightAbs=PxAbs(thrustRight);
1682
1683 //Work out now many left wheels are enabled.
1684 PxF32 numLeftWheels=0.0f;
1685 for(PxU32 i=0;i<numActiveWheels;i+=2)
1686 {
1687 if(activeWheelStates[i])
1688 {
1689 numLeftWheels+=1.0f;
1690 }
1691 }
1692 const PxF32 invNumEnabledWheelsLeft = numLeftWheels > 0 ? 1.0f/numLeftWheels : 0.0f;
1693
1694 //Work out now many right wheels are enabled.
1695 PxF32 numRightWheels=0.0f;
1696 for(PxU32 i=1;i<numActiveWheels;i+=2)
1697 {
1698 if(activeWheelStates[i])
1699 {
1700 numRightWheels+=1.0f;
1701 }
1702 }
1703 const PxF32 invNumEnabledWheelsRight = numRightWheels > 0 ? 1.0f/numRightWheels : 0.0f;
1704
1705 //Split the diff torque between left and right.
1706 PxF32 diffTorqueRatioLeft=0.5f;
1707 PxF32 diffTorqueRatioRight=0.5f;
1708 if((thrustLeftAbs + thrustRightAbs) > 1e-3f)
1709 {
1710 const PxF32 thrustDiff = 0.5f*(thrustLeftAbs - thrustRightAbs)/(thrustLeftAbs + thrustRightAbs);
1711 diffTorqueRatioLeft += thrustDiff;
1712 diffTorqueRatioRight -= thrustDiff;
1713
1714 }
1715 diffTorqueRatioLeft *= invNumEnabledWheelsLeft;
1716 diffTorqueRatioRight *= invNumEnabledWheelsRight;
1717
1718 //Compute the per wheel gearing.
1719 PxF32 wheelGearingLeft=1.0f;
1720 PxF32 wheelGearingRight=1.0f;
1721 if((thrustLeftAbs + thrustRightAbs) > 1e-3f)
1722 {
1723 wheelGearingLeft=computeSign(thrustLeft);
1724 wheelGearingRight=computeSign(thrustRight);
1725 }
1726
1727 //Compute the contribution of each wheel to the average speed at the clutch.
1728 const PxF32 aveWheelSpeedContributionLeft = 0.5f*invNumEnabledWheelsLeft;
1729 const PxF32 aveWheelSpeedContributionRight = 0.5f*invNumEnabledWheelsRight;
1730
1731 //Set all the left wheels.
1732 for(PxU32 i=0;i<numActiveWheels;i+=2)

Callers 1

updateTankMethod · 0.85

Calls 2

PxAbsFunction · 0.85
computeSignFunction · 0.85

Tested by

no test coverage detected