Logo ROOT   6.10/09
Reference Guide
TGLTransManip.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 "TGLTransManip.h"
13 #include "TGLPhysicalShape.h"
14 #include "TGLCamera.h"
15 #include "TGLIncludes.h"
16 
17 /** \class TGLTransManip
18 \ingroup opengl
19 Translation manipulator - attaches to physical shape and draws local
20 axes widgets with arrow heads. User can mouse over (turns yellow) and
21 L click/drag to translate along this axis.
22 Widgets use standard 3D package axes colours: X red, Y green, Z blue.
23 */
24 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Construct translation manipulator not bound to any physical shape.
29 
31 {
32 }
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Construct translation manipulator, attached to supplied TGLViewer
36 /// 'viewer', bound to TGLPhysicalShape 'shape'.
37 
39  TGLManip(shape)
40 {
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Destroy the translation manipulator
45 
47 {
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Draw translation manipulator - tubes with arrow heads, in local axes of
52 /// attached shape, in red(X), green(Y) and blue(Z), with white center sphere.
53 /// If selected widget (mouse over) this is drawn in active colour (yellow).
54 
55 void TGLTransManip::Draw(const TGLCamera & camera) const
56 {
57  if (!fShape) {
58  return;
59  }
60 
61  // Get draw scales
62  const TGLBoundingBox & box = fShape->BoundingBox();
63  Double_t baseScale;
64  TGLVector3 axisScale[3];
65  CalcDrawScale(box, camera, baseScale, axisScale);
66 
67  // Get permitted manipulations on shape
69 
70  glEnable(GL_BLEND);
71  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
72  glDisable(GL_CULL_FACE);
73 
74  // Draw three axis widgets out of bounding box where permitted
75  // Not drawing will prevent interaction
76  // GL name loading for hit testing - 0 reserved for no selection
77  if (manip & TGLPhysicalShape::kTranslateX) {
78  glPushName(1);
80  baseScale, ColorFor(1));
81  glPopName();
82  } else {
84  baseScale, TGLUtil::fgGrey);
85  }
86  if (manip & TGLPhysicalShape::kTranslateY) {
87  glPushName(2);
89  baseScale, ColorFor(2));
90  glPopName();
91  } else {
93  baseScale, TGLUtil::fgGrey);
94  }
95  if (manip & TGLPhysicalShape::kTranslateZ) {
96  glPushName(3);
98  baseScale, ColorFor(3));
99  glPopName();
100  } else {
101  TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadArrow,
102  baseScale, TGLUtil::fgGrey);
103  }
104  // Draw white center sphere
105  TGLUtil::DrawSphere(box.Center(), baseScale/2.0, TGLUtil::fgWhite);
106 
107  glEnable(GL_CULL_FACE);
108  glDisable(GL_BLEND);
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Handle mouse motion over manipulator - if active (selected
113 /// widget) translate physical along selected widget (axis) of the
114 /// manipulator, so it tracks mouse action. Returns kTRUE if redraw
115 /// required kFALSE otherwise.
116 
118  const TGLCamera & camera)
119 {
120  if (fActive) {
121  // Find mouse delta projected into world at attached object center
122  TGLVector3 shift =
124  event.fX - fLastMouse.GetX(),
125  -event.fY + fLastMouse.GetY() ); // Y inverted
126 
127  // Now project this delta onto the current widget (axis) to give
128  // a constrained shift along this
129  UInt_t axisIndex = fSelectedWidget - 1; // Ugg sort out axis / widget id mapping
130  TGLVector3 widgetAxis = fShape->BoundingBox().Axis(axisIndex, kTRUE);
131  TGLVector3 constrainedShift = widgetAxis * Dot(shift, widgetAxis);
132  fShape->Translate(constrainedShift);
133 
134  fLastMouse.SetX(event.fX);
135  fLastMouse.SetY(event.fY);
136 
137  return kTRUE;
138  }
139  return kFALSE;
140 }
141 
Abstract base class for viewer manipulators, which allow direct in viewer manipulation of a (TGlPhysi...
Definition: TGLManip.h:28
void SetX(SCoord_t x)
Definition: TPoint.h:49
TGLVertex3 Center() const
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:43
void Translate(const TGLVector3 &vect)
static void DrawLine(const TGLLine3 &line, ELineHeadShape head, Double_t size, const UChar_t rgba[4])
Draw thick line (tube) defined by 'line', with head at end shape 'head' - box/arrow/none, (head) size 'size', color 'rgba'.
Definition: TGLUtil.cxx:2333
Int_t fY
Definition: GuiTypes.h:177
TGLTransManip()
Construct translation manipulator not bound to any physical shape.
static const UChar_t fgGrey[4]
Definition: TGLUtil.h:1052
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t HandleMotion(const Event_t &event, const TGLCamera &camera)
Handle mouse motion over manipulator - if active (selected widget) translate physical along selected ...
SCoord_t GetY() const
Definition: TPoint.h:48
SCoord_t GetX() const
Definition: TPoint.h:47
UInt_t fSelectedWidget
manipulated shape
Definition: TGLManip.h:32
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
virtual ~TGLTransManip()
Destroy the translation manipulator.
void SetY(SCoord_t y)
Definition: TPoint.h:50
Concrete physical shape - a GL drawable.
EManip GetManip() const
static void DrawSphere(const TGLVertex3 &position, Double_t radius, const UChar_t rgba[4])
Draw sphere, centered on vertex 'position', with radius 'radius', color 'rgba'.
Definition: TGLUtil.cxx:2318
const TGLBoundingBox & BoundingBox() const
3 component (x/y/z) vector class.
Definition: TGLUtil.h:246
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
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
Bool_t fActive
active width (axis) component
Definition: TGLManip.h:33
static const UChar_t fgWhite[4]
Definition: TGLUtil.h:1051
TGLPhysicalShape * fShape
Definition: TGLManip.h:31
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:92
Double_t Dot(const TGLVector3 &v1, const TGLVector3 &v2)
Definition: TGLUtil.h:318
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
virtual void Draw(const TGLCamera &camera) const
Draw translation manipulator - tubes with arrow heads, in local axes of attached shape, in red(X), green(Y) and blue(Z), with white center sphere.
Concrete class describing an orientated (free) or axis aligned box of 8 vertices. ...
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
const TGLVector3 & Axis(UInt_t i, Bool_t normalised=kTRUE) const
const Bool_t kTRUE
Definition: RtypesCore.h:91
Int_t fX
Definition: GuiTypes.h:177
Translation manipulator - attaches to physical shape and draws local axes widgets with arrow heads...
Definition: TGLTransManip.h:27