Safer calculation of wheelSlipOpt.

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6291 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: b3f32eb847806cd7d6e4747018f6eee69aeb6a14
Former-commit-id: 86818190869299dcae830446b6e20f7a8ced7d0e
This commit is contained in:
kakukri 2015-11-29 22:57:57 +00:00
parent aca8dfab70
commit 49afb9e126

View file

@ -155,24 +155,25 @@ SimWheelConfig(tCar *car, int index)
/* calculate optimal slip value */
tdble s, Bx, low, high;
int i;
//wheel->mfC * atan(Bx * (1.0f - wheel->mfE) + wheel->mfE * atan(Bx))
Bx = PI_2 / wheel->mfC;
low = high = Bx;
while (wheel->mfC * atan(low * (1.0f - wheel->mfE) + wheel->mfE * atan(low)) > PI_2) {
low *= 0.9;
}
while (wheel->mfC * atan(high * (1.0f - wheel->mfE) + wheel->mfE * atan(high)) < PI_2) {
high *=1.1;
}
for (i = 0; i < 32; i++) {
Bx = 0.5 * (low + high);
if (wheel->mfC * atan(Bx * (1.0f - wheel->mfE) + wheel->mfE * atan(Bx)) < PI_2) {
low = Bx;
} else {
high = Bx;
//wheel->mfC * atan(Bx * (1.0f - wheel->mfE) + wheel->mfE * atan(Bx)) == PI/2
low = 0.0;
high = wheel->mfB;
if (wheel->mfC * atan(high * (1.0f - wheel->mfE) + wheel->mfE * atan(high)) < PI_2) {
/* tire parameters are unphysical*/
s = 1.0;
GfLogWarning("Tire magic curve parameters are unphysical!");
} else {
for (i = 0; i < 32; i++) {
Bx = 0.5 * (low + high);
if (wheel->mfC * atan(Bx * (1.0f - wheel->mfE) + wheel->mfE * atan(Bx)) < PI_2) {
low = Bx;
} else {
high = Bx;
}
}
s = 0.5 * (low + high) / wheel->mfB;
}
s = 0.5 * (low + high) / wheel->mfB;
car->carElt->_wheelSlipOpt(index) = s;
}