I've just made an aircraft aerodynamic model coupled with Bullet. It applies aerodynamic forces on a rigid body generated by the wings to simulate flight.
To increase the precision of the velocity integration in btRigidBody I have a suggestion to use a two-step Adams-Bashford method instead of the current Euler method.
It does not add much extra code or cpu cycles and I've got a working code example here:
Code: Select all
(btRigidBody.cpp)
void btRigidBody::integrateVelocities(btScalar step)
{
if (isStaticOrKinematicObject())
return;
// Adams-Bashford method for integration
btVector3 accel = m_totalForce*m_inverseMass;
btVector3 angular_accel = m_invInertiaTensorWorld*m_totalTorque;
btScalar hs = 0.5*step;
m_linearVelocity += hs*(3.0*accel - m_previousAccel);
m_angularVelocity += hs*(3.0*angular_accel - m_previousAngularAccel);
m_previousAccel = accel;
m_previousAngularAccel = angular_accel;
// Euler method:
// m_linearVelocity += m_totalForce * (m_inverseMass * step);
// m_angularVelocity += m_invInertiaTensorWorld * m_totalTorque * step;
#define MAX_ANGVEL SIMD_HALF_PI
/// clamp angular velocity. collision calculations will fail on higher angular velocities
btScalar angvel = m_angularVelocity.length();
if (angvel*step > MAX_ANGVEL)
{
m_angularVelocity *= (MAX_ANGVEL/step) /angvel;
}
clearForces();
}
Code: Select all
btVector3 m_previousAccel;
btVector3 m_previousAngularAccel;
Here's more on the method: http://en.wikipedia.org/wiki/Linear_multistep_method
What do you think?
As an alternative I'd be very happy just to have the integrateVelocities function to be defined as virtual in btRigidBody.h. That way I can replace it myself without maintaining my own version of Bullet.
Best regards,
Ola