13#include "TGLIncludes.h"
111 glGetDoublev(GL_PROJECTION_MATRIX,
fProjM.Arr());
112 glGetDoublev(GL_MODELVIEW_MATRIX,
fModVM.Arr());
175 Error(
"TGLCamera::FrustumBox()",
"cache dirty - must call Apply()");
221 Error(
"TGLPerspectiveCamera::FrustumBox()",
"cache dirty - must call Apply()");
238 Error(
"TGLCamera::FrustumBox()",
"cache dirty - must call Apply()");
253 Error(
"TGLCamera::FrustumCenter()",
"cache dirty - must call Apply()");
262 if (!nearBottomLeft.first || !farTopRight.first) {
263 Error(
"TGLCamera::FrustumCenter()",
"frustum planes invalid");
266 return nearBottomLeft.second + (farTopRight.second - nearBottomLeft.second)/2.0;
277 Error(
"TGLCamera::FrustumOverlap()",
"cache dirty - must call Apply()");
286 Int_t planesInside = 0;
354 Error(
"TGLCamera::ViewportSize()",
"cache dirty - must call Apply()");
369 vertexCount =
box.FaceVertices(*face).size();
371 vertexCount =
box.NumVertices();
374 for (
UInt_t i = 0; i < vertexCount; i++)
376 const TGLVertex3 & vertex = face ?
box.Vertex(
box.FaceVertices(*face).at(i)) :
379 gluProject(vertex.
X(), vertex.
Y(), vertex.
Z(),
381 &winX, &winY, &winZ);
406 Error(
"TGLCamera::WorldToViewport()",
"cache dirty - must call Apply()");
409 gluProject(worldVertex[0], worldVertex[1], worldVertex[2],
410 modviewMat ? modviewMat->
CArr() :
fModVM.CArr(),
412 &viewportVertex[0], &viewportVertex[1], &viewportVertex[2]);
413 return viewportVertex;
429 Error(
"TGLCamera::WorldToViewport()",
"cache dirty - must call Apply()");
456 Error(
"TGLCamera::ViewportToWorld()",
"cache dirty - must call Apply()");
459 gluUnProject(viewportVertex[0], viewportVertex[1], viewportVertex[2],
460 modviewMat ? modviewMat->
CArr() :
fModVM.CArr(),
462 &worldVertex[0], &worldVertex[1], &worldVertex[2]);
479 Error(
"TGLCamera::Viewport2DToWorldLine()",
"cache dirty - must call Apply()");
484 return TGLLine3(nearClipWorld, farClipWorld - nearClipWorld);
549 Error(
"TGLCamera::ViewportDeltaToWorld()",
"cache dirty - must call Apply()");
552 winVertex.
Shift(viewportXDelta, viewportYDelta, 0.0);
655 newInterestBox.
Scale(minBoxLength/frustumExtents[0], minBoxLength/frustumExtents[1], minBoxLength/frustumExtents[2]);
670 if (volRatio > 8.0 || volRatio < 0.125 ||
fInterestBox.IsEmpty() ||
678 Error(
"TGLCamera::UpdateInterest",
"update interest box does not contain frustum");
681 exposedUpdate =
kTRUE;
688 Info(
"TGLCamera::UpdateInterest",
"changed - volume ratio %f", volRatio );
692 return exposedUpdate;
725 if (screenShift == 0) {
750 else if (val > max) {
754 return val != oldVal;
764 if (screenShift == 0)
781 return sens * deltaFactor * screenShift;
795 glColor3d(1.0,0.0,0.0);
799 glColor3d(1.0,0.65,0.15);
803 glColor3d(0.0,0.0,1.0);
814 glColor3d(1.0,1.0,1.0);
816 glVertex3dv(
start.CArr());
817 glVertex3dv(end.
CArr());
895 if (xDelta != 0 || yDelta != 0)
928 using namespace TMath;
935 else if (
d < -1)
d = -1;
940 M[0] = M[5] = M[10] = 1;
941 M[1] = M[2] = M[4] = M[6] = M[8] = M[9] = 0;
1002 using namespace TMath;
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with 'other'.
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
TGLVector3 Extents() const
void Scale(Double_t factor)
Isotropically scale bounding box along it's LOCAL axes, preserving center.
Rgl::EOverlap FrustumOverlap(const TGLBoundingBox &box) const
Calculate overlap (kInside, kOutside, kPartial) of box with camera frustum Camera must have valid fru...
static UInt_t fgDollyDeltaSens
TGLVector3 EyeDirection() const
Extract the camera eye direction (vector), running from EyePoint() Camera must have valid frustum cac...
virtual Bool_t RotateRad(Double_t hRotate, Double_t vRotate)
Rotate camera around center.
Bool_t fCacheDirty
! cached items dirty?
TGLVertex3 FrustumCenter() const
Find the center of the camera frustum from intersection of planes This method will work even with par...
TGLCamera()
Default base camera constructor.
void ResetInterest()
Clear out the existing interest box.
virtual Bool_t Dolly(Int_t delta, Bool_t mod1, Bool_t mod2)
Dolly the camera - 'move camera along eye line, retaining lens focal length'.
TGLBoundingBox Frustum(Bool_t asBox=kTRUE) const
Return the current camera frustum.
virtual Bool_t RotateArcBallRad(Double_t hRotate, Double_t vRotate)
Rotate camera around center.
TGLVector3 * fCenter
! current camera center
Double_t fNearClip
! last applied near-clip
TGLMatrix fProjM
! projection matrix (cached)
Bool_t AdjustAndClampVal(Double_t &val, Double_t min, Double_t max, Int_t screenShift, Int_t screenShiftRange, Bool_t mod1, Bool_t mod2) const
Adjust a passed REFERENCE value 'val', based on screenShift delta.
TGLVector3 ViewportDeltaToWorld(const TGLVertex3 &worldRef, Double_t viewportXDelta, Double_t viewportYDelta, TGLMatrix *modviewMat=nullptr) const
Apply a 2D viewport delta (shift) to the projection of worldRef onto viewport, returning the resultan...
virtual Bool_t Truck(Double_t xDelta, Double_t yDelta)
Truck the camera - 'move camera parallel to film plane'.
Rgl::EOverlap ViewportOverlap(const TGLBoundingBox &box) const
Calculate overlap (kInside, kOutside, kPartial) of box projection onto viewport (as rect) against the...
TGLBoundingBox fInterestBox
! the interest box - created in UpdateInterest()
TGLBoundingBox fInterestFrustumAsBox
! frustum basis (as box) of current interest box (DEBUG)
TGLRect ViewportRect(const TGLBoundingBox &box, TGLBoundingBox::EFace face) const
Calculate viewport rectangle which just contains projection of single 'face' of world frame bounding ...
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Rotate the camera round view volume center established in Setup().
void SetCenterVecWarp(Double_t x, Double_t y, Double_t z)
Set camera center vector and do not keep the same combined camera transformation matrix.
TGLRect fViewport
! viewport (GL coords - origin bottom left)
TGLVector3 WorldDeltaToViewport(const TGLVertex3 &worldRef, const TGLVector3 &worldDelta) const
Convert a 3D vector worldDelta (shift) about vertex worldRef to a viewport (screen) '3D' vector.
TGLMatrix fModVM
! modelView matrix (cached)
~TGLCamera() override
Base camera destructor.
TGLVertex3 WorldToViewport(const TGLVertex3 &worldVertex, TGLMatrix *modviewMat=nullptr) const
Convert a 3D world vertex to '3D' viewport (screen) one.
TGLPlane fFrustumPlanes[kPlanesPerFrustum]
! frustum planes (cached)
Double_t GetTheta() const
Get angle between camera up axis.
std::pair< Bool_t, TGLVertex3 > ViewportPlaneIntersection(Double_t viewportX, Double_t viewportY, const TGLPlane &worldPlane) const
Find the intersection of projection of supplied viewport point (a 3D world line - see ViewportToWorld...
Bool_t UpdateInterest(Bool_t force)
Update the internal interest box (fInterestBox) of the camera.
void DrawDebugAids() const
Draw out some debugging aids for the camera:
TGLBoundingBox fInterestFrustum
! frustum basis of current interest box - NOT a true BB! (DEBUG)
void UpdateCache() const
Update internally cached frustum values.
TGLMatrix fClipM
! object space clip matrix (cached)
UInt_t fTimeStamp
! timestamp
void SetExternalCenter(Bool_t x)
Set camera center diffrent than scene center, if enable is kTRUE.
void SetCenterVec(Double_t x, Double_t y, Double_t z)
Set camera center vector.
Double_t fFarClip
! last applied far-clip
void SetViewport(const TGLRect &viewport)
Set viewport extents from passed 'viewport' rect.
TGLBoundingBox fPreviousInterestBox
! previous interest box (DEBUG)
virtual Bool_t RotateArcBall(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Rotate the camera round view volume center established in Setup().
static const Double_t fgInterestBoxExpansion
! expansion c.f. aligned current frustum box
Bool_t OfInterest(const TGLBoundingBox &box, Bool_t ignoreSize) const
Calculate if the an object defined by world frame bounding box is 'of interest' to the camera.
TGLVertex3 EyePoint() const
Return the camera eye point (vertex) in world space Camera must have valid frustum cache - call Apply...
Double_t AdjustDelta(Double_t screenShift, Double_t deltaFactor, Bool_t mod1, Bool_t mod2) const
Adjust a passed screen value and apply modifiers.
TGLVertex3 ViewportToWorld(const TGLVertex3 &viewportVertex, TGLMatrix *modviewMat=nullptr) const
Convert a '3D' viewport vertex to 3D world one.
3D space, fixed length, line class, with direction / length 'vector', passing through point 'vertex'.
16 component (4x4) transform matrix - column MAJOR as per GL.
Double_t Invert()
Invert the matrix, returns determinant.
const Double_t * CArr() const
3D plane class - of format Ax + By + Cz + D = 0
Viewport (pixel base) 2D rectangle class.
Rgl::EOverlap Overlap(const TGLRect &other) const
Return overlap result (kInside, kOutside, kPartial) of this rect with 'other'.
void Expand(Int_t x, Int_t y)
Expand the rect to encompass point (x,y).
void SetCorner(Int_t x, Int_t y)
3 component (x/y/z) vector class.
3 component (x/y/z) vertex class.
void Shift(TGLVector3 &shift)
Offset a vertex by vector 'shift'.
const Double_t * CArr() const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Double_t ACos(Double_t)
Returns the principal value of the arc cosine of x, expressed in radians.
Double_t ASin(Double_t)
Returns the principal value of the arc sine of x, expressed in radians.
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
constexpr Double_t TwoPi()