]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Gear.cpp
Use bool where the source and destination variable is bool.
[flightgear.git] / src / FDM / YASim / Gear.cpp
index d56a519a046386498d8e5440773840ba1ea91285..1936c3594bc4016240908396559a8c5565504a7f 100644 (file)
@@ -180,9 +180,13 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
     // First off, make sure that the gear "tip" is below the ground.
     // If it's not, there's no force.
     float a = ground[3] - Math::dot3(_pos, ground);
+    _compressDist = -a;
     if(a > 0) {
        _wow = 0;
        _frac = 0;
+        _compressDist = 0;
+        _rollSpeed = 0;
+        _casterAngle = 0;
        return;
     }
 
@@ -230,10 +234,6 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
     _wow = (fmag - damp) * -Math::dot3(cmpr, ground);
     Math::mul3(-_wow, ground, _force);
 
-    // Castering gear feel no force in the ground plane
-    if(_castering)
-       return;
-
     // Wheels are funky.  Split the velocity along the ground plane
     // into rolling and skidding components.  Assuming small angles,
     // we generate "forward" and "left" unit vectors (the compression
@@ -272,6 +272,19 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
     float vskid  = Math::dot3(cv, skid);
     float wgt = Math::dot3(_force, gup); // force into the ground
 
+    if(_castering) {
+        _rollSpeed = Math::sqrt(vsteer*vsteer + vskid*vskid);
+        // Don't modify caster angle when the wheel isn't moving,
+        // or else the angle will animate the "jitter" of a stopped
+        // gear.
+        if(_rollSpeed > 0.05)
+            _casterAngle = Math::atan2(vskid, vsteer);
+        return;
+    } else {
+        _rollSpeed = vsteer;
+        _casterAngle = _rot;
+    }
+
     float fsteer = _brake * calcFriction(wgt, vsteer);
     float fskid  = calcFriction(wgt, vskid);
     if(vsteer > 0) fsteer = -fsteer;