One of the problems here is that gp_Trsf defined from axis and rotation angle does not keeps transformation path, only final result which is decomposed in a different way. AIS_AnimationObject performs linear interpolation between two gp_Trsf decomposed into translation, rotation and scale parts.
There are several options to achieve desired animation:
- Define an object from an origin matching rotation axis.
- Subclass AIS_Animation and define your own transformation logic.
- Decompose a complex transformation into several smaller steps.
class MyRotateAnimation : public AIS_AnimationObject
{
public:
MyRotateAnimation (const TCollection_AsciiString& theName,
const Handle(AIS_InteractiveContext)& theCtx,
const Handle(AIS_InteractiveObject)& thePrs)
: AIS_AnimationObject (theName, theCtx, thePrs, gp_Trsf(), gp_Trsf())
{
//
}
void SetRotation (const gp_Ax1& theAxis, double theAngle)
{
myAxis = theAxis;
myAngle = theAngle;
}
protected:
virtual void update (const AIS_AnimationProgress& theProgress) override
{
double aCurrentAngle = theProgress.LocalNormalized * myAngle;
gp_Trsf aTrsf;
aTrsf.SetRotation (myAxis, myAngle);
myContext->SetLocation (myObject, aTrsf);
invalidateViewer();
}
private:
gp_Ax1 myAxis;
double myAngle;
};