40 ClassImp(TGLAutoRotator);
45 TGLAutoRotator::TGLAutoRotator(TGLViewer* v) :
46 fViewer(v), fCamera(0),
47 fTimer(new TTimer), fWatch(new TStopwatch),
52 fWTheta(0.15), fATheta(0.5),
53 fWDolly(0.30), fADolly(0.4),
54 fTimerRunning(kFALSE),
55 fImageCount(0), fImageAutoSave(kFALSE),
56 fImageGUIBaseName(
"animation"), fImageGUIOutMode(1)
58 fTimer->Connect(
"Timeout()",
"TGLAutoRotator",
this,
"Timeout()");
64 TGLAutoRotator::~TGLAutoRotator()
74 void TGLAutoRotator::SetDt(Double_t dt)
76 fDt = TMath::Range(0.01, 1.0, dt);
79 fTimer->SetTime(TMath::Nint(1000*fDt));
88 void TGLAutoRotator::SetATheta(Double_t a)
90 a = TMath::Range(0.01, 1.0, a);
93 fThetaA0 = fThetaA0 * a / fATheta;
102 void TGLAutoRotator::SetADolly(Double_t a)
104 a = TMath::Range(0.01, 1.0, a);
107 fDollyA0 = fDollyA0 * a / fADolly;
115 void TGLAutoRotator::Start()
122 fCamera = & fViewer->CurrentCamera();
124 fThetaA0 = fATheta * TMath::PiOver2();
125 fDollyA0 = fADolly * fCamera->GetCamTrans().GetBaseVec(4).Mag();
127 fTimerRunning = kTRUE;
128 fTimer->SetTime(TMath::Nint(1000*fDt));
137 void TGLAutoRotator::Stop()
143 fTimerRunning = kFALSE;
151 void TGLAutoRotator::Timeout()
153 if (!fTimerRunning || gTQSender != fTimer)
155 Error(
"Timeout",
"Not running or not called via timer.");
159 using namespace TMath;
162 Double_t time = fWatch->RealTime();
168 Double_t delta_p = fWPhi*fDt;
169 Double_t delta_t = fThetaA0*fWTheta*Cos(fWTheta*time)*fDt;
170 Double_t delta_d = fDollyA0*fWDolly*Cos(fWDolly*time)*fDt;
171 Double_t th = fCamera->GetTheta();
173 if (th + delta_t > 3.0 || th + delta_t < 0.1416)
176 fCamera->RotateRad(delta_t, delta_p);
177 fCamera->RefCamTrans().MoveLF(1, -delta_d);
180 fViewer->RequestDraw(TGLRnrCtx::kLODHigh);
185 if (fImageName.Contains(
"%"))
187 filename.Form(fImageName, fImageCount);
191 filename = fImageName;
193 fViewer->SavePicture(filename);
204 void TGLAutoRotator::StartImageAutoSaveAnimatedGif(
const TString& filename)
206 if ( ! filename.Contains(
".gif+"))
208 Error(
"StartImageAutoSaveAnimatedGif",
"Name should end with '.gif+'. Not starting.");
212 fImageName = filename;
214 fImageAutoSave = kTRUE;
224 void TGLAutoRotator::StartImageAutoSave(
const TString& filename)
226 if ( ! filename.Contains(
"%"))
228 Error(
"StartImageAutoSave",
"Name should include a '%%' character, like 'image-%%05d.png'. Not starting.");
232 fImageName = filename;
234 fImageAutoSave = kTRUE;
240 void TGLAutoRotator::StopImageAutoSave()
242 fImageAutoSave = kFALSE;
250 void TGLAutoRotator::SetImageGUIOutMode(Int_t m)
254 Warning(
"SetImageGUIOutMode",
"Invalid value, ignoring");
257 fImageGUIOutMode = m;
263 void TGLAutoRotator::StartImageAutoSaveWithGUISettings()
265 if (fImageGUIOutMode == 1)
267 TString name = fImageGUIBaseName +
".gif+";
268 StartImageAutoSaveAnimatedGif(name);
270 else if (fImageGUIOutMode == 2)
272 TString name = fImageGUIBaseName +
"-%05d.png";
273 StartImageAutoSave(name);
277 Warning(
"StartImageAutoSaveWithGUISettings",
"Unsupported mode '%d'.", fImageGUIOutMode);
286 void TGLAutoRotator::RotateScene()
288 TGLViewer::SceneInfoList_t & scenes = fViewer->fScenes;
289 TGLViewer::SceneInfoList_i sceneIter = scenes.begin();
291 for (; sceneIter != scenes.end(); ++sceneIter) {
292 TGLScene::TSceneInfo *sceneInfo =
dynamic_cast<TGLScene::TSceneInfo *
>(*sceneIter);
294 TGLPhysicalShape *axisShape = 0;
295 TGLScene::ShapeVec_i shapeIter = sceneInfo->fShapesOfInterest.begin();
296 for (; shapeIter != sceneInfo->fShapesOfInterest.end(); ++shapeIter) {
297 TGLPhysicalShape *
const testShape =
const_cast<TGLPhysicalShape *
>(*shapeIter);
298 if (testShape && testShape->GetLogical()->ID()->TestBit(13)) {
299 axisShape = testShape;
308 const TGLBoundingBox &bbox = sceneInfo->GetTransformedBBox();
310 center = bbox.Center();
312 axis = axisShape->BoundingBox().Axis(2);
313 center = axisShape->BoundingBox().Center();
316 shapeIter = sceneInfo->fShapesOfInterest.begin();
317 for (; shapeIter != sceneInfo->fShapesOfInterest.end(); ++shapeIter) {
318 if (TGLPhysicalShape *
const shape = const_cast<TGLPhysicalShape *>(*shapeIter))
319 shape->Rotate(center, axis, fDeltaPhi);