TGeoVolume *bigTorus = 0; TGeoVolume *smallTorus = 0; void create_geometry() { TCanvas *c1 = new TCanvas("c1"); new TGeoManager("geo", "geo"); TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7); TGeoMedium *med = new TGeoMedium("MED",1,mat); TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100); gGeoManager->SetTopVolume(top); // define shape components with names bigTorus = gGeoManager->MakeTorus("torus1", med, 45., 5., 10.); bigTorus->SetLineColor(kRed); smallTorus = gGeoManager->MakeTorus("torus2", med, 25., 4., 8.); smallTorus->SetLineColor(kCyan); top->AddNode(bigTorus, 1); top->AddNode(smallTorus, 1); gGeoManager->CloseGeometry(); gGeoManager->SetNsegments(40); top->Draw("ogl"); } TTimer timer(30); void kill_timer(const char *message) { std::cout<<"Animation was stopped: "<GetListOfCanvases()->FindObject("c1")) return kill_timer("canvas was closed."); //Workaround - CINT's dynamic_cast does not work. //TGLViewer *viewer = dynamic_cast(gPad->GetViewer3D()); TGLViewer * viewer = 0; if (gPad->GetViewer3D()->InheritsFrom("TGLViewer")) viewer = static_cast(gPad->GetViewer3D()); else return kill_timer("no gl-viwer."); if (viewer->GetHackedShapesNumber() != 2) return kill_timer("unexpected number of shapes in gl-scene."); TGLPhysicalShape *bigTorusGL = 0; TGLPhysicalShape *smallTorusGL = 0; TGLPhysicalShape **shapes = viewer->GetHackedShapes(); TGeoVolume *testVolume = static_cast(shapes[0]->GetLogical().GetExternal()); testVolume == bigTorus ? bigTorusGL = shapes[0] : testVolume == smallTorus ? smallTorusGL = shapes[0] : 0; testVolume = static_cast(shapes[1]->GetLogical().GetExternal()); testVolume == bigTorus ? bigTorusGL = shapes[1] : testVolume == smallTorus ? smallTorusGL = shapes[1] : 0; if (!smallTorusGL || !bigTorusGL) return kill_timer("unknown shapes in gl scene."); smallTorusGL->Rotate(rotationCenter, rotationAxis, angle); bigTorusGL->Rotate(rotationCenter, rotationAxis, -angle); viewer->RequestDraw(TGLDrawFlags::kLODMed);//kLODHigh } void animation() { gSystem->Load("libGeom"); create_geometry(); timer.SetCommand("animate_geometry()"); timer.TurnOn(); }