Logo ROOT  
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
19Translation manipulator - attaches to physical shape and draws local
20axes widgets with arrow heads. User can mouse over (turns yellow) and
21L click/drag to translate along this axis.
22Widgets 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
55void TGLTransManip::Draw(const TGLCamera & camera) const
56{
57 if (!fShape) {
58 return;
59 }
60
61 // Get draw scales
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
78 glPushName(1);
79 TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadArrow,
80 baseScale, ColorFor(1));
81 glPopName();
82 } else {
83 TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadArrow,
84 baseScale, TGLUtil::fgGrey);
85 }
87 glPushName(2);
88 TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadArrow,
89 baseScale, ColorFor(2));
90 glPopName();
91 } else {
92 TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadArrow,
93 baseScale, TGLUtil::fgGrey);
94 }
96 glPushName(3);
97 TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadArrow,
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
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
TGLVertex3 Center() const
const TGLVector3 & Axis(UInt_t i, Bool_t normalised=kTRUE) const
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:44
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
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
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
TGLPhysicalShape * fShape
Definition: TGLManip.h:31
Concrete physical shape - a GL drawable.
const TGLBoundingBox & BoundingBox() const
void Translate(const TGLVector3 &vect)
EManip GetManip() const
Translation manipulator - attaches to physical shape and draws local axes widgets with arrow heads.
Definition: TGLTransManip.h:28
virtual ~TGLTransManip()
Destroy the translation manipulator.
virtual Bool_t HandleMotion(const Event_t &event, const TGLCamera &camera)
Handle mouse motion over manipulator - if active (selected widget) translate physical along selected ...
TGLTransManip()
Construct translation manipulator not bound to any physical shape.
virtual void Draw(const TGLCamera &camera) const
Draw translation manipulator - tubes with arrow heads, in local axes of attached shape,...
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:2352
static const UChar_t fgWhite[4]
Definition: TGLUtil.h:1052
@ kLineHeadArrow
Definition: TGLUtil.h:947
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,...
Definition: TGLUtil.cxx:2367
static const UChar_t fgGrey[4]
Definition: TGLUtil.h:1053
3 component (x/y/z) vector class.
Definition: TGLUtil.h:247
SCoord_t GetY() const
Definition: TPoint.h:47
void SetX(SCoord_t x)
Definition: TPoint.h:48
void SetY(SCoord_t y)
Definition: TPoint.h:49
SCoord_t GetX() const
Definition: TPoint.h:46
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
#define Dot(u, v)
Definition: normal.c:49
Int_t fY
Definition: GuiTypes.h:177
Int_t fX
Definition: GuiTypes.h:177