Hi,
I find that for damping values > 1.0f, velocity values are dependent on time step.
After going through the damping implementation details, I found that following scheme works independent of time step and unconditionally stable (implicit scheme).
// Applying force and damping
// ODE: m * dv/dt = F - c * v
// using Implicit difference scheme : m * (v(t+dt)-v(t))/dt = F - c * v(t+dt)
// Rearranging: (1 + c/m*dt)*v(t+dt) = (F/m*dt + v(t))
// v(t+dt) = (v(t) + F/m*dt) / (1 + c/m*dt)
v.x = (v.x + h * (b.m_gravityScale * gravity.x + b.m_invMass * b.m_force.x))/(1 + b.m_linearDamping * h);
v.y = (v.y + h * (b.m_gravityScale * gravity.y + b.m_invMass * b.m_force.y))/(1 + b.m_linearDamping * h);
w = (w + h * b.m_invI * b.m_torque)/(1 + b.m_angularDamping*h);
Please give your inputs, whether this implementation is ok?
Thanks
Rajesh
I find that for damping values > 1.0f, velocity values are dependent on time step.
After going through the damping implementation details, I found that following scheme works independent of time step and unconditionally stable (implicit scheme).
// Applying force and damping
// ODE: m * dv/dt = F - c * v
// using Implicit difference scheme : m * (v(t+dt)-v(t))/dt = F - c * v(t+dt)
// Rearranging: (1 + c/m*dt)*v(t+dt) = (F/m*dt + v(t))
// v(t+dt) = (v(t) + F/m*dt) / (1 + c/m*dt)
v.x = (v.x + h * (b.m_gravityScale * gravity.x + b.m_invMass * b.m_force.x))/(1 + b.m_linearDamping * h);
v.y = (v.y + h * (b.m_gravityScale * gravity.y + b.m_invMass * b.m_force.y))/(1 + b.m_linearDamping * h);
w = (w + h * b.m_invI * b.m_torque)/(1 + b.m_angularDamping*h);
Please give your inputs, whether this implementation is ok?
Thanks
Rajesh