Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
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=nullptr) const
Apply a 2D viewport delta (shift) to the projection of worldRef onto viewport, returning the resultan...
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:94
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:153
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.
Bool_t HandleMotion(const Event_t &event, const TGLCamera &camera) override
Handle mouse motion over manipulator - if active (selected widget) translate physical along selected ...
void Draw(const TGLCamera &camera) const override
Draw translation manipulator - tubes with arrow heads, in local axes of attached shape,...
~TGLTransManip() override
Destroy the translation manipulator.
TGLTransManip()
Construct translation manipulator not bound to any physical 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:2357
static const UChar_t fgWhite[4]
Definition TGLUtil.h:1060
@ kLineHeadArrow
Definition TGLUtil.h:951
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:2372
static const UChar_t fgGrey[4]
Definition TGLUtil.h:1061
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
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
Event structure.
Definition GuiTypes.h:174
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Int_t fX
Definition GuiTypes.h:178