Logo ROOT   6.16/01
Reference Guide
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 "TVirtualGL.h"
14#include "TGLUtil.h"
15
16/** \class TGLPlotCamera
17\ingroup opengl
18Camera for TGLPlotPainter and sub-classes.
19*/
20
22
23////////////////////////////////////////////////////////////////////////////////
24///Construct camera for plot painters.
25
27 fZoom(1.), fShift(1.5), fCenter(),
28 fVpChanged(kFALSE)
29{
30 fOrthoBox[0] = 1.;
31 fOrthoBox[1] = 1.;
32 fOrthoBox[2] = -100.;
33 fOrthoBox[3] = 100.;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37///Setup viewport, if it was changed, plus reset arcball.
38
40{
41 if (vp.Width() != fViewport.Width() || vp.Height() != fViewport.Height() ||
42 vp.X() != fViewport.X() || vp.Y() != fViewport.Y())
43 {
45 fArcBall.SetBounds(vp.Width(), vp.Height());
46 fViewport = vp;
47
48 } else
50}
51
52////////////////////////////////////////////////////////////////////////////////
53///'box' is the TGLPlotPainter's back box's coordinates.
54
56{
57/* fCenter[0] = (box[0].X() + box[1].X()) / 2;
58 fCenter[1] = (box[0].Y() + box[2].Y()) / 2;
59 fCenter[2] = (box[0].Z() + box[4].Z()) / 2;
60 const Double_t maxDim = box[1].X() - box[0].X();
61 fOrthoBox[0] = maxDim;
62 fOrthoBox[1] = maxDim;
63 fOrthoBox[2] = -100 * maxDim;//100?
64 fOrthoBox[3] = 100 * maxDim;
65 fShift = maxDim * 1.5;*/
66}
67
68////////////////////////////////////////////////////////////////////////////////
69///User clicks somewhere (px, py).
70
72{
73 fArcBall.Click(TPoint(px, py));
74}
75
76////////////////////////////////////////////////////////////////////////////////
77///Mouse movement.
78
80{
81 fArcBall.Drag(TPoint(px, py));
82}
83
84////////////////////////////////////////////////////////////////////////////////
85///User clicks somewhere (px, py).
86
88{
89 fMousePos.fX = px;
91}
92
93////////////////////////////////////////////////////////////////////////////////
94///Pan camera.
95
97{
98 py = fViewport.Height() - py;
99
100 //Extract gl matrices.
101 Double_t mv[16] = {0.};
102 glGetDoublev(GL_MODELVIEW_MATRIX, mv);
103 Double_t pr[16] = {0.};
104 glGetDoublev(GL_PROJECTION_MATRIX, pr);
105 Int_t vp[] = {0, 0, fViewport.Width(), fViewport.Height()};
106 //Adjust pan vector.
107 TGLVertex3 start, end;
108 gluUnProject(fMousePos.fX, fMousePos.fY, 1., mv, pr, vp, &start.X(), &start.Y(), &start.Z());
109 gluUnProject(px, py, 1., mv, pr, vp, &end.X(), &end.Y(), &end.Z());
110 fTruck += (start - end) /= 2.;
111 //
112 fMousePos.fX = px;
113 fMousePos.fY = py;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117///Viewport and projection.
118
120{
121 glViewport(fViewport.X(), fViewport.Y(), fViewport.Width(), fViewport.Height());
122
123 glMatrixMode(GL_PROJECTION);
124 glLoadIdentity();
125 glOrtho(
126 -fOrthoBox[0] * fZoom,
127 fOrthoBox[0] * fZoom,
128 -fOrthoBox[1] * fZoom,
129 fOrthoBox[1] * fZoom,
130 fOrthoBox[2],
131 fOrthoBox[3]
132 );
133
134 glMatrixMode(GL_MODELVIEW);
135 glLoadIdentity();
136}
137
138////////////////////////////////////////////////////////////////////////////////
139///Applies rotations and translations before drawing
140
142{
143 glTranslated(0., 0., -fShift);
144 glMultMatrixd(fArcBall.GetRotMatrix());
145 glRotated(theta - 90., 1., 0., 0.);
146 glRotated(phi, 0., 0., 1.);
147 glTranslated(-fTruck[0], -fTruck[1], -fTruck[2]);
148// glTranslated(-fCenter[0], -fCenter[1], -fCenter[2]);
149}
150
151////////////////////////////////////////////////////////////////////////////////
152///viewport[0]
153
155{
156 return fViewport.X();
157}
158
159////////////////////////////////////////////////////////////////////////////////
160///viewport[1]
161
163{
164 return fViewport.Y();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168///viewport[2]
169
171{
172 return Int_t(fViewport.Width());
173}
174
175////////////////////////////////////////////////////////////////////////////////
176///viewport[3]
177
179{
180 return Int_t(fViewport.Height());
181}
182
183////////////////////////////////////////////////////////////////////////////////
184///Zoom in.
185
187{
188 fZoom /= 1.2;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192///Zoom out.
193
195{
196 fZoom *= 1.2;
197}
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
void Drag(const TPoint &NewPt)
Mouse drag, calculate rotation.
Definition: TArcBall.cxx:260
void SetBounds(UInt_t NewWidth, UInt_t NewHeight)
Definition: TArcBall.h:38
void Click(const TPoint &NewPt)
Mouse down.
Definition: TArcBall.cxx:249
const Double_t * GetRotMatrix() const
Definition: TArcBall.h:47
Camera for TGLPlotPainter and sub-classes.
Definition: TGLPlotCamera.h:22
Int_t GetY() const
viewport[1]
Double_t fOrthoBox[4]
Definition: TGLPlotCamera.h:31
Double_t fZoom
Definition: TGLPlotCamera.h:29
TGLPlotCamera()
Construct camera for plot painters.
Double_t fShift
Definition: TGLPlotCamera.h:30
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.
Bool_t fVpChanged
Definition: TGLPlotCamera.h:36
Int_t GetWidth() const
viewport[2]
void Pan(Int_t px, Int_t py)
Pan camera.
TGLRect fViewport
Definition: TGLPlotCamera.h:28
void ZoomOut()
Zoom out.
Int_t GetHeight() const
viewport[3]
TGLVector3 fTruck
Definition: TGLPlotCamera.h:33
TArcBall fArcBall
Definition: TGLPlotCamera.h:34
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.
TPoint fMousePos
Definition: TGLPlotCamera.h:35
Viewport (pixel base) 2D rectangle class.
Definition: TGLUtil.h:423
Int_t Y() const
Definition: TGLUtil.h:449
Int_t Height() const
Definition: TGLUtil.h:453
Int_t Width() const
Definition: TGLUtil.h:451
Int_t X() const
Definition: TGLUtil.h:447
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:83
Double_t X() const
Definition: TGLUtil.h:118
Double_t Z() const
Definition: TGLUtil.h:122
Double_t Y() const
Definition: TGLUtil.h:120
Definition: TPoint.h:31
SCoord_t fY
Definition: TPoint.h:36
SCoord_t fX
Definition: TPoint.h:35