31 ClassImp(TGLOrthoCamera);
33 UInt_t TGLOrthoCamera::fgZoomDeltaSens = 500;
38 TGLOrthoCamera::TGLOrthoCamera() :
39 TGLCamera(TGLVector3( 0.0, 0.0, 1.0), TGLVector3(0.0, 1.0, 0.0)),
41 fEnableRotate(kFALSE), fDollyToZoom(kTRUE),
42 fZoomMin(0.001), fZoomDefault(0.78), fZoomMax(1000.0),
43 fVolume(TGLVertex3(-100.0, -100.0, -100.0), TGLVertex3(100.0, 100.0, 100.0)),
46 Setup(TGLBoundingBox(TGLVertex3(-100,-100,-100), TGLVertex3(100,100,100)));
52 TGLOrthoCamera::TGLOrthoCamera(EType type,
const TGLVector3 & hAxis,
const TGLVector3 & vAxis) :
53 TGLCamera(hAxis, vAxis),
55 fEnableRotate(kFALSE), fDollyToZoom(kTRUE),
56 fZoomMin(0.001), fZoomDefault(0.78), fZoomMax(1000.0),
57 fVolume(TGLVertex3(-100.0, -100.0, -100.0), TGLVertex3(100.0, 100.0, 100.0)),
60 Setup(TGLBoundingBox(TGLVertex3(-100,-100,-100), TGLVertex3(100,100,100)));
66 TGLOrthoCamera::~TGLOrthoCamera()
74 void TGLOrthoCamera::Setup(
const TGLBoundingBox & box, Bool_t reset)
78 if (fExternalCenter == kFALSE)
82 SetCenterVec(fFDCenter.X(), fFDCenter.Y(), fFDCenter.Z());
86 TGLVertex3 center = box.Center();
87 SetCenterVec(center.X(), center.Y(), center.Z());
98 void TGLOrthoCamera::Reset()
100 TGLVector3 e = fVolume.Extents();
106 fDefXSize = e.X(); fDefYSize = e.Y();
113 fDefXSize = e.X(); fDefYSize = e.Z();
121 fDefXSize = e.Z(); fDefYSize = e.Y();
128 fDefXSize = e.Z(); fDefYSize = e.X();
133 fDollyDefault = 1.25*0.5*TMath::Sqrt(3)*fVolume.Extents().Mag();
134 fDollyDistance = 0.002 * fDollyDefault;
135 fZoom = fZoomDefault;
136 fCamTrans.SetIdentity();
137 fCamTrans.MoveLF(1, fDollyDefault);
146 Bool_t TGLOrthoCamera::Dolly(Int_t delta, Bool_t mod1, Bool_t mod2)
149 return Zoom(delta, mod1, mod2);
151 return TGLCamera::Dolly(delta, mod1, mod2);
168 Bool_t TGLOrthoCamera::Zoom(Int_t delta, Bool_t mod1, Bool_t mod2)
170 if (AdjustAndClampVal(fZoom, fZoomMin, fZoomMax, -delta*2, fgZoomDeltaSens, mod1, mod2))
185 void TGLOrthoCamera::SetZoomMin(Double_t z)
188 if (fZoom < fZoomMin) {
198 void TGLOrthoCamera::SetZoomMax(Double_t z)
201 if (fZoom > fZoomMax) {
211 Bool_t TGLOrthoCamera::Truck(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
213 Double_t xstep = 2.0 * xDelta / fProjM[0] / fViewport.Width();
214 Double_t ystep = 2.0 * yDelta / fProjM[5] / fViewport.Height();
216 xstep = AdjustDelta(xstep, 1.0, mod1, mod2);
217 ystep = AdjustDelta(ystep, 1.0, mod1, mod2);
219 return Truck(-xstep, -ystep);
226 Bool_t TGLOrthoCamera::Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
229 return TGLCamera::Rotate(xDelta, yDelta, mod1, mod2);
246 void TGLOrthoCamera::Apply(
const TGLBoundingBox & ,
247 const TGLRect * pickRect)
const
249 glViewport(fViewport.X(), fViewport.Y(), fViewport.Width(), fViewport.Height());
251 if(fViewport.Width() == 0 || fViewport.Height() == 0)
253 glMatrixMode(GL_PROJECTION);
255 glMatrixMode(GL_MODELVIEW);
260 glMatrixMode(GL_PROJECTION);
266 TGLRect rect(*pickRect);
267 WindowToViewport(rect);
268 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
269 (Int_t*) fViewport.CArr());
272 Double_t halfRangeX, halfRangeY;
273 if (fDefYSize*fViewport.Width()/fDefXSize > fViewport.Height()) {
274 halfRangeY = 0.5 *fDefYSize;
275 halfRangeX = halfRangeY*fViewport.Width()/fViewport.Height();
277 halfRangeX = 0.5 *fDefXSize;
278 halfRangeY = halfRangeX*fViewport.Height()/fViewport.Width();
284 fNearClip = 0.05*fDollyDefault;
285 fFarClip = 2.0*fDollyDefault;
286 glOrtho(-halfRangeX, halfRangeX,
287 -halfRangeY, halfRangeY,
288 fNearClip, fFarClip);
290 if (!pickRect) glGetDoublev(GL_PROJECTION_MATRIX, fLastNoPickProjM.Arr());
293 glMatrixMode(GL_MODELVIEW);
295 TGLMatrix mx = fCamBase*fCamTrans;
296 TGLVector3 pos = mx.GetTranslation();
297 TGLVector3 fwd = mx.GetBaseVec(1);
298 TGLVector3 center = pos - fwd;
299 TGLVector3 up = mx.GetBaseVec(3);
301 gluLookAt(pos[0], pos[1], pos[2],
302 center[0], center[1], center[2],
303 up[0], up[1], up[2]);
305 if (fCacheDirty) UpdateCache();
316 void TGLOrthoCamera::Configure(Double_t zoom, Double_t dolly, Double_t center[3],
317 Double_t hRotate, Double_t vRotate)
322 SetCenterVec(center[0], center[1], center[2]);
324 fCamTrans.MoveLF(1, dolly);
325 RotateRad(hRotate, vRotate);