
Fri, 07/09/2021 - 05:45
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
Sat, 07/10/2021 - 12:06
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.
Sat, 06/08/2024 - 06:04
Hi,Luyu:
I have the same code with you for the rotation of animation.but,it run is not I expect,the Shape not rotate around the defined AX as I expect,the radius all is not as expection,it run on OCC7.1.
Handle(AIS_Shape) ashapeb = new AIS_Shape(tshapea);
ashapeb->SetColor(Quantity_NOC_RED);
myAISContext->Display(ashapeb, true);
//gp_Ax2 ax2 = gp_Ax2(gpe, gp_Dir(0, 0, 1));
gp_Ax2 ax2 = gp_Ax2(lastposition, gp_Dir(0, 0, 1));
//DisplayTrihedron(ax2);
gp_Trsf trsfb;
//trsfb.SetRotation(ax2.Axis(), 4*M_PI_2);
trsfb.SetRotation(ax2.Axis(), 2 * M_PI_2);
Handle(AIS_Animation) ais_animation = new AIS_Animation("obj1");
gp_Trsf sTrsf = shape->LocalTransformation();
Handle(AIS_AnimationObject) ani_object = new AIS_AnimationObject("obj1", myAISContext, shape, sTrsf, trsfb);
//ani_object->SetOwnDuration(0.5);//动画持续时间,也就是从起始变化到截至状态的动画演示持续时间,单位应该是秒
ani_object->SetOwnDuration(2);
ais_animation->Add(ani_object);
//AIS_Animation::OwnDuration();
double duration = ais_animation->Duration();
ais_animation->StartTimer(0, 1.0, true);
while (!ais_animation->IsStopped())
{
ais_animation->UpdateTimer();
myAISContext->UpdateCurrentViewer();
}
So,Could you give me any suggestion?
Jason