void PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs (const PxVehicleKeySmoothingData& keySmoothing, const PxVehicleDriveTankRawInputData& rawInputData, const PxF32 timestep, PxVehicleDriveTank& focusVehicle) { PxF32 val; val=processDigitalValue(PxVehicleDriveTank::eANALOG_INPUT_ACCEL,keySmoothing,rawInputData.getDigitalAccel(),timestep,focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_ACCEL)); focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_ACCEL); val=processDigitalValue(PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT,keySmoothing,rawInputData.getDigitalLeftThrust(),timestep,focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT)); focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); val=processDigitalValue(PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT,keySmoothing,rawInputData.getDigitalRightThrust(),timestep,focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT)); focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); val=processDigitalValue(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT,keySmoothing,rawInputData.getDigitalLeftBrake(),timestep,focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT)); focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); val=processDigitalValue(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT,keySmoothing,rawInputData.getDigitalRightBrake(),timestep,focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT)); focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); //Update digital inputs for focus vehicle. focusVehicle.mDriveDynData.setGearUp(rawInputData.getGearUp()); focusVehicle.mDriveDynData.setGearDown(rawInputData.getGearDown()); switch(rawInputData.getDriveModel()) { case PxVehicleDriveTank::eDRIVE_MODEL_SPECIAL: { const PxF32 thrustL=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT)-focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); focusVehicle.mDriveDynData.setAnalogInput(thrustL,PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); const PxF32 thrustR=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT)-focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); focusVehicle.mDriveDynData.setAnalogInput(thrustR,PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); } break; case PxVehicleDriveTank::eDRIVE_MODEL_STANDARD: { const PxF32 thrustL=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT)-focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); if(thrustL>0) { focusVehicle.mDriveDynData.setAnalogInput(thrustL,PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); } else { focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); focusVehicle.mDriveDynData.setAnalogInput(-thrustL,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); } const PxF32 thrustR=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT)-focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); if(thrustR>0) { focusVehicle.mDriveDynData.setAnalogInput(thrustR,PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); } else { focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); focusVehicle.mDriveDynData.setAnalogInput(-thrustR,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); } } break; default: PX_ASSERT(false); break; } }
void PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs (const PxVehiclePadSmoothingData& padSmoothing, const PxVehicleDriveTankRawInputData& rawInputData, const PxReal timestep, PxVehicleDriveTank& focusVehicle) { //Process the gearup/geardown buttons. const bool gearup=rawInputData.getGearUp(); const bool geardown=rawInputData.getGearDown(); focusVehicle.mDriveDynData.setGearUp(gearup); focusVehicle.mDriveDynData.setGearDown(geardown); //Process the accel. { const PxF32 riseRate=padSmoothing.mRiseRates[PxVehicleDriveTank::eANALOG_INPUT_ACCEL]; const PxF32 fallRate=padSmoothing.mFallRates[PxVehicleDriveTank::eANALOG_INPUT_ACCEL]; const PxF32 currentVal=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_ACCEL); const PxF32 targetVal=rawInputData.getAnalogAccel(); const PxF32 accel=processPositiveAnalogValue(riseRate,fallRate,currentVal,targetVal,timestep); focusVehicle.mDriveDynData.setAnalogInput(accel,PxVehicleDriveTank::eANALOG_INPUT_ACCEL); } PX_ASSERT(focusVehicle.getDriveModel()==rawInputData.getDriveModel()); switch(rawInputData.getDriveModel()) { case PxVehicleDriveTank::eDRIVE_MODEL_SPECIAL: { //Process the left brake. { const PxF32 riseRate=padSmoothing.mRiseRates[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT]; const PxF32 fallRate=padSmoothing.mFallRates[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT]; const PxF32 currentVal=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); const PxF32 targetVal=rawInputData.getAnalogLeftBrake(); const PxF32 accel=processPositiveAnalogValue(riseRate,fallRate,currentVal,targetVal,timestep); focusVehicle.mDriveDynData.setAnalogInput(accel,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); } //Process the right brake. { const PxF32 riseRate=padSmoothing.mRiseRates[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT]; const PxF32 fallRate=padSmoothing.mFallRates[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT]; const PxF32 currentVal=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); const PxF32 targetVal=rawInputData.getAnalogRightBrake(); const PxF32 accel=processPositiveAnalogValue(riseRate,fallRate,currentVal,targetVal,timestep); focusVehicle.mDriveDynData.setAnalogInput(accel,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); } //Left thrust { const PxF32 riseRate=padSmoothing.mRiseRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT]; const PxF32 fallRate=padSmoothing.mFallRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT]; const PxF32 currentVal=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); const PxF32 targetVal=rawInputData.getAnalogLeftThrust(); const PxF32 val=processAnalogValue(riseRate,fallRate,currentVal,targetVal,timestep); focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); } //Right thrust { const PxF32 riseRate=padSmoothing.mRiseRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT]; const PxF32 fallRate=padSmoothing.mFallRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT]; const PxF32 currentVal=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); const PxF32 targetVal=rawInputData.getAnalogRightThrust(); const PxF32 val=processAnalogValue(riseRate,fallRate,currentVal,targetVal,timestep); focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); } } break; case PxVehicleDriveTank::eDRIVE_MODEL_STANDARD: { //Right thrust { const PxF32 riseRate=padSmoothing.mRiseRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT]; const PxF32 fallRate=padSmoothing.mFallRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT]; const PxF32 currentVal=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT)-focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); const PxF32 targetVal=rawInputData.getAnalogRightThrust()-rawInputData.getAnalogRightBrake(); const PxF32 val=processAnalogValue(riseRate,fallRate,currentVal,targetVal,timestep); if(val>0) { focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); } else { focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT); focusVehicle.mDriveDynData.setAnalogInput(-val,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT); } } //Left thrust { const PxF32 riseRate=padSmoothing.mRiseRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT]; const PxF32 fallRate=padSmoothing.mFallRates[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT]; const PxF32 currentVal=focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT)-focusVehicle.mDriveDynData.getAnalogInput(PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); const PxF32 targetVal=rawInputData.getAnalogLeftThrust()-rawInputData.getAnalogLeftBrake(); const PxF32 val=processAnalogValue(riseRate,fallRate,currentVal,targetVal,timestep); if(val>0) { focusVehicle.mDriveDynData.setAnalogInput(val,PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); } else { focusVehicle.mDriveDynData.setAnalogInput(0.0f,PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT); focusVehicle.mDriveDynData.setAnalogInput(-val,PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT); } } } break; default: PX_ASSERT(false); break; } }