Warning, file /include/root/TGLCamera.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGLCamera
0013 #define ROOT_TGLCamera
0014
0015 #include "TGLUtil.h"
0016 #include "TGLBoundingBox.h"
0017 #include "TPoint.h"
0018 #include "TObject.h"
0019
0020 #include <cmath>
0021 #include <utility>
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 class TGLCamera : public TObject
0044 {
0045 public:
0046 enum EFrustumPlane
0047 {
0048 kNear = 0,
0049 kLeft = 1,
0050 kRight = 2,
0051 kTop = 3,
0052 kBottom = 4,
0053 kFar = 5,
0054 kPlanesPerFrustum = 6
0055 };
0056
0057 private:
0058
0059
0060
0061 TGLBoundingBox fPreviousInterestBox;
0062 TGLBoundingBox fInterestFrustum;
0063 TGLBoundingBox fInterestFrustumAsBox;
0064
0065 static const Double_t fgInterestBoxExpansion;
0066
0067
0068 TGLBoundingBox Frustum(Bool_t asBox = kTRUE) const;
0069
0070
0071 TGLCamera(const TGLCamera &) = delete;
0072 TGLCamera & operator=(const TGLCamera &) = delete;
0073
0074 protected:
0075
0076 TGLMatrix fCamBase;
0077 TGLMatrix fCamTrans;
0078 Bool_t fExternalCenter;
0079 Bool_t fFixDefCenter;
0080 Bool_t fWasArcBalled;
0081 TGLVector3 fExtCenter;
0082 TGLVector3 fDefCenter;
0083 TGLVector3 fFDCenter;
0084 TGLVector3 *fCenter;
0085
0086 mutable Double_t fNearClip;
0087 mutable Double_t fFarClip;
0088
0089
0090 Double_t fDollyDefault;
0091 Double_t fDollyDistance;
0092 Float_t fVAxisMinAngle;
0093
0094
0095 mutable Bool_t fCacheDirty;
0096 mutable UInt_t fTimeStamp;
0097 mutable TGLMatrix fLastNoPickProjM;
0098 mutable TGLMatrix fProjM;
0099 mutable TGLMatrix fModVM;
0100 mutable TGLMatrix fClipM;
0101 mutable TGLPlane fFrustumPlanes[kPlanesPerFrustum];
0102
0103 TGLRect fViewport;
0104
0105 TGLBoundingBox fInterestBox;
0106 mutable Double_t fLargestSeen;
0107
0108
0109
0110 void UpdateCache() const;
0111
0112 static UInt_t fgDollyDeltaSens;
0113 public:
0114 TGLCamera();
0115 TGLCamera(const TGLVector3 & hAxis, const TGLVector3 & vAxis);
0116 ~TGLCamera() override;
0117
0118 virtual Bool_t IsOrthographic() const { return kFALSE; }
0119 virtual Bool_t IsPerspective() const { return kFALSE; }
0120
0121 const TGLMatrix& RefModelViewMatrix() const { return fModVM; }
0122
0123 Bool_t IsCacheDirty() const { return fCacheDirty; }
0124 void IncTimeStamp() { fCacheDirty = kTRUE; ++fTimeStamp; }
0125 UInt_t TimeStamp() const { return fTimeStamp; }
0126
0127 void SetViewport(const TGLRect & viewport);
0128 TGLRect& RefViewport() { return fViewport; }
0129 const TGLRect& RefViewport() const { return fViewport; }
0130
0131
0132 virtual void Setup(const TGLBoundingBox & box, Bool_t reset=kTRUE) = 0;
0133 virtual void Reset() = 0;
0134
0135 virtual Bool_t Dolly(Int_t delta, Bool_t mod1, Bool_t mod2);
0136 virtual Bool_t Zoom (Int_t delta, Bool_t mod1, Bool_t mod2) = 0;
0137 virtual Bool_t Truck(Double_t xDelta, Double_t yDelta);
0138 virtual Bool_t Truck(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2) = 0;
0139 virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2);
0140 virtual Bool_t RotateRad(Double_t hRotate, Double_t vRotate);
0141 virtual Bool_t RotateArcBall(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2);
0142 virtual Bool_t RotateArcBallRad(Double_t hRotate, Double_t vRotate);
0143
0144 virtual void Apply(const TGLBoundingBox & sceneBox, const TGLRect * pickRect = nullptr) const = 0;
0145
0146 Bool_t AdjustAndClampVal(Double_t & val, Double_t min, Double_t max,
0147 Int_t screenShift, Int_t screenShiftRange,
0148 Bool_t mod1, Bool_t mod2) const;
0149 Double_t AdjustDelta(Double_t screenShift, Double_t deltaFactor,
0150 Bool_t mod1, Bool_t mod2) const;
0151
0152 void SetExternalCenter(Bool_t x);
0153 Bool_t GetExternalCenter(){ return fExternalCenter; }
0154
0155 void SetCenterVec(Double_t x, Double_t y, Double_t z);
0156 void SetCenterVecWarp(Double_t x, Double_t y, Double_t z);
0157 Double_t* GetCenterVec() { return fCenter->Arr(); }
0158
0159 void SetFixDefCenter(Bool_t x) { fFixDefCenter = x; }
0160 void SetFixDefCenterVec(Double_t x, Double_t y, Double_t z) { fFDCenter.Set(x, y, z); }
0161 Double_t* GetFixDefCenterVec() { return fFDCenter.Arr(); }
0162
0163 Double_t GetNearClip() const { return fNearClip; }
0164 Double_t GetFarClip() const { return fFarClip; }
0165
0166 const TGLMatrix& GetCamBase() const { return fCamBase; }
0167 const TGLMatrix& GetCamTrans() const { return fCamTrans; }
0168
0169 TGLMatrix& RefCamBase() { return fCamBase; }
0170 TGLMatrix& RefCamTrans() { return fCamTrans; }
0171
0172 Double_t GetTheta() const;
0173
0174 TGLMatrix& RefLastNoPickProjM() const { return fLastNoPickProjM; }
0175
0176
0177 TGLVertex3 EyePoint() const;
0178 TGLVector3 EyeDirection() const;
0179 TGLVertex3 FrustumCenter() const;
0180 const TGLPlane & FrustumPlane(EFrustumPlane plane) const;
0181
0182
0183
0184 Rgl::EOverlap FrustumOverlap (const TGLBoundingBox & box) const;
0185 Rgl::EOverlap ViewportOverlap(const TGLBoundingBox & box) const;
0186 TGLRect ViewportRect (const TGLBoundingBox & box, TGLBoundingBox::EFace face) const;
0187 TGLRect ViewportRect (const TGLBoundingBox & box, const TGLBoundingBox::EFace * face = nullptr) const;
0188 TGLVertex3 WorldToViewport(const TGLVertex3 & worldVertex, TGLMatrix* modviewMat = nullptr) const;
0189 TGLVector3 WorldDeltaToViewport(const TGLVertex3 & worldRef, const TGLVector3 & worldDelta) const;
0190 TGLVertex3 ViewportToWorld(const TGLVertex3 & viewportVertex, TGLMatrix* modviewMat = nullptr) const;
0191 TGLLine3 ViewportToWorld(Double_t viewportX, Double_t viewportY) const;
0192 TGLLine3 ViewportToWorld(const TPoint & viewport) const;
0193 TGLVector3 ViewportDeltaToWorld(const TGLVertex3 & worldRef, Double_t viewportXDelta, Double_t viewportYDelta, TGLMatrix* modviewMat = nullptr) const;
0194 std::pair<Bool_t, TGLVertex3> ViewportPlaneIntersection(Double_t viewportX, Double_t viewportY, const TGLPlane & worldPlane) const;
0195 std::pair<Bool_t, TGLVertex3> ViewportPlaneIntersection(const TPoint & viewport, const TGLPlane & worldPlane) const;
0196
0197
0198 void WindowToViewport(Int_t & , Int_t & y) const { y = fViewport.Height() - y; }
0199 void WindowToViewport(TPoint & point) const { point.SetY(fViewport.Height() - point.GetY()); }
0200 void WindowToViewport(TGLRect & rect) const { rect.Y() = fViewport.Height() - rect.Y(); }
0201 void WindowToViewport(TGLVertex3 & vertex) const { vertex.Y() = fViewport.Height() - vertex.Y(); }
0202
0203 Float_t GetVAxisMinAngle(){return fVAxisMinAngle;}
0204 void SetVAxisMinAngle(Float_t x){fVAxisMinAngle = x;}
0205
0206 virtual void Configure(Double_t zoom, Double_t dolly, Double_t center[3],
0207 Double_t hRotate, Double_t vRotate) = 0;
0208
0209 Bool_t OfInterest(const TGLBoundingBox & box, Bool_t ignoreSize) const;
0210 Bool_t UpdateInterest(Bool_t force);
0211 void ResetInterest();
0212
0213
0214 void DrawDebugAids() const;
0215
0216 ClassDefOverride(TGLCamera,1);
0217 };
0218
0219 inline const TGLPlane & TGLCamera::FrustumPlane(EFrustumPlane plane) const
0220 {
0221
0222 if (fCacheDirty) {
0223 Error("TGLCamera::FrustumBox()", "cache dirty");
0224 }
0225 return fFrustumPlanes[plane];
0226 }
0227
0228
0229 #endif