[ad_1]
This is a classical management downside. You wish to create a suggestions loop that takes the divergence from optimum place and applies the suitable torque to nudge it again into place.
btQuaternion targetOrientation = // no matter you want
btQuaternion currentOrientation = myObject->getOrientation();
Getting the delta orientation is kind of easy, you might want to discover the “distinction” between two the quaternions goal and present orientation.
btQuaternion deltaOrientation = targetOrientation * currentOrientation.inverse();
Unfortunately this quaterion doesn’t say a lot about any divergence that we are able to use.
But in case you convert this delta orientation into euler angles.
btVector3 deltaEuler = QuaternionToEulerXYZ(deltaOrientation );
You mainly get the scaled inverse of the torque you wish to apply. Now you “simply” want to seek out an acceptable quantity to ease it in.
btVector torqueToApply = management(-deltaEuler);
The easy answer is to multiply it with an element. You might have to mess around with the issue till you discover a good worth.
// easy proportional controller
btVector management(btVector in)
{
// mess around with the issue till you discover a matching one
static Kp = 0.5;
return in * Kp;
}
You may additionally wish to look right into a PID-Controller to get a smoother extra responsive easing.
[ad_2]