HOW TO USE AIS_Animation WITH interactive?

TopoDS_Shape obj1 = BRepPrimAPI_MakeBox(100, 500, 20);
Handle(AIS_Shape) ais_obj1 = new AIS_Shape(obj1);
g_pDoc->myAISContext->Display(ais_obj1, true);

gp_Trsf start_pnt, end_pnt;

start_pnt.SetValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0);
end_pnt.SetValues(1, 0, 0, 100, 0, 1, 0, 100, 0, 0, 1, 100);

Handle(AIS_Animation) ais_animation = new AIS_Animation("obj1");
Handle(AIS_AnimationObject) ais_ao = new AIS_AnimationObject("obj1", g_pDoc->myAISContext, ais_obj1, start_pnt, end_pnt);
ais_ao->SetOwnDuration(10);
ais_ao->SetStartPts(0);

ais_animation->Add(ais_ao);

double duration = ais_animation->Duration();

ais_animation->StartTimer(0, 1.0, true);

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

g_pDoc->myAISContext->UpdateCurrentViewer();
}

I use this code in my project, it can run correctly, but i cannot interactive,like rotate select!

Kirill Gavrilov's picture

Making an infinite loop prevents application handling user input events - hense, no camera interactions until animation timer is finished in your code.
Take a look onto AIS_Animation documentation:

Note, that AIS_Animation::StartTimer() defines a timer calculating an elapsed time, not a multimedia timer executing Viewer updates at specific intervals!
Application should avoid using implicit and immediate Viewer updates to ensure that AIS_Animation::UpdateTimer() is called before each redrawing of a Viewer content. Redrawing logic should be also managed at application level for managing a smooth animation (by defining a multimedia timer provided by used GUI framework executing updates at desired framerate, or as continuous redraws in loop).