void NxVehicle::control(NxReal steering, bool analogSteering, NxReal acceleration, bool analogAcceleration, bool handBrake) { if (steering != 0 || acceleration != 0 || handBrake) _bodyActor->wakeUp(0.05); _controlSteering(steering, analogSteering); _computeLocalVelocity(); if (!_braking || _releaseBraking) { _braking = _localVelocity.x * acceleration < (-0.1f /* NxMath::sign(-acceleration)*/); _releaseBraking = false; } //printf("Braking: %s, Handbrake: %s\n", _braking?"true":"false", handBrake?"true":"false"); if(_handBrake != handBrake) { _handBrake = handBrake; _brakePedalChanged; } _controlAcceleration(acceleration, analogAcceleration); }
void pVehicle::control(float steering, bool analogSteering, float acceleration, bool analogAcceleration, bool handBrake) { if (steering != 0 || acceleration != 0 || handBrake) getActor()->wakeUp(0.05); return; _controlSteering(steering, analogSteering); _computeLocalVelocity(); NxVec3 locVel = _localVelocity; float lcx = locVel.x; float lcz = locVel.z; float test = _localVelocity.z * acceleration < ( NxMath::sign(-acceleration) ); float test2 = _localVelocity.z * acceleration < ( -0.1f ); float test3 = XAbs(_localVelocity.z) * acceleration < ( -0.1f ); if (!_braking || _releaseBraking) { //_braking = _localVelocity.x * acceleration < (-0.1f /** NxMath::sign(-acceleration) */); _braking = _localVelocity.z * acceleration < ( -0.1 /*NxMath::sign(acceleration) */ ); //_braking = _localVelocity.z * acceleration < ( NxMath::sign(acceleration)); _releaseBraking = false; } if(_handBrake != handBrake) { _handBrake = handBrake; _brakePedalChanged; } //printf("Braking: %s, Handbrake: %s\n", _braking?"true":"false", handBrake?"true":"false"); _controlAcceleration(acceleration, analogAcceleration); }
int pVehicle::_calculateCurrentStatus() { int result = 0; //---------------------------------------------------------------- // // is moving ? // { _computeLocalVelocity(); if ( NxMath::abs(_localVelocity.z) > 0.01f) result |=VS_IsMoving; if (result & VS_IsMoving) { if(_localVelocity.z > 0.0f) result|=VS_IsRollingForward; if(_localVelocity.z < 0.0f) result|=VS_IsRollingBackward; } } NxVec3 _loc = _localVelocity; //---------------------------------------------------------------- // // is accelerated ? // if ( _cAcceleration > 0.1f ) result |=VS_IsAcceleratedForward; if ( _cAcceleration < 0.0f ) result |=VS_IsAcceleratedBackward; if ( (result & VS_IsAcceleratedForward) || (result & VS_IsAcceleratedBackward) ) result |=VS_IsAccelerated; //---------------------------------------------------------------- // // is Braking ? // if ( (result & VS_IsMoving ) ) { if ( _localVelocity.z > 0.0f && ( result & VS_IsAcceleratedBackward ) ) { result |=VS_IsBraking; } if ( _localVelocity.z < 0.0f && (result & VS_IsAcceleratedForward ) ) { result |=VS_IsBraking; } } //---------------------------------------------------------------- // // is steering // if( XAbs(_cSteering) > 0.01f ) result|=VS_IsSteering; //---------------------------------------------------------------- // // is falling + handbrake // _nbNotTouching =0; _nbTouching =0; _nbHandbrakeOn =0; int nbWheels = _wheels.size(); for(NxU32 i = 0; i < _wheels.size(); i++) { pWheel* wheel = _wheels[i]; if (!wheel->hasGroundContact()) { _nbNotTouching++; } else { _nbTouching++; } if(_cHandbrake && wheel->getWheelFlag(WF_AffectedByHandbrake)) { _nbHandbrakeOn++; } } if (_nbNotTouching == _wheels.size()) result |= VS_IsFalling; if (_cHandbrake && _nbHandbrakeOn ) { result|=VS_Handbrake; } /* if ( !(result & VS_IsBraking) ) { mBreakLastFrame = false; mTimeBreaking = 0.0f; } */ _accelerationPedal = _cAcceleration; return result; }