TGLAutoRotator.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TGLAutoRotator.cxx 36373 2010-10-19 17:43:35Z matevz $
00002 // Author: Matevz Tadel 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGLAutoRotator.h"
00013 
00014 #include "TGLViewer.h"
00015 #include "TGLCamera.h"
00016 
00017 #include "TMath.h"
00018 #include "TTimer.h"
00019 #include "TStopwatch.h"
00020 
00021 //______________________________________________________________________________
00022 //
00023 // Automatically rotates GL camera.
00024 //
00025 // W's are angular velocities.
00026 // ATheta -- Theta amplitude in units of Pi/2.
00027 // ADolly -- In/out amplitude in units of initial distance.
00028 
00029 ClassImp(TGLAutoRotator);
00030 
00031 //______________________________________________________________________________
00032 TGLAutoRotator::TGLAutoRotator(TGLViewer* v) :
00033    fViewer(v), fCamera(0),
00034    fTimer(new TTimer), fWatch(new TStopwatch),
00035    fDt    (0.01),
00036    fWPhi  (0.40),
00037    fWTheta(0.15), fATheta(0.5),
00038    fWDolly(0.30), fADolly(0.4),
00039    fTimerRunning(kFALSE)
00040 {
00041    // Constructor.
00042 
00043    fTimer->Connect("Timeout()", "TGLAutoRotator", this, "Timeout()");
00044 }
00045 
00046 //______________________________________________________________________________
00047 TGLAutoRotator::~TGLAutoRotator()
00048 {
00049    // Destructor.
00050 
00051    delete fWatch;
00052    delete fTimer;
00053 }
00054 
00055 //==============================================================================
00056 
00057 //______________________________________________________________________________
00058 void TGLAutoRotator::SetDt(Double_t dt)
00059 {
00060    // Set time between two redraws in seconds.
00061    // Range: 0.001 -> 1.
00062 
00063    fDt = TMath::Range(0.01, 1.0, dt);
00064    if (fTimerRunning)
00065    {
00066       fTimer->SetTime(TMath::Nint(1000*fDt));
00067       fTimer->Reset();
00068    }
00069 }
00070 
00071 //______________________________________________________________________________
00072 void TGLAutoRotator::SetATheta(Double_t a)
00073 {
00074    // Set relative amplitude of theta oscilation.
00075    // Value range: 0.01 -> 1.
00076 
00077    a = TMath::Range(0.01, 1.0, a);
00078    if (fTimerRunning)
00079    {
00080       fThetaA0 = fThetaA0 * a / fATheta;
00081    }
00082    fATheta = a;
00083 }
00084 
00085 //______________________________________________________________________________
00086 void TGLAutoRotator::SetADolly(Double_t a)
00087 {
00088    // Set relative amplitude of forward/backward oscilation.
00089    // Value range: 0.01 -> 1.
00090 
00091   a = TMath::Range(0.01, 1.0, a);
00092   if (fTimerRunning)
00093   {
00094      fDollyA0 = fDollyA0 * a / fADolly;
00095   }
00096   fADolly = a;
00097 }
00098 
00099 //==============================================================================
00100 
00101 //______________________________________________________________________________
00102 void TGLAutoRotator::Start()
00103 {
00104    if (fTimerRunning)
00105    {
00106       Stop();
00107    }
00108 
00109    fCamera = & fViewer->CurrentCamera();
00110 
00111    fThetaA0 = fATheta * TMath::PiOver2();
00112    fDollyA0 = fADolly * fCamera->GetCamTrans().GetBaseVec(4).Mag();
00113 
00114    fTimerRunning = kTRUE;
00115    fTimer->SetTime(TMath::Nint(1000*fDt));
00116    fTimer->Reset();
00117    fTimer->TurnOn();
00118    fWatch->Start();
00119 }
00120 
00121 //______________________________________________________________________________
00122 void TGLAutoRotator::Stop()
00123 {
00124    if (fTimerRunning)
00125    {
00126       fWatch->Stop();
00127       fTimer->TurnOff();
00128       fTimerRunning = kFALSE;
00129    }
00130 }
00131 
00132 //______________________________________________________________________________
00133 void TGLAutoRotator::Timeout()
00134 {
00135    if (!fTimerRunning || gTQSender != fTimer)
00136    {
00137       Error("Timeout", "Not running or not called via timer.");
00138       return;
00139    }
00140 
00141    using namespace TMath;
00142 
00143    fWatch->Stop();
00144    Double_t time = fWatch->RealTime();
00145    fWatch->Continue();
00146 
00147    Double_t delta_p = fWPhi*fDt;
00148    Double_t delta_t = fThetaA0*fWTheta*Cos(fWTheta*time)*fDt;
00149    Double_t delta_d = fDollyA0*fWDolly*Cos(fWDolly*time)*fDt;
00150    Double_t th      = fCamera->GetTheta();
00151 
00152    if (th + delta_t > 3.0 || th + delta_t < 0.1416)
00153       delta_t = 0;
00154 
00155    fCamera->RotateRad(delta_t, delta_p);
00156    fCamera->RefCamTrans().MoveLF(1, -delta_d);
00157 
00158    fViewer->RequestDraw(TGLRnrCtx::kLODHigh);
00159 }

Generated on Tue Jul 5 14:18:05 2011 for ROOT_528-00b_version by  doxygen 1.5.1