let a shape translate first and then rotate it

Hello there,
l already have a shape . And l want to let this shape translate first and then rotate . Show the whole process in the form of animation.
l have already know need use AIS_AnimationObject class to creat a single animation and add them to AIS_Animation class. And now l can let the shape translate and rotate separately. And the process of rotation or translation is shown in the form of animation.But I want to combine the two transformation,first transalate and then rotate.

gp_Trsf start_pnt1, end_pnt1,start_pnt2,end_pnt2;
(ps:p1,p2,p3 is gp_pnt)
end_pnt1.SetTranslation(p2, p3);//p1,p2,p3is gp_pnt

gp_Vec tempVec = gp_Vec(p1, p2);
gp_Dir tempDir = gp_Dir(tempVec);
gp_Ax1 tempAx1 = gp_Ax1(p1, tempVec);

end_pnt2.SetRotation(tempAx1, 180);

Handle(AIS_Animation) ais_animation = new AIS_Animation("aPipeMaker9");
Handle(AIS_AnimationObject) ais_ao1 = new AIS_AnimationObject("animation1", myOccView->getContext(), wireshow9, start_pnt1, end_pnt1);
Handle(AIS_AnimationObject) ais_ao2 = new AIS_AnimationObject("animation2", myOccView->getContext(), wireshow9, start_pnt2, end_pnt2);
(ps: wireshow9 is my shape)
here is my code . But the results were bad. what should l do ?
Thanks in advance

Kirill Gavrilov's picture

AIS_AnimationObject defines animation between two object locations. Putting into animation pipeline two instances of AIS_AnimationObject for the same object and timestamps makes no sense as one animation will override another.

Normally, you need defining a single AIS_AnimationObject with a final gp_Trsf aggregating translations/rotations/scale components. How this gp_Trsf should be computed depends on required result.

If you indeed want to create an animation that first translates and then rotates an object, then you need setting starting time AIS_Animation::StartPts() of the second animation to the end of first animation basing on its own duration AIS_Animation::OwnDuration() and start time. Note that normally you always need to set animation duration.

In general case of non-standard object transformation, you can either sublcass AIS_AnimationObject and define own transformation math, or split transformation into several small parts with each one defined by precomputed gp_Trsf.

pload MODELING VISUALIZATION

# show origin
vtrihedron t0

# make a box
box b 100 20 20
vdisplay -dispMode 1 b
vfit; vzoom 0.5

# play with transformations
# translate within -DX direction
# and then rotate around DY axis
vlocation b -reset
vlocation b -translate -50 0 0
vlocation b -rotate 0 0 0 0 1 0 90
# dump final transformation
vlocation b

# define box animation
vlocation b -reset
vanim a -object b -loc1 0 0 0 -loc2 0 0 50 -rot1 0 0 0 1 -rot2 0 0.707107 0 0.707107 -duration 10
vanim a -play
Attachments: