AIS_Animation:How to rotation arround an axis parallel to the Y-axis

I want to make the shape rotate around an axis parallel to the Y-axis.
The final result is right,but the animation process is wrong,the shape will translate and rotate in the same time.It's because the shape will first dot translate Mat to XYZ then rotate then translate to the original position?
How to deal it? please

Best regard.

gp_Trsf start_pnt, end_pnt;

gp_Vec tempVec = gp_Vec(0,1,0);
gp_Ax1 tempAx1 = gp_Ax1(gp_Pnt(10,0,0), tempVec);

end_pnt.SetRotation(tempAx1, 1.57);

Handle(AIS_Animation) ais_animation = new AIS_Animation("obj1");
Handle(AIS_AnimationObject) ais_ao = new AIS_AnimationObject("obj1", m_occView->getOpenCascadeCtrl()->GetAISContext(), shapeDoor, start_pnt, end_pnt);

ais_ao->SetOwnDuration(0.5);
ais_animation->Add(ais_ao);

double duration = ais_animation->Duration();
ais_animation->StartTimer(0, 1.0, true);

while (!ais_animation->IsStopped())
{
ais_animation->UpdateTimer();

m_occView->getOpenCascadeCtrl()->GetAISContext()->UpdateCurrentViewer();
}

Kirill Gavrilov's picture

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;
};