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

Function processAutoBox

physx/source/physxvehicle/src/PxVehicleUpdate.cpp:1270–1326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1268
1269
1270PX_FORCE_INLINE PxF32 processAutoBox(const PxU32 accelIndex, const PxF32 timestep, const PxVehicleDriveSimData& vehCoreSimData, PxVehicleDriveDynData& vehDynData)
1271{
1272 PX_ASSERT(vehDynData.getUseAutoGears());
1273
1274 PxF32 autoboxCompensatedAnalogAccel = vehDynData.mControlAnalogVals[accelIndex];
1275
1276 //If still undergoing a gear change triggered by the autobox
1277 //then turn off the accelerator pedal. This happens in autoboxes
1278 //to stop the driver revving the engine crazily then damaging the
1279 //clutch when the clutch re-engages at the end of the gear change.
1280 const PxU32 currentGear=vehDynData.getCurrentGear();
1281 const PxU32 targetGear=vehDynData.getTargetGear();
1282 if(targetGear!=currentGear && PxVehicleGearsData::eNEUTRAL==currentGear)
1283 {
1284 autoboxCompensatedAnalogAccel = 0;
1285 }
1286
1287 //Only process the autobox if no gear change is underway and the time passed since the last autobox
1288 //gear change is greater than the autobox latency.
1289 PxF32 autoBoxSwitchTime=vehDynData.getAutoBoxSwitchTime();
1290 const PxF32 autoBoxLatencyTime=vehCoreSimData.getAutoBoxData().mDownRatios[PxVehicleGearsData::eREVERSE];
1291 if(targetGear==currentGear && autoBoxSwitchTime > autoBoxLatencyTime)
1292 {
1293 //Work out if the autobox wants to switch up or down.
1294 const PxF32 normalisedEngineOmega=vehDynData.getEngineRotationSpeed()*vehCoreSimData.getEngineData().getRecipMaxOmega();
1295 const PxVehicleAutoBoxData& autoBoxData=vehCoreSimData.getAutoBoxData();
1296
1297 bool gearUp=false;
1298 if(normalisedEngineOmega > autoBoxData.mUpRatios[currentGear] && PxVehicleGearsData::eREVERSE!=currentGear)
1299 {
1300 //If revs too high and not in reverse and not undergoing a gear change then switch up.
1301 gearUp=true;
1302 }
1303
1304 bool gearDown=false;
1305 if(normalisedEngineOmega < autoBoxData.mDownRatios[currentGear] && currentGear > PxVehicleGearsData::eFIRST)
1306 {
1307 //If revs too low and in gear greater than first and not undergoing a gear change then change down.
1308 gearDown=true;
1309 }
1310
1311 //Start the gear change and reset the time since the last autobox gear change.
1312 if(gearUp || gearDown)
1313 {
1314 vehDynData.setGearUp(gearUp);
1315 vehDynData.setGearDown(gearDown);
1316 vehDynData.setAutoBoxSwitchTime(0.f);
1317 }
1318 }
1319 else
1320 {
1321 autoBoxSwitchTime+=timestep;
1322 vehDynData.setAutoBoxSwitchTime(autoBoxSwitchTime);
1323 }
1324
1325 return autoboxCompensatedAnalogAccel;
1326}
1327

Callers 3

updateDrive4WMethod · 0.85
updateDriveNWMethod · 0.85
updateTankMethod · 0.85

Calls 9

getUseAutoGearsMethod · 0.80
getCurrentGearMethod · 0.80
getTargetGearMethod · 0.80
getAutoBoxSwitchTimeMethod · 0.80
getRecipMaxOmegaMethod · 0.80
setAutoBoxSwitchTimeMethod · 0.80
setGearUpMethod · 0.45
setGearDownMethod · 0.45

Tested by

no test coverage detected