|
|
@@ -788,7 +788,14 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
bAlreadySkidding = false;
|
|
bAlreadySkidding = false;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
// how much force we want to apply in these axes
|
|
// Velocity impulses fwd and right. Units are like meters per second.
|
|
|
|
// This function was written assuming a fixed FPS, so a correction is made
|
|
|
|
// right at the end before actually applying these impulses.
|
|
|
|
//
|
|
|
|
// Note that many functions in this engine deal with "force impulses" rather
|
|
|
|
// than "velocity impulses". They are directly related: F=ma. It is
|
|
|
|
// possible that the original devs actually used force impulses here but
|
|
|
|
// an optimising compiler re-arranged their maths.
|
|
float fwd = 0.0f;
|
|
float fwd = 0.0f;
|
|
float right = 0.0f;
|
|
float right = 0.0f;
|
|
|
|
|
|
|
@@ -804,36 +811,30 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
bAlreadySkidding = true;
|
|
bAlreadySkidding = true;
|
|
*wheelState = WHEEL_STATE_NORMAL;
|
|
*wheelState = WHEEL_STATE_NORMAL;
|
|
|
|
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
// Everything else here is timestep independent, let's stay with this theme to keep the rest of the FPS bugfixes simpler.
|
|
|
|
adhesion *= CTimer::GetDefaultTimeStep();
|
|
|
|
#else
|
|
adhesion *= CTimer::GetTimeStep();
|
|
adhesion *= CTimer::GetTimeStep();
|
|
|
|
#endif
|
|
if(bAlreadySkidding)
|
|
if(bAlreadySkidding)
|
|
adhesion *= pHandling->fTractionLoss;
|
|
adhesion *= pHandling->fTractionLoss;
|
|
|
|
|
|
// moving sideways
|
|
// moving sideways
|
|
if(contactSpeedRight != 0.0f){
|
|
if(contactSpeedRight != 0.0f){
|
|
// exert opposing force
|
|
// exert opposing force
|
|
right = -contactSpeedRight/wheelsOnGround;
|
|
right = -contactSpeedRight/wheelsOnGround;
|
|
// BUG?
|
|
|
|
// contactSpeedRight is independent of framerate but right has timestep as a factor
|
|
|
|
// so we probably have to fix this
|
|
|
|
// fixing this causes jittery cars at 15fps, and causes the car to move backwards slowly at 18fps
|
|
|
|
// at 19fps, the effects are gone ...
|
|
|
|
//right *= CTimer::GetTimeStepFix();
|
|
|
|
|
|
|
|
if(wheelStatus == WHEEL_STATUS_BURST){
|
|
if(wheelStatus == WHEEL_STATUS_BURST){
|
|
float fwdspeed = Min(contactSpeedFwd, fBurstSpeedMax);
|
|
float fwdspeed = Min(contactSpeedFwd, fBurstSpeedMax);
|
|
#ifdef FIX_BUGS
|
|
|
|
// Keep the effect running at the same frequency even when the game is at high FPS
|
|
|
|
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstTyreMod, fBurstTyreMod) * CTimer::GetLogicalFramesPassed();
|
|
|
|
#else
|
|
|
|
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstTyreMod, fBurstTyreMod);
|
|
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstTyreMod, fBurstTyreMod);
|
|
#endif
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(bDriving){
|
|
if(bDriving){
|
|
fwd = thrust;
|
|
fwd = thrust;
|
|
|
|
|
|
// limit sideways force (why?)
|
|
// Limit sideways forces applied by the tires to the max the tires can possibly do.
|
|
if(right > 0.0f){
|
|
if(right > 0.0f){
|
|
if(right > adhesion)
|
|
if(right > adhesion)
|
|
right = adhesion;
|
|
right = adhesion;
|
|
|
@@ -843,11 +844,6 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
}
|
|
}
|
|
}else if(contactSpeedFwd != 0.0f){
|
|
}else if(contactSpeedFwd != 0.0f){
|
|
fwd = -contactSpeedFwd/wheelsOnGround;
|
|
fwd = -contactSpeedFwd/wheelsOnGround;
|
|
#ifdef FIX_BUGS
|
|
|
|
// contactSpeedFwd is independent of framerate but fwd has timestep as a factor
|
|
|
|
// so we probably have to fix this
|
|
|
|
fwd *= CTimer::GetTimeStepFix();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!bBraking){
|
|
if(!bBraking){
|
|
if(m_fGasPedal < 0.01f){
|
|
if(m_fGasPedal < 0.01f){
|
|
|
@@ -859,9 +855,6 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
brake = 0.2f * mod_HandlingManager.fWheelFriction / pHandling->fMass;
|
|
brake = 0.2f * mod_HandlingManager.fWheelFriction / pHandling->fMass;
|
|
else
|
|
else
|
|
brake = mod_HandlingManager.fWheelFriction / pHandling->fMass;
|
|
brake = mod_HandlingManager.fWheelFriction / pHandling->fMass;
|
|
#ifdef FIX_BUGS
|
|
|
|
brake *= CTimer::GetTimeStepFix();
|
|
|
|
#endif
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -888,10 +881,10 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
*wheelState = WHEEL_STATE_SKIDDING;
|
|
*wheelState = WHEEL_STATE_SKIDDING;
|
|
}
|
|
}
|
|
|
|
|
|
float l = Sqrt(speedSq);
|
|
float speed = Sqrt(speedSq);
|
|
float tractionLoss = bAlreadySkidding ? 1.0f : pHandling->fTractionLoss;
|
|
float tractionLoss = bAlreadySkidding ? 1.0f : pHandling->fTractionLoss;
|
|
right *= adhesion * tractionLoss / l;
|
|
right *= adhesion * tractionLoss / speed;
|
|
fwd *= adhesion * tractionLoss / l;
|
|
fwd *= adhesion * tractionLoss / speed;
|
|
}
|
|
}
|
|
|
|
|
|
if(fwd != 0.0f || right != 0.0f){
|
|
if(fwd != 0.0f || right != 0.0f){
|
|
|
@@ -923,9 +916,19 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
else
|
|
else
|
|
turnDirection = direction;
|
|
turnDirection = direction;
|
|
|
|
|
|
|
|
|
|
|
|
// Curious: there is a perfectly good ApplyMoveSpeed() function that
|
|
|
|
// takes "velocity impulses", but instead we use the ApplyMoveForce()
|
|
|
|
// function which takes a "force impulse" instead and then fix up the
|
|
|
|
// difference by multiplying in the vehicle mass (F=ma). Possibly
|
|
|
|
// evidence that an optimising compiler re-arranged the arithmetic?
|
|
float impulse = speed*m_fMass;
|
|
float impulse = speed*m_fMass;
|
|
float turnImpulse = turnSpeed*GetMass(wheelContactPoint, turnDirection);
|
|
float turnImpulse = turnSpeed*GetMass(wheelContactPoint, turnDirection);
|
|
|
|
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
impulse = impulse * CTimer::GetTimeStepFix();
|
|
|
|
turnImpulse = turnImpulse * CTimer::GetTimeStepFix();
|
|
|
|
#endif
|
|
ApplyMoveForce(impulse * direction);
|
|
ApplyMoveForce(impulse * direction);
|
|
ApplyTurnForce(turnImpulse * turnDirection, wheelContactPoint);
|
|
ApplyTurnForce(turnImpulse * turnDirection, wheelContactPoint);
|
|
}
|
|
}
|
|
|
@@ -949,7 +952,14 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
bAlreadySkidding = false;
|
|
bAlreadySkidding = false;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
// how much force we want to apply in these axes
|
|
// Velocity impulses fwd and right. Units are like meters per second.
|
|
|
|
// This function was written assuming a fixed FPS, so a correction is made
|
|
|
|
// right at the end before actually applying these impulses.
|
|
|
|
//
|
|
|
|
// Note that many functions in this engine deal with "force impulses" rather
|
|
|
|
// than "velocity impulses". They are directly related: F=ma. It is
|
|
|
|
// possible that the original devs actually used force impulses here but
|
|
|
|
// an optimising compiler re-arranged their maths.
|
|
float fwd = 0.0f;
|
|
float fwd = 0.0f;
|
|
float right = 0.0f;
|
|
float right = 0.0f;
|
|
|
|
|
|
|
@@ -966,7 +976,12 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
bAlreadySkidding = true;
|
|
bAlreadySkidding = true;
|
|
*wheelState = WHEEL_STATE_NORMAL;
|
|
*wheelState = WHEEL_STATE_NORMAL;
|
|
|
|
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
// Everything else here is timestep independent, let's stay with this theme to keep the rest of the FPS bugfixes simpler.
|
|
|
|
adhesion *= CTimer::GetDefaultTimeStep();
|
|
|
|
#else
|
|
adhesion *= CTimer::GetTimeStep();
|
|
adhesion *= CTimer::GetTimeStep();
|
|
|
|
#endif
|
|
if(bAlreadySkidding)
|
|
if(bAlreadySkidding)
|
|
adhesion *= pHandling->fTractionLoss;
|
|
adhesion *= pHandling->fTractionLoss;
|
|
|
|
|
|
|
@@ -979,20 +994,10 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
if(contactSpeedRight != 0.0f){
|
|
if(contactSpeedRight != 0.0f){
|
|
// exert opposing force
|
|
// exert opposing force
|
|
right = -contactSpeedRight/wheelsOnGround;
|
|
right = -contactSpeedRight/wheelsOnGround;
|
|
#ifdef FIX_BUGS
|
|
|
|
// contactSpeedRight is independent of framerate but right has timestep as a factor
|
|
|
|
// so we probably have to fix this
|
|
|
|
right *= CTimer::GetTimeStepFix();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(wheelStatus == WHEEL_STATUS_BURST){
|
|
if(wheelStatus == WHEEL_STATUS_BURST){
|
|
float fwdspeed = Min(contactSpeedFwd, fBurstBikeSpeedMax);
|
|
float fwdspeed = Min(contactSpeedFwd, fBurstBikeSpeedMax);
|
|
#ifdef FIX_BUGS
|
|
|
|
// Keep the effect running at the same frequency even when the game is at high FPS
|
|
|
|
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstBikeTyreMod, fBurstBikeTyreMod) * CTimer::GetLogicalFramesPassed();
|
|
|
|
#else
|
|
|
|
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstBikeTyreMod, fBurstBikeTyreMod);
|
|
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstBikeTyreMod, fBurstBikeTyreMod);
|
|
#endif
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1009,12 +1014,6 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
}
|
|
}
|
|
}else if(contactSpeedFwd != 0.0f){
|
|
}else if(contactSpeedFwd != 0.0f){
|
|
fwd = -contactSpeedFwd/wheelsOnGround;
|
|
fwd = -contactSpeedFwd/wheelsOnGround;
|
|
#ifdef FIX_BUGS
|
|
|
|
// contactSpeedFwd is independent of framerate but fwd has timestep as a factor
|
|
|
|
// so we probably have to fix this
|
|
|
|
fwd *= CTimer::GetTimeStepFix();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!bBraking){
|
|
if(!bBraking){
|
|
if(m_fGasPedal < 0.01f){
|
|
if(m_fGasPedal < 0.01f){
|
|
if(IsBike())
|
|
if(IsBike())
|
|
|
@@ -1025,9 +1024,6 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
brake = 0.2f * mod_HandlingManager.fWheelFriction / m_fMass;
|
|
brake = 0.2f * mod_HandlingManager.fWheelFriction / m_fMass;
|
|
else
|
|
else
|
|
brake = mod_HandlingManager.fWheelFriction / m_fMass;
|
|
brake = mod_HandlingManager.fWheelFriction / m_fMass;
|
|
#ifdef FIX_BUGS
|
|
|
|
brake *= CTimer::GetTimeStepFix();
|
|
|
|
#endif
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1078,6 +1074,10 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
|
|
|
|
float impulse = speed*m_fMass;
|
|
float impulse = speed*m_fMass;
|
|
float turnImpulse = speed*GetMass(wheelContactPoint, direction);
|
|
float turnImpulse = speed*GetMass(wheelContactPoint, direction);
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
impulse = impulse * CTimer::GetTimeStepFix();
|
|
|
|
turnImpulse = turnImpulse * CTimer::GetTimeStepFix();
|
|
|
|
#endif
|
|
CVector vTurnImpulse = turnImpulse * direction;
|
|
CVector vTurnImpulse = turnImpulse * direction;
|
|
ApplyMoveForce(impulse * direction);
|
|
ApplyMoveForce(impulse * direction);
|
|
|
|
|
|
|
|