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
25
26////////////////////////////////////////////////////////////////////////////////
27/// Construct translation manipulator not bound to any physical shape.
28
32
33////////////////////////////////////////////////////////////////////////////////
34/// Construct translation manipulator, attached to supplied TGLViewer
35/// 'viewer', bound to TGLPhysicalShape 'shape'.
36
41
42////////////////////////////////////////////////////////////////////////////////
43/// Destroy the translation manipulator
44
48
49////////////////////////////////////////////////////////////////////////////////
50/// Draw translation manipulator - tubes with arrow heads, in local axes of
51/// attached shape, in red(X), green(Y) and blue(Z), with white center sphere.
52/// If selected widget (mouse over) this is drawn in active colour (yellow).
53
54void TGLTransManip::Draw(const TGLCamera & camera) const
55{
56 if (!fShape) {
57 return;
58 }
59
60 // Get draw scales
61 const TGLBoundingBox & box = fShape->BoundingBox();
62 Double_t baseScale;
63 TGLVector3 axisScale[3];
64 CalcDrawScale(box, camera, baseScale, axisScale);
65
66 // Get permitted manipulations on shape
67 TGLPhysicalShape::EManip manip = fShape->GetManip();
68
69 glEnable(GL_BLEND);
70 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
71 glDisable(GL_CULL_FACE);
72
73 // Draw three axis widgets out of bounding box where permitted
74 // Not drawing will prevent interaction
75 // GL name loading for hit testing - 0 reserved for no selection
77 glPushName(1);
78 TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadArrow,
79 baseScale, ColorFor(1));
80 glPopName();
81 } else {
82 TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadArrow,
83 baseScale, TGLUtil::fgGrey);
84 }
86 glPushName(2);
87 TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadArrow,
88 baseScale, ColorFor(2));
89 glPopName();
90 } else {
91 TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadArrow,
92 baseScale, TGLUtil::fgGrey);
93 }
95 glPushName(3);
96 TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadArrow,
97 baseScale, ColorFor(3));
98 glPopName();
99 } else {
100 TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadArrow,
101 baseScale, TGLUtil::fgGrey);
102 }
103 // Draw white center sphere
104 TGLUtil::DrawSphere(box.Center(), baseScale/2.0, TGLUtil::fgWhite);
105
106 glEnable(GL_CULL_FACE);
107 glDisable(GL_BLEND);
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Handle mouse motion over manipulator - if active (selected
112/// widget) translate physical along selected widget (axis) of the
113/// manipulator, so it tracks mouse action. Returns kTRUE if redraw
114/// required kFALSE otherwise.
115
117 const TGLCamera & camera)
118{
119 if (fActive) {
120 // Find mouse delta projected into world at attached object center
121 TGLVector3 shift =
122 camera.ViewportDeltaToWorld( fShape->BoundingBox().Center(),
123 event.fX - fLastMouse.GetX(),
124 -event.fY + fLastMouse.GetY() ); // Y inverted
125
126 // Now project this delta onto the current widget (axis) to give
127 // a constrained shift along this
128 UInt_t axisIndex = fSelectedWidget - 1; // Ugg sort out axis / widget id mapping
129 TGLVector3 widgetAxis = fShape->BoundingBox().Axis(axisIndex, kTRUE);
130 TGLVector3 constrainedShift = widgetAxis * Dot(shift, widgetAxis);
131 fShape->Translate(constrainedShift);
132
133 fLastMouse.SetX(event.fX);
134 fLastMouse.SetY(event.fY);
135
136 return kTRUE;
137 }
138 return kFALSE;
139}
140
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
Double_t Dot(const TGLVector3 &v1, const TGLVector3 &v2)
Definition TGLUtil.h:317
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: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...
TPoint fLastMouse
! last (latest) 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:93
Bool_t fActive
! manipulator is active?
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:152
UInt_t fSelectedWidget
! active width (axis) component
Definition TGLManip.h:32
TGLPhysicalShape * fShape
! manipulated shape
Definition TGLManip.h:31
TGLManip(const TGLManip &)
Copy constructor.
Definition TGLManip.cxx:57
Concrete physical shape - a GL drawable.
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:2348
static const UChar_t fgWhite[4]
Definition TGLUtil.h:1425
@ 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:2363
static const UChar_t fgGrey[4]
Definition TGLUtil.h:1426
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Event structure.
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:179
Int_t fX
Definition GuiTypes.h:179