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
21
22////////////////////////////////////////////////////////////////////////////////
23///Construct camera for plot painters.
24
26 fZoom(1.), fShift(1.5), fCenter(),
27 fVpChanged(kFALSE)
28{
29 fOrthoBox[0] = 1.;
30 fOrthoBox[1] = 1.;
31 fOrthoBox[2] = -100.;
32 fOrthoBox[3] = 100.;
33}
34
35////////////////////////////////////////////////////////////////////////////////
36///Setup viewport, if it was changed, plus reset arcball.
37
39{
40 if (vp.Width() != fViewport.Width() || vp.Height() != fViewport.Height() ||
41 vp.X() != fViewport.X() || vp.Y() != fViewport.Y())
42 {
44 fArcBall.SetBounds(vp.Width(), vp.Height());
45 fViewport = vp;
46
47 } else
49}
50
51////////////////////////////////////////////////////////////////////////////////
52///'box' is the TGLPlotPainter's back box's coordinates.
53
55{
56/* fCenter[0] = (box[0].X() + box[1].X()) / 2;
57 fCenter[1] = (box[0].Y() + box[2].Y()) / 2;
58 fCenter[2] = (box[0].Z() + box[4].Z()) / 2;
59 const Double_t maxDim = box[1].X() - box[0].X();
60 fOrthoBox[0] = maxDim;
61 fOrthoBox[1] = maxDim;
62 fOrthoBox[2] = -100 * maxDim;//100?
63 fOrthoBox[3] = 100 * maxDim;
64 fShift = maxDim * 1.5;*/
65}
66
67////////////////////////////////////////////////////////////////////////////////
68///User clicks somewhere (px, py).
69
71{
72 fArcBall.Click(TPoint(px, py));
73}
74
75////////////////////////////////////////////////////////////////////////////////
76///Mouse movement.
77
79{
80 fArcBall.Drag(TPoint(px, py));
81}
82
83////////////////////////////////////////////////////////////////////////////////
84///User clicks somewhere (px, py).
85
87{
88 fMousePos.fX = px;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93///Pan camera.
94
96{
97 py = fViewport.Height() - py;
98
99 //Extract gl matrices.
100 Double_t mv[16] = {0.};
101 glGetDoublev(GL_MODELVIEW_MATRIX, mv);
102 Double_t pr[16] = {0.};
103 glGetDoublev(GL_PROJECTION_MATRIX, pr);
104 Int_t vp[] = {0, 0, fViewport.Width(), fViewport.Height()};
105 //Adjust pan vector.
106 TGLVertex3 start, end;
107 gluUnProject(fMousePos.fX, fMousePos.fY, 1., mv, pr, vp, &start.X(), &start.Y(), &start.Z());
108 gluUnProject(px, py, 1., mv, pr, vp, &end.X(), &end.Y(), &end.Z());
109 fTruck += (start - end) /= 2.;
110 //
111 fMousePos.fX = px;
112 fMousePos.fY = py;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116///Viewport and projection.
117
119{
120 glViewport(fViewport.X(), fViewport.Y(), fViewport.Width(), fViewport.Height());
121
122 glMatrixMode(GL_PROJECTION);
123 glLoadIdentity();
124 glOrtho(
125 -fOrthoBox[0] * fZoom,
126 fOrthoBox[0] * fZoom,
127 -fOrthoBox[1] * fZoom,
128 fOrthoBox[1] * fZoom,
129 fOrthoBox[2],
130 fOrthoBox[3]
131 );
132
133 glMatrixMode(GL_MODELVIEW);
134 glLoadIdentity();
135}
136
137////////////////////////////////////////////////////////////////////////////////
138///Applies rotations and translations before drawing
139
141{
142 glTranslated(0., 0., -fShift);
143 glMultMatrixd(fArcBall.GetRotMatrix());
144 glRotated(theta - 90., 1., 0., 0.);
145 glRotated(phi, 0., 0., 1.);
146 glTranslated(-fTruck[0], -fTruck[1], -fTruck[2]);
147// glTranslated(-fCenter[0], -fCenter[1], -fCenter[2]);
148}
149
150////////////////////////////////////////////////////////////////////////////////
151///viewport[0]
152
154{
155 return fViewport.X();
156}
157
158////////////////////////////////////////////////////////////////////////////////
159///viewport[1]
160
162{
163 return fViewport.Y();
164}
165
166////////////////////////////////////////////////////////////////////////////////
167///viewport[2]
168
170{
171 return Int_t(fViewport.Width());
172}
173
174////////////////////////////////////////////////////////////////////////////////
175///viewport[3]
176
178{
179 return Int_t(fViewport.Height());
180}
181
182////////////////////////////////////////////////////////////////////////////////
183///Zoom in.
184
186{
187 fZoom /= 1.2;
188}
189
190////////////////////////////////////////////////////////////////////////////////
191///Zoom out.
192
194{
195 fZoom *= 1.2;
196}
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
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.
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
Double_t X() const
Definition TGLUtil.h:119
Double_t Z() const
Definition TGLUtil.h:123
Double_t Y() const
Definition TGLUtil.h:121
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35