opengl – Bullet Physics Integration – direct motion of rigid bodies

My usual approach here – and one that seems to work well in VR games and motion control too – is to calculate a speed that will bring the previous position of the object's physical body to the target's desired position in one step of physics.

$$ vec v_ {wanted} = frac { vec p_ {wanted} – vec p_ {previous}} { Delta t} $$

Right here $ Delta t $ is the duration of your physical step, not necessarily your frame time if these are decoupled in your case.

Some APIs allow you to set the velocity directly, canceling other physical effects. However, if you can only apply forces, we must apply acceleration to achieve this. Starting from the equation of motion in constant acceleration …

$$ vec p (t) = vec p (0) + vec v cdot t + vec a cdot frac {t ^ 2} 2 \
vec a_ {net} = 2 cdot frac { vec p_ {wanted} – vec {p_previous} – vec v_ {previous} cdot Delta t} { Delta t ^ 2} $$

This is the net acceleration needed to land at the desired point. If you have other continuous forces acting on that body (like gravity), subtract them to get the intervention acceleration that you need to apply.

Then, to convert this acceleration into a force to apply, you simply need to $ vec F = m cdot vec a $ 😉

You can use a similar strategy to set the angular velocity or apply angular acceleration to synchronize an orientation. You first calculate the difference in orientation between the two:

$$ R_ {difference} = R_ {wanted} cdot {R_ {previous}} ^ {- 1} $$

Then, convert it to an axis-angle representation and set the axis vector to scale according to the angle in radians on the delta time. This gives you your angular velocity to define.