simuv2 bug fix
Brian Martin <[email protected]>
| Newsgroups | gmane.games.torcs.general |
|---|---|
| Message-ID | <[email protected]> |
Ok, it's a kludge, not really a fix for some cars being
positioned wrong on the track. You can reproduce this problem with the xml
file i provided in my previous post. The problem is in wheel.cpp in
SimWheelUpdateRide().
The problem manifests itself when
new_susp_x=prexwheel - wheel->rel_vel * SimDeltaTime;
generates a wrong value for new_susp_x. I would like to have a real
solution to this
problem. The code changes are just a work around for the problem. I am
not familiar
enough with the torcs code to even know where to begin looking for the
root of this problem.
Here is the code:
void SimWheelUpdateRide(tCar *car, int index)
{
tWheel *wheel = &(car->wheel[index]);
tdble Zroad;
// compute suspension travel
RtTrackGlobal2Local(car->trkPos.seg, wheel->pos.x, wheel->pos.y,
&(wheel->trkPos), TR_LPOS_SEGMENT);
wheel->zRoad = Zroad = RtTrackHeightL(&(wheel->trkPos));
// Wheel susp.x is not the wheel movement, look at SimSuspCheckIn,
it becomes there scaled with
// susp->spring.bellcrank, so we invert this here.
tdble prexwheel = wheel->susp.x / wheel->susp.spring.bellcrank;
tdble new_susp_x= prexwheel - wheel->rel_vel * SimDeltaTime;
tdble max_extend = wheel->pos.z - Zroad;
wheel->rideHeight = max_extend;
//////////////////////test///////////////////
tdble prex = wheel->susp.x;
//////////////////////////////////////////////////
if (max_extend < wheel->susp.x) {
wheel->susp.x = max_extend;
wheel->rel_vel = 0.0f;
} else if (wheel->susp.x < wheel->susp.spring.packers) {
//////////////test (fixes elevated car at race start for most
cars)///
//wheel->susp.x = wheel->susp.spring.packers;
/////////////////////////////////////////////////////
wheel->rel_vel = 0.0f;
///////////////test fixes all mispositioned car problems/////
wheel->susp.x = wheel->pos.z - Zroad;
}else if (wheel->rel_vel != 0.0f){
wheel->susp.x = new_susp_x;
}else{
wheel->susp.x = wheel->pos.z - Zroad;
}
//////////////////////////////////////////////////////////////
// tdble prex = wheel->susp.x;
// wheel->susp.x = new_susp_x;
// verify the suspension travel, beware, wheel->susp.x will be
scaled by SimSuspCheckIn
SimSuspCheckIn(&(wheel->susp));
wheel->susp.v = (prex - wheel->susp.x) / SimDeltaTime;
// update wheel brake
SimBrakeUpdate(car, wheel, &(wheel->brake));
}
Thank you.
brian
------------------------------------------------------------------------------