void SimWheelUpdateRotation(tCar *car) { int i; tWheel *wheel; tdble deltan; tdble cosaz, sinaz; for (i = 0; i < 4; i++) { wheel = &(car->wheel[i]); /*calculate gyroscopic forces*/ cosaz = cos(wheel->relPos.az); sinaz = sin(wheel->relPos.az); if( (i == 0) || (i == 1) ){ wheel->torques.y = wheel->torques.x * sinaz; wheel->torques.x = wheel->torques.x * cosaz; } else { wheel->torques.x = wheel->torques.y =0.0; } deltan = -(wheel->in.spinVel - wheel->prespinVel) * wheel->I / SimDeltaTime; wheel->torques.x -= deltan * wheel->cosax *sinaz; wheel->torques.y += deltan * wheel->cosax *cosaz; wheel->torques.z = deltan * wheel->sinax; /*update rotation*/ wheel->spinVel = wheel->in.spinVel; FLOAT_RELAXATION2(wheel->spinVel, wheel->prespinVel, 50.0f); wheel->relPos.ay += wheel->spinVel * SimDeltaTime; FLOAT_NORM_PI_PI(wheel->relPos.ay); car->carElt->_wheelSpinVel(i) = wheel->spinVel; } }
void SimWheelUpdateRotation(tCar *car) { int i; tWheel *wheel; for (i = 0; i < 4; i++) { wheel = &(car->wheel[i]); wheel->spinVel = wheel->in.spinVel; FLOAT_RELAXATION2(wheel->spinVel, wheel->prespinVel, 50.0f); wheel->relPos.ay += wheel->spinVel * SimDeltaTime; FLOAT_NORM_PI_PI(wheel->relPos.ay); car->carElt->_wheelSpinVel(i) = wheel->spinVel; } }
void SimWheelUpdateForce(tCar *car, int index) { tWheel *wheel = &(car->wheel[index]); tdble axleFz = wheel->axleFz; tdble vt, v, v2, wrl; // wheel related velocity tdble Fn, Ft; tdble waz; tdble CosA, SinA; tdble s, sa, sx, sy; // slip vector tdble stmp, F, Bx; tdble mu; tdble reaction_force = 0.0f; wheel->state = 0; // VERTICAL STUFF CONSIDERING SMALL PITCH AND ROLL ANGLES // update suspension force SimSuspUpdate(&(wheel->susp)); // check suspension state wheel->state |= wheel->susp.state; if ((wheel->state & SIM_SUSP_EXT) == 0) { wheel->forces.z = axleFz + wheel->susp.force; reaction_force = wheel->forces.z; wheel->rel_vel -= SimDeltaTime * wheel->susp.force / wheel->mass; if (wheel->forces.z < 0.0f) { wheel->forces.z = 0.0f; } } else { if (wheel->rel_vel < 0.0) { wheel->rel_vel = 0.0; } wheel->rel_vel -= SimDeltaTime * wheel->susp.force / wheel->mass; wheel->forces.z = 0.0f; } // update wheel coord, center relative to GC wheel->relPos.z = - wheel->susp.x / wheel->susp.spring.bellcrank + wheel->radius; // HORIZONTAL FORCES waz = wheel->steer + wheel->staticPos.az; CosA = cos(waz); SinA = sin(waz); // tangent velocity. vt = wheel->bodyVel.x * CosA + wheel->bodyVel.y * SinA; v2 = wheel->bodyVel.x * wheel->bodyVel.x + wheel->bodyVel.y * wheel->bodyVel.y; v = sqrt(v2); // slip angle if (v < 0.000001f) { sa = 0.0f; } else { sa = atan2(wheel->bodyVel.y, wheel->bodyVel.x) - waz; } FLOAT_NORM_PI_PI(sa); wrl = wheel->spinVel * wheel->radius; if ((wheel->state & SIM_SUSP_EXT) != 0) { sx = sy = 0.0f; } else if (v < 0.000001f) { sx = wrl; sy = 0.0f; } else { sx = (vt - wrl) / fabs(vt); sy = sin(sa); } Ft = 0.0f; Fn = 0.0f; s = sqrt(sx*sx+sy*sy); { // calculate _skid and _reaction for sound. if (v < 2.0f) { car->carElt->_skid[index] = 0.0f; } else { car->carElt->_skid[index] = MIN(1.0f, (s*reaction_force*0.0002f)); } car->carElt->_reaction[index] = reaction_force; } stmp = MIN(s, 1.5f); // MAGIC FORMULA Bx = wheel->mfB * stmp; F = sin(wheel->mfC * atan(Bx * (1.0f - wheel->mfE) + wheel->mfE * atan(Bx))) * (1.0f + stmp * simSkidFactor[car->carElt->_skillLevel]); // load sensitivity mu = wheel->mu * (wheel->lfMin + (wheel->lfMax - wheel->lfMin) * exp(wheel->lfK * wheel->forces.z / wheel->opLoad)); F *= wheel->forces.z * mu * wheel->trkPos.seg->surface->kFriction * (1.0f + 0.05f * sin(-wheel->staticPos.ax * 18.0f)); /* coeff */ //For debug weather with some tracks #ifdef SD_DEBUG GfLogDebug("Simu v2 kFriction : %f ", wheel->trkPos.seg->surface->kFriction); #endif wheel->rollRes = wheel->forces.z * wheel->trkPos.seg->surface->kRollRes; car->carElt->priv.wheel[index].rollRes = wheel->rollRes; if (s > 0.000001f) { // wheel axis based Ft -= F * sx / s; Fn -= F * sy / s; } FLOAT_RELAXATION2(Fn, wheel->preFn, 50.0f); FLOAT_RELAXATION2(Ft, wheel->preFt, 50.0f); wheel->relPos.az = waz; wheel->forces.x = Ft * CosA - Fn * SinA; wheel->forces.y = Ft * SinA + Fn * CosA; wheel->spinTq = Ft * wheel->radius; wheel->sa = sa; wheel->sx = sx; wheel->feedBack.spinVel = wheel->spinVel; wheel->feedBack.Tq = wheel->spinTq; wheel->feedBack.brkTq = wheel->brake.Tq; car->carElt->_wheelSlipSide(index) = sy*v; car->carElt->_wheelSlipAccel(index) = sx*v; car->carElt->_reaction[index] = reaction_force; }