00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TGLCamera
00013 #define ROOT_TGLCamera
00014
00015 #include "TGLUtil.h"
00016 #include "TGLBoundingBox.h"
00017 #include "TPoint.h"
00018
00019 #include <cassert>
00020 #include <cmath>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 class TGLCamera
00043 {
00044 public:
00045 enum EFrustumPlane
00046 {
00047 kNear = 0,
00048 kLeft = 1,
00049 kRight = 2,
00050 kTop = 3,
00051 kBottom = 4,
00052 kFar = 5,
00053 kPlanesPerFrustum = 6
00054 };
00055
00056 private:
00057
00058
00059
00060 TGLBoundingBox fPreviousInterestBox;
00061 TGLBoundingBox fInterestFrustum;
00062 TGLBoundingBox fInterestFrustumAsBox;
00063
00064 static const Double_t fgInterestBoxExpansion;
00065
00066
00067 TGLBoundingBox Frustum(Bool_t asBox = kTRUE) const;
00068
00069
00070 TGLCamera(const TGLCamera &);
00071 TGLCamera & operator=(const TGLCamera &);
00072
00073 protected:
00074
00075 TGLMatrix fCamBase;
00076 TGLMatrix fCamTrans;
00077 Bool_t fExternalCenter;
00078 Bool_t fFixDefCenter;
00079 TGLVector3 fExtCenter;
00080 TGLVector3 fDefCenter;
00081 TGLVector3 fFDCenter;
00082 TGLVector3 *fCenter;
00083
00084 mutable Double_t fNearClip;
00085 mutable Double_t fFarClip;
00086
00087
00088 Double_t fDollyDefault;
00089 Double_t fDollyDistance;
00090 Float_t fVAxisMinAngle;
00091
00092
00093 mutable Bool_t fCacheDirty;
00094 mutable UInt_t fTimeStamp;
00095 mutable TGLMatrix fLastNoPickProjM;
00096 mutable TGLMatrix fProjM;
00097 mutable TGLMatrix fModVM;
00098 mutable TGLMatrix fClipM;
00099 mutable TGLPlane fFrustumPlanes[kPlanesPerFrustum];
00100
00101 TGLRect fViewport;
00102
00103 TGLBoundingBox fInterestBox;
00104 mutable Double_t fLargestSeen;
00105
00106
00107
00108 void UpdateCache() const;
00109
00110 static UInt_t fgDollyDeltaSens;
00111 public:
00112 TGLCamera();
00113 TGLCamera(const TGLVector3 & hAxis, const TGLVector3 & vAxis);
00114 virtual ~TGLCamera();
00115
00116 virtual Bool_t IsOrthographic() const { return kFALSE; }
00117 virtual Bool_t IsPerspective() const { return kFALSE; }
00118
00119 const TGLMatrix& RefModelViewMatrix() const { return fModVM; }
00120
00121 Bool_t IsCacheDirty() const { return fCacheDirty; }
00122 void IncTimeStamp() { fCacheDirty = kTRUE; ++fTimeStamp; }
00123 UInt_t TimeStamp() const { return fTimeStamp; }
00124
00125 void SetViewport(const TGLRect & viewport);
00126 TGLRect& RefViewport() { return fViewport; }
00127 const TGLRect& RefViewport() const { return fViewport; }
00128
00129
00130 virtual void Setup(const TGLBoundingBox & box, Bool_t reset=kTRUE) = 0;
00131 virtual void Reset() = 0;
00132
00133 virtual Bool_t Dolly(Int_t delta, Bool_t mod1, Bool_t mod2);
00134 virtual Bool_t Zoom (Int_t delta, Bool_t mod1, Bool_t mod2) = 0;
00135 virtual Bool_t Truck(Double_t xDelta, Double_t yDelta);
00136 virtual Bool_t Truck(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2) = 0;
00137 virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2);
00138 virtual Bool_t RotateRad(Double_t hRotate, Double_t vRotate);
00139
00140 virtual void Apply(const TGLBoundingBox & sceneBox, const TGLRect * pickRect = 0) const = 0;
00141
00142 Bool_t AdjustAndClampVal(Double_t & val, Double_t min, Double_t max,
00143 Int_t screenShift, Int_t screenShiftRange,
00144 Bool_t mod1, Bool_t mod2) const;
00145 Double_t AdjustDelta(Double_t screenShift, Double_t deltaFactor,
00146 Bool_t mod1, Bool_t mod2) const;
00147
00148 void SetExternalCenter(Bool_t x);
00149 Bool_t GetExternalCenter(){ return fExternalCenter; }
00150
00151 void SetCenterVec(Double_t x, Double_t y, Double_t z);
00152 void SetCenterVecWarp(Double_t x, Double_t y, Double_t z);
00153 Double_t* GetCenterVec() { return fCenter->Arr(); }
00154
00155 void SetFixDefCenter(Bool_t x) { fFixDefCenter = x; }
00156 void SetFixDefCenterVec(Double_t x, Double_t y, Double_t z) { fFDCenter.Set(x, y, z); }
00157 Double_t* GetFixDefCenterVec() { return fFDCenter.Arr(); }
00158
00159 Double_t GetNearClip() const { return fNearClip; }
00160 Double_t GetFarClip() const { return fFarClip; }
00161
00162 const TGLMatrix& GetCamBase() const { return fCamBase; }
00163 const TGLMatrix& GetCamTrans() const { return fCamTrans; }
00164
00165 TGLMatrix& RefCamBase() { return fCamBase; }
00166 TGLMatrix& RefCamTrans() { return fCamTrans; }
00167
00168 Double_t GetTheta() const;
00169
00170 TGLMatrix& RefLastNoPickProjM() const { return fLastNoPickProjM; }
00171
00172
00173 TGLVertex3 EyePoint() const;
00174 TGLVector3 EyeDirection() const;
00175 TGLVertex3 FrustumCenter() const;
00176 const TGLPlane & FrustumPlane(EFrustumPlane plane) const;
00177
00178
00179
00180 EOverlap FrustumOverlap (const TGLBoundingBox & box) const;
00181 EOverlap ViewportOverlap(const TGLBoundingBox & box) const;
00182 TGLRect ViewportRect (const TGLBoundingBox & box, TGLBoundingBox::EFace face) const;
00183 TGLRect ViewportRect (const TGLBoundingBox & box, const TGLBoundingBox::EFace * face = 0) const;
00184 TGLVertex3 WorldToViewport(const TGLVertex3 & worldVertex, TGLMatrix* modviewMat=0) const;
00185 TGLVector3 WorldDeltaToViewport(const TGLVertex3 & worldRef, const TGLVector3 & worldDelta) const;
00186 TGLVertex3 ViewportToWorld(const TGLVertex3 & viewportVertex, TGLMatrix* modviewMat=0) const;
00187 TGLLine3 ViewportToWorld(Double_t viewportX, Double_t viewportY) const;
00188 TGLLine3 ViewportToWorld(const TPoint & viewport) const;
00189 TGLVector3 ViewportDeltaToWorld(const TGLVertex3 & worldRef, Double_t viewportXDelta, Double_t viewportYDelta, TGLMatrix* modviewMat=0) const;
00190 std::pair<Bool_t, TGLVertex3> ViewportPlaneIntersection(Double_t viewportX, Double_t viewportY, const TGLPlane & worldPlane) const;
00191 std::pair<Bool_t, TGLVertex3> ViewportPlaneIntersection(const TPoint & viewport, const TGLPlane & worldPlane) const;
00192
00193
00194 void WindowToViewport(Int_t & , Int_t & y) const { y = fViewport.Height() - y; }
00195 void WindowToViewport(TPoint & point) const { point.SetY(fViewport.Height() - point.GetY()); }
00196 void WindowToViewport(TGLRect & rect) const { rect.Y() = fViewport.Height() - rect.Y(); }
00197 void WindowToViewport(TGLVertex3 & vertex) const { vertex.Y() = fViewport.Height() - vertex.Y(); }
00198
00199 Float_t GetVAxisMinAngle(){return fVAxisMinAngle;}
00200 void SetVAxisMinAngle(Float_t x){fVAxisMinAngle = x;}
00201
00202 virtual void Configure(Double_t zoom, Double_t dolly, Double_t center[3],
00203 Double_t hRotate, Double_t vRotate) = 0;
00204
00205 Bool_t OfInterest(const TGLBoundingBox & box, Bool_t ignoreSize) const;
00206 Bool_t UpdateInterest(Bool_t force);
00207 void ResetInterest();
00208
00209
00210 void DrawDebugAids() const;
00211
00212 ClassDef(TGLCamera,0);
00213 };
00214
00215 inline const TGLPlane & TGLCamera::FrustumPlane(EFrustumPlane plane) const
00216 {
00217
00218 if (fCacheDirty) {
00219 Error("TGLCamera::FrustumBox()", "cache dirty");
00220 }
00221 return fFrustumPlanes[plane];
00222 }
00223
00224
00225 #endif // ROOT_TGLCamera