00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00024
00025
00026
00027
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
00042
00043 fTimer->Connect("Timeout()", "TGLAutoRotator", this, "Timeout()");
00044 }
00045
00046
00047 TGLAutoRotator::~TGLAutoRotator()
00048 {
00049
00050
00051 delete fWatch;
00052 delete fTimer;
00053 }
00054
00055
00056
00057
00058 void TGLAutoRotator::SetDt(Double_t dt)
00059 {
00060
00061
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
00075
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
00089
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 }