|
|
@@ -788,7 +788,14 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
|
bAlreadySkidding = false; |
|
|
#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 right = 0.0f; |
|
|
|
|
|
@@ -804,36 +811,30 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
|
bAlreadySkidding = true; |
|
|
*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(); |
|
|
#endif |
|
|
if(bAlreadySkidding) |
|
|
adhesion *= pHandling->fTractionLoss; |
|
|
|
|
|
// moving sideways |
|
|
if(contactSpeedRight != 0.0f){ |
|
|
// exert opposing force |
|
|
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){ |
|
|
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); |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
if(bDriving){ |
|
|
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 > adhesion) |
|
|
right = adhesion; |
|
|
@@ -843,11 +844,6 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
|
} |
|
|
}else if(contactSpeedFwd != 0.0f){ |
|
|
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(m_fGasPedal < 0.01f){ |
|
|
@@ -859,9 +855,6 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
|
brake = 0.2f * mod_HandlingManager.fWheelFriction / pHandling->fMass; |
|
|
else |
|
|
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; |
|
|
} |
|
|
|
|
|
float l = Sqrt(speedSq); |
|
|
float speed = Sqrt(speedSq); |
|
|
float tractionLoss = bAlreadySkidding ? 1.0f : pHandling->fTractionLoss; |
|
|
right *= adhesion * tractionLoss / l; |
|
|
fwd *= adhesion * tractionLoss / l; |
|
|
right *= adhesion * tractionLoss / speed; |
|
|
fwd *= adhesion * tractionLoss / speed; |
|
|
} |
|
|
|
|
|
if(fwd != 0.0f || right != 0.0f){ |
|
|
@@ -923,9 +916,19 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon |
|
|
else |
|
|
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 turnImpulse = turnSpeed*GetMass(wheelContactPoint, turnDirection); |
|
|
|
|
|
#ifdef FIX_BUGS |
|
|
impulse = impulse * CTimer::GetTimeStepFix(); |
|
|
turnImpulse = turnImpulse * CTimer::GetTimeStepFix(); |
|
|
#endif |
|
|
ApplyMoveForce(impulse * direction); |
|
|
ApplyTurnForce(turnImpulse * turnDirection, wheelContactPoint); |
|
|
} |
|
|
@@ -949,7 +952,14 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
|
bAlreadySkidding = false; |
|
|
#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 right = 0.0f; |
|
|
|
|
|
@@ -966,7 +976,12 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
|
bAlreadySkidding = true; |
|
|
*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(); |
|
|
#endif |
|
|
if(bAlreadySkidding) |
|
|
adhesion *= pHandling->fTractionLoss; |
|
|
|
|
|
@@ -979,20 +994,10 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
|
if(contactSpeedRight != 0.0f){ |
|
|
// exert opposing force |
|
|
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){ |
|
|
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); |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
@@ -1009,12 +1014,6 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
|
} |
|
|
}else if(contactSpeedFwd != 0.0f){ |
|
|
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(m_fGasPedal < 0.01f){ |
|
|
if(IsBike()) |
|
|
@@ -1025,9 +1024,6 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee |
|
|
brake = 0.2f * mod_HandlingManager.fWheelFriction / m_fMass; |
|
|
else |
|
|
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 turnImpulse = speed*GetMass(wheelContactPoint, direction); |
|
|
#ifdef FIX_BUGS |
|
|
impulse = impulse * CTimer::GetTimeStepFix(); |
|
|
turnImpulse = turnImpulse * CTimer::GetTimeStepFix(); |
|
|
#endif |
|
|
CVector vTurnImpulse = turnImpulse * direction; |
|
|
ApplyMoveForce(impulse * direction); |
|
|
|
|
|
|