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 SampleVehicle_VehicleController::processAutoReverse (const PxVehicleWheels& focusVehicle, const PxVehicleDriveDynData& driveDynData, const PxVehicleWheelQueryResult& vehicleWheelQueryResults, const PxVehicleDriveTankRawInputData& tankRawInputs, bool& toggleAutoReverse, bool& newIsMovingForwardSlowly) const { newIsMovingForwardSlowly = false; toggleAutoReverse = false; if(driveDynData.getUseAutoGears()) { //If the car is travelling very slowly in forward gear without player input and the player subsequently presses the brake then we want the car to go into reverse gear //If the car is travelling very slowly in reverse gear without player input and the player subsequently presses the accel then we want the car to go into forward gear //If the car is in forward gear and is travelling backwards then we want to automatically put the car into reverse gear. //If the car is in reverse gear and is travelling forwards then we want to automatically put the car into forward gear. //(If the player brings the car to rest with the brake the player needs to release the brake then reapply it //to indicate they want to toggle between forward and reverse.) const bool prevIsMovingForwardSlowly=mIsMovingForwardSlowly; bool isMovingForwardSlowly=false; bool isMovingBackwards=false; const bool isInAir = PxVehicleIsInAir(vehicleWheelQueryResults); if(!isInAir) { bool accelLeft,accelRight,brakeLeft,brakeRight; if(mUseKeyInputs) { accelLeft=tankRawInputs.getDigitalLeftThrust(); accelRight=tankRawInputs.getDigitalRightThrust(); brakeLeft=tankRawInputs.getDigitalLeftBrake(); brakeRight=tankRawInputs.getDigitalRightBrake(); } else { accelLeft = tankRawInputs.getAnalogLeftThrust() > 0 ? true : false; accelRight = tankRawInputs.getAnalogRightThrust() > 0 ? true : false; brakeLeft = tankRawInputs.getAnalogLeftBrake() > 0 ? true : false; brakeRight = tankRawInputs.getAnalogRightBrake() > 0 ? true : false; /* if(accelLeft && accelLeft==accelRight && !brakeLeft && !brakeRight) { shdfnd::printFormatted("aligned accel\n"); } if(brakeLeft && brakeLeft==brakeRight && !accelLeft && !accelRight) { shdfnd::printFormatted("aligned brake\n"); } */ } const PxF32 forwardSpeed = focusVehicle.computeForwardSpeed(); const PxF32 forwardSpeedAbs = PxAbs(forwardSpeed); const PxF32 sidewaysSpeedAbs = PxAbs(focusVehicle.computeSidewaysSpeed()); const PxU32 currentGear = driveDynData.getCurrentGear(); const PxU32 targetGear = driveDynData.getTargetGear(); //Check if the car is rolling against the gear (backwards in forward gear or forwards in reverse gear). if(PxVehicleGearsData::eFIRST == currentGear && forwardSpeed < -THRESHOLD_ROLLING_BACKWARDS_SPEED) { isMovingBackwards = true; } else if(PxVehicleGearsData::eREVERSE == currentGear && forwardSpeed > THRESHOLD_ROLLING_BACKWARDS_SPEED) { isMovingBackwards = true; } //Check if the car is moving slowly. if(forwardSpeedAbs < THRESHOLD_FORWARD_SPEED && sidewaysSpeedAbs < THRESHOLD_SIDEWAYS_SPEED) { isMovingForwardSlowly=true; } //Now work if we need to toggle from forwards gear to reverse gear or vice versa. if(isMovingBackwards) { if(!accelLeft && !accelRight && !brakeLeft && !brakeRight && (currentGear == targetGear)) { //The car is rolling against the gear and the player is doing nothing to stop this. toggleAutoReverse = true; } } else if(prevIsMovingForwardSlowly && isMovingForwardSlowly) { if((currentGear > PxVehicleGearsData::eNEUTRAL) && brakeLeft && brakeRight && !accelLeft && !accelRight && (currentGear == targetGear)) { //The car was moving slowly in forward gear without player input and is now moving slowly with player input that indicates the //player wants to switch to reverse gear. toggleAutoReverse = true; } else if(currentGear == PxVehicleGearsData::eREVERSE && accelLeft && accelRight && !brakeLeft && !brakeRight && (currentGear == targetGear)) { //The car was moving slowly in reverse gear without player input and is now moving slowly with player input that indicates the //player wants to switch to forward gear. toggleAutoReverse = true; } } //If the car was brought to rest through braking then the player needs to release the brake then reapply //to indicate that the gears should toggle between reverse and forward. if(isMovingForwardSlowly && (!brakeLeft || !brakeRight) && (!accelLeft || !accelRight)) { newIsMovingForwardSlowly = true; } } } }