Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. public void ApplyWheelConstraint(Wheel wheel, float dt)
  2. {
  3.     Vector offset = ToWorld(wheel.mPosition);
  4.     Vector groundVel = PointVel(offset);
  5.     Vector patchDir = ToWorld(wheel.PatchDir());
  6.     Vector constraintDir = ToWorld(wheel.ConstraintDir());
  7.     Vector deltaV = -groundVel.Project(constraintDir);
  8.     Vector dir = deltaV;
  9.     float mag = 0.0f;
  10.     dir.Normalize(out mag);
  11.  
  12.     if (mag < 0.1f)
  13.         wheel.mStaticFriction = true;
  14.     else if (wheel.mStaticFriction)
  15.     {
  16.         float acc = wheel.mAcceleration.mValue.Length;
  17.         float maxAcc = cGravity * wheel.Friction();
  18.         if (acc > maxAcc)
  19.             wheel.mStaticFriction = false;
  20.     }
  21.  
  22.     mag *= wheel.Friction();
  23.  
  24.     Vector impulse = ChangePointVel( dt, offset, dir, mag );
  25.  
  26.     wheel.mAngVel = groundVel.Dot(patchDir) / wheel.mRadius;
  27.     //wheel.mAcceleration.mValue = deltaV / dt; //Direct
  28.     wheel.mAcceleration.Add( deltaV / dt, 0.2f ); //Interpolated
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement