Logo ROOT  
Reference Guide
TGLManip.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Richard Maunder 16/09/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, 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
12#include "TGLManip.h"
13#include "TGLUtil.h"
14#include "TGLCamera.h"
15#include "TGLPhysicalShape.h"
16#include "TGLIncludes.h"
17#include "TROOT.h"
18
19#include "TVirtualX.h"
20
21/** \class TGLManip
22\ingroup opengl
23Abstract base class for viewer manipulators, which allow direct in
24viewer manipulation of a (TGlPhysicalShape) object - currently
25translation, scaling and rotation along/round objects local axes.
26See derived classes for these implementations.
27
28This class provides binding to the zero or one manipulated physical,
29hit testing (selection) for manipulator sub component (widget), and
30some common mouse action handling/tracking.
31*/
32
34
35////////////////////////////////////////////////////////////////////////////////
36/// Construct a manipulator object, bound to supplied viewer, and no
37/// physical shape.
38
40 fShape(0),
41 fSelectedWidget(0), fActive(kFALSE),
42 fFirstMouse(0, 0),
43 fLastMouse(0, 0)
44{
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Construct a manipulator object, bound to supplied physical shape.
49
51 fShape(shape),
52 fSelectedWidget(0), fActive(kFALSE),
53 fFirstMouse(0, 0),
54 fLastMouse(0, 0)
55{
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Copy constructor.
60
63 fShape(gm.fShape),
64 fSelectedWidget(gm.fSelectedWidget),
65 fActive(gm.fActive),
66 fFirstMouse(gm.fFirstMouse),
67 fLastMouse(gm.fLastMouse)
68{
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Assignment operator.
73
75{
76 if(this!=&gm) {
78 fShape=gm.fShape;
83 }
84 return *this;
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Destroy manipulator object.
89
91{
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Returns color to be used for given widget.
96
97const UChar_t* TGLManip::ColorFor(UInt_t widget) const
98{
99 if (widget == fSelectedWidget)
100 {
101 return TGLUtil::fgYellow;
102 }
103 else
104 {
105 switch (widget)
106 {
107 case 1: return TGLUtil::fgRed;
108 case 2: return TGLUtil::fgGreen;
109 case 3: return TGLUtil::fgBlue;
110 default: return TGLUtil::fgGrey;
111 }
112 }
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Handle a mouse button event - return kTRUE if processed, kFALSE otherwise
117
118Bool_t TGLManip::HandleButton(const Event_t& event, const TGLCamera& /*camera*/)
119{
120 // Only interested in Left mouse button actions
121 if (event.fCode != kButton1) {
122 return kFALSE;
123 }
124
125 // Mouse down on selected widget?
126 if (event.fType == kButtonPress && fSelectedWidget != 0) {
127 fFirstMouse.SetX(event.fX);
128 fFirstMouse.SetY(event.fY);
129 fLastMouse.SetX(event.fX);
130 fLastMouse.SetY(event.fY);
131 fActive = kTRUE;
132 return kTRUE;
133 } else if (event.fType == kButtonRelease && fActive) {
134 fActive = kFALSE;
135 return kTRUE;
136 } else {
137 return kFALSE;
138 }
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Handle a mouse button event - return kTRUE if widget selection change
143/// kFALSE otherwise
144
146 const TGLCamera& /*camera*/)
147{
148 return kFALSE;
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Calculates base and axis scale factor (in world units) for
153/// drawing manipulators with reasonable size range in current
154/// camera.
155
157 const TGLCamera& camera,
158 Double_t& base,
159 TGLVector3 axis[3]) const
160{
161 // Calculate a base scale
162 base = box.Extents().Mag() / 100.0;
163
164 // Clamp this base scale to a viewport pixel range
165 // Allow some variation so zooming is noticeable
166 TGLVector3 pixelInWorld = camera.ViewportDeltaToWorld(box.Center(), 1, 1);
167 Double_t pixelScale = pixelInWorld.Mag();
168 if (base < pixelScale * 3.0) {
169 base = pixelScale * 3.0;
170 } else if (base > pixelScale * 6.0) {
171 base = pixelScale * 6.0;
172 }
173
174 // Calculate some axis scales
175 for (UInt_t i = 0; i<3; i++) {
176 if (box.IsEmpty()) {
177 axis[i] = box.Axis(i, kTRUE)*base*-10.0;
178 } else {
179 axis[i] = box.Axis(i, kFALSE)*-0.51;
180 if (axis[i].Mag() < base*10.0) {
181 axis[i] = box.Axis(i, kTRUE)*base*-10.0;
182 }
183 }
184 }
185}
@ kButtonRelease
Definition: GuiTypes.h:59
@ kButtonPress
Definition: GuiTypes.h:59
@ kButton1
Definition: GuiTypes.h:213
unsigned char UChar_t
Definition: RtypesCore.h:36
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
Binding & operator=(OUT(*fun)(void))
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:43
TGLVector3 ViewportDeltaToWorld(const TGLVertex3 &worldRef, Double_t viewportXDelta, Double_t viewportYDelta, TGLMatrix *modviewMat=0) const
Apply a 2D viewport delta (shift) to the projection of worldRef onto viewport, returning the resultan...
Definition: TGLCamera.cxx:546
Abstract base class for viewer manipulators, which allow direct in viewer manipulation of a (TGlPhysi...
Definition: TGLManip.h:29
TGLManip()
Construct a manipulator object, bound to supplied viewer, and no physical shape.
Definition: TGLManip.cxx:39
TGLManip & operator=(const TGLManip &)
Assignment operator.
Definition: TGLManip.cxx:74
TPoint fLastMouse
first (start) mouse position (in WINDOW coords)
Definition: TGLManip.h:37
const UChar_t * ColorFor(UInt_t widget) const
Returns color to be used for given widget.
Definition: TGLManip.cxx:97
TPoint fFirstMouse
manipulator is active?
Definition: TGLManip.h:36
virtual Bool_t HandleButton(const Event_t &event, const TGLCamera &camera)
Handle a mouse button event - return kTRUE if processed, kFALSE otherwise.
Definition: TGLManip.cxx:118
Bool_t fActive
active width (axis) component
Definition: TGLManip.h:33
void CalcDrawScale(const TGLBoundingBox &box, const TGLCamera &camera, Double_t &base, TGLVector3 axis[3]) const
Calculates base and axis scale factor (in world units) for drawing manipulators with reasonable size ...
Definition: TGLManip.cxx:156
UInt_t fSelectedWidget
manipulated shape
Definition: TGLManip.h:32
virtual ~TGLManip()
Destroy manipulator object.
Definition: TGLManip.cxx:90
TGLPhysicalShape * fShape
Definition: TGLManip.h:31
virtual Bool_t HandleMotion(const Event_t &event, const TGLCamera &camera)
Handle a mouse button event - return kTRUE if widget selection change kFALSE otherwise.
Definition: TGLManip.cxx:145
Concrete physical shape - a GL drawable.
static const UChar_t fgRed[4]
Definition: TGLUtil.h:1048
static const UChar_t fgBlue[4]
Definition: TGLUtil.h:1050
static const UChar_t fgGrey[4]
Definition: TGLUtil.h:1053
static const UChar_t fgGreen[4]
Definition: TGLUtil.h:1049
static const UChar_t fgYellow[4]
Definition: TGLUtil.h:1051
3 component (x/y/z) vector class.
Definition: TGLUtil.h:247
Double_t Mag() const
Definition: TGLUtil.h:297
void SetX(SCoord_t x)
Definition: TPoint.h:48
void SetY(SCoord_t y)
Definition: TPoint.h:49
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
T Mag(const SVector< T, D > &rhs)
Vector magnitude (Euclidian norm) Compute : .
Definition: Functions.h:252
EGEventType fType
Definition: GuiTypes.h:174
Int_t fY
Definition: GuiTypes.h:177
Int_t fX
Definition: GuiTypes.h:177
UInt_t fCode
Definition: GuiTypes.h:179