Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLPlotCamera.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Timur Pocheptsov
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11#include "TGLPlotCamera.h"
12#include "TGLIncludes.h"
13#include "TGLUtil.h"
14
15/** \class TGLPlotCamera
16\ingroup opengl
17Camera for TGLPlotPainter and sub-classes.
18*/
19
20
21////////////////////////////////////////////////////////////////////////////////
22///Construct camera for plot painters.
23
25 fZoom(1.), fShift(1.5), fCenter(),
26 fVpChanged(kFALSE)
27{
28 fOrthoBox[0] = 1.;
29 fOrthoBox[1] = 1.;
30 fOrthoBox[2] = -100.;
31 fOrthoBox[3] = 100.;
32}
33
34////////////////////////////////////////////////////////////////////////////////
35///Setup viewport, if it was changed, plus reset arcball.
36
38{
39 if (vp.Width() != fViewport.Width() || vp.Height() != fViewport.Height() ||
40 vp.X() != fViewport.X() || vp.Y() != fViewport.Y())
41 {
43 fArcBall.SetBounds(vp.Width(), vp.Height());
44 fViewport = vp;
45
46 } else
48}
49
50////////////////////////////////////////////////////////////////////////////////
51///'box' is the TGLPlotPainter's back box's coordinates.
52
54{
55/* fCenter[0] = (box[0].X() + box[1].X()) / 2;
56 fCenter[1] = (box[0].Y() + box[2].Y()) / 2;
57 fCenter[2] = (box[0].Z() + box[4].Z()) / 2;
58 const Double_t maxDim = box[1].X() - box[0].X();
59 fOrthoBox[0] = maxDim;
60 fOrthoBox[1] = maxDim;
61 fOrthoBox[2] = -100 * maxDim;//100?
62 fOrthoBox[3] = 100 * maxDim;
63 fShift = maxDim * 1.5;*/
64}
65
66////////////////////////////////////////////////////////////////////////////////
67///User clicks somewhere (px, py).
68
70{
71 fArcBall.Click(TPoint(px, py));
72}
73
74////////////////////////////////////////////////////////////////////////////////
75///Mouse movement.
76
78{
79 fArcBall.Drag(TPoint(px, py));
80}
81
82////////////////////////////////////////////////////////////////////////////////
83///User clicks somewhere (px, py).
84
86{
87 fMousePos.fX = px;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92///Pan camera.
93
95{
96 py = fViewport.Height() - py;
97
98 //Extract gl matrices.
99 Double_t mv[16] = {0.};
101 Double_t pr[16] = {0.};
103 Int_t vp[] = {0, 0, fViewport.Width(), fViewport.Height()};
104 //Adjust pan vector.
105 TGLVertex3 start, end;
106 gluUnProject(fMousePos.fX, fMousePos.fY, 1., mv, pr, vp, &start.X(), &start.Y(), &start.Z());
107 gluUnProject(px, py, 1., mv, pr, vp, &end.X(), &end.Y(), &end.Z());
108 fTruck += (start - end) /= 2.;
109 //
110 fMousePos.fX = px;
111 fMousePos.fY = py;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115///Viewport and projection.
116
118{
120
123 glOrtho(
124 -fOrthoBox[0] * fZoom,
125 fOrthoBox[0] * fZoom,
126 -fOrthoBox[1] * fZoom,
127 fOrthoBox[1] * fZoom,
128 fOrthoBox[2],
129 fOrthoBox[3]
130 );
131
134}
135
136////////////////////////////////////////////////////////////////////////////////
137///Applies rotations and translations before drawing
138
140{
141 glTranslated(0., 0., -fShift);
143 glRotated(theta - 90., 1., 0., 0.);
144 glRotated(phi, 0., 0., 1.);
145 glTranslated(-fTruck[0], -fTruck[1], -fTruck[2]);
146// glTranslated(-fCenter[0], -fCenter[1], -fCenter[2]);
147}
148
149////////////////////////////////////////////////////////////////////////////////
150///viewport[0]
151
153{
154 return fViewport.X();
155}
156
157////////////////////////////////////////////////////////////////////////////////
158///viewport[1]
159
161{
162 return fViewport.Y();
163}
164
165////////////////////////////////////////////////////////////////////////////////
166///viewport[2]
167
169{
170 return Int_t(fViewport.Width());
171}
172
173////////////////////////////////////////////////////////////////////////////////
174///viewport[3]
175
177{
178 return Int_t(fViewport.Height());
179}
180
181////////////////////////////////////////////////////////////////////////////////
182///Zoom in.
183
185{
186 fZoom /= 1.2;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190///Zoom out.
191
193{
194 fZoom *= 1.2;
195}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Drag(const TPoint &NewPt)
Mouse drag, calculate rotation.
Definition TArcBall.cxx:259
void SetBounds(UInt_t NewWidth, UInt_t NewHeight)
Definition TArcBall.h:38
void Click(const TPoint &NewPt)
Mouse down.
Definition TArcBall.cxx:248
const Double_t * GetRotMatrix() const
Definition TArcBall.h:47
Int_t GetY() const
viewport[1]
Double_t fOrthoBox[4]
TGLPlotCamera()
Construct camera for plot painters.
Double_t fShift
void StartPan(Int_t px, Int_t py)
User clicks somewhere (px, py).
void Apply(Double_t phi, Double_t theta) const
Applies rotations and translations before drawing.
void SetViewport(const TGLRect &vp)
Setup viewport, if it was changed, plus reset arcball.
Int_t GetX() const
viewport[0]
void RotateCamera(Int_t px, Int_t py)
Mouse movement.
void SetCamera() const
Viewport and projection.
void ZoomIn()
Zoom in.
Int_t GetWidth() const
viewport[2]
void Pan(Int_t px, Int_t py)
Pan camera.
TGLRect fViewport
void ZoomOut()
Zoom out.
Int_t GetHeight() const
viewport[3]
TGLVector3 fTruck
TArcBall fArcBall
void StartRotation(Int_t px, Int_t py)
User clicks somewhere (px, py).
void SetViewVolume(const TGLVertex3 *box)
'box' is the TGLPlotPainter's back box's coordinates.
Viewport (pixel base) 2D rectangle class.
Definition TGLUtil.h:422
Int_t Y() const
Definition TGLUtil.h:448
Int_t Height() const
Definition TGLUtil.h:452
Int_t Width() const
Definition TGLUtil.h:450
Int_t X() const
Definition TGLUtil.h:446
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35