Code:
void CAR::updateAction(btCollisionWorld* collisionWorld, btScalar dt)
{
// cardynamics run then times faster then bullet
const float num_repeats = 10;
const float internal_dt = dt / num_repeats;
// overwrite vdrift pose/velocities with bullet calculation
UpdateDynamics();
// init deltaAngularVelocity (contains sum over all delta Velocities in substeps)
MATHVECTOR<float, 3> newAngularVelocity = dynamics.GetBody().GetAngularVelocity();
MATHVECTOR<float, 3> oldPosition = dynamics.GetBody().GetPosition();
//double old_force = force_feedback;
//force_feedback = 0;
UpdateWheelContacts();
// apply several vdrift steps (cause frequency must be very high for a vehicle)
for(int i = 0; i < num_repeats; ++i)
{
// get the new engine and so on sounds
//UpdateSounds(internal_dt);
//force_feedback += GetFeedback();
// set forward the vdrift physics
InterpolateWheelContacts();
TickPhysics(internal_dt);
// accumulate delta velocity
newAngularVelocity = newAngularVelocity + dynamics.GetBody().GetAngularVelocity();
}
newAngularVelocity = dynamics.GetBody().GetAngularVelocity();//deltaAngularVelocity / (num_repeats + 1);
//force_feedback /= num_repeats;
MATHVECTOR<float, 3> newPosition = dynamics.GetBody().GetPosition();
MATHVECTOR<float, 3> newVelocity = dynamics.GetBody().GetVelocity();//(newPosition - oldPosition) / dt;
// update the Bullet angular and linear Velocities: This is the only connection from Vdrift to bullet
UpdateChassis(newVelocity, newAngularVelocity);
}
Oh, I am interpolating wheel contacts(plane approximation) in the inner loop.
And the simulation dt depends on the framerate atm.
The original wheel forces code contains some bugs I tried to fix in my "elchtest" modification.