Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TGLScaleManip.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 "TGLScaleManip.h"
13#include "TGLPhysicalShape.h"
14#include "TGLCamera.h"
15#include "TGLIncludes.h"
16
17/** \class TGLScaleManip
18\ingroup opengl
19Scale manipulator - attaches to physical shape and draws local axes
20widgets with box heads. User can mouse over (turns yellow) and L
21click/drag to scale along this axis.
22*/
23
24
25////////////////////////////////////////////////////////////////////////////////
26/// Construct scale manipulator not bound to any physical shape.
27
31
32////////////////////////////////////////////////////////////////////////////////
33/// Construct scale manipulator bound to TGLPhysicalShape 'shape'.
34
39
40////////////////////////////////////////////////////////////////////////////////
41/// Destroy the scale manipulator
42
46
47////////////////////////////////////////////////////////////////////////////////
48/// Draw scale manipulator - tubes with box heads, in local axes of
49/// attached shape, in red(X), green(Y) and blue(Z), with white center sphere.
50/// If selected widget (mouse over) this is drawn in active colour (yellow).
51
52void TGLScaleManip::Draw(const TGLCamera & camera) const
53{
54 if (!fShape) {
55 return;
56 }
57
58 // Get draw scales
59 const TGLBoundingBox & box = fShape->BoundingBox();
60 Double_t baseScale;
61 TGLVector3 axisScale[3];
62 CalcDrawScale(box, camera, baseScale, axisScale);
63
64 // Get permitted manipulations on shape
65 TGLPhysicalShape::EManip manip = fShape->GetManip();
66
67 glEnable(GL_BLEND);
68 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
69 glDisable(GL_CULL_FACE);
70
71 // Draw three axis widgets out of bounding box where permitted
72 // Not drawing will prevent interaction
73 // GL name loading for hit testing - 0 reserved for no selection
74 if (manip & TGLPhysicalShape::kScaleX) {
75 glPushName(1);
76 TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadBox,
77 baseScale, ColorFor(1));
78 glPopName();
79 } else {
80 TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadBox,
81 baseScale, TGLUtil::fgGrey);
82 }
83 if (manip & TGLPhysicalShape::kScaleY) {
84 glPushName(2);
85 TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadBox,
86 baseScale, ColorFor(2));
87 glPopName();
88 } else {
89 TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadBox,
90 baseScale, TGLUtil::fgGrey);
91 }
92 if (manip & TGLPhysicalShape::kScaleZ) {
93 glPushName(3);
94 TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadBox,
95 baseScale, ColorFor(3));
96 glPopName();
97 } else {
98 TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadBox,
99 baseScale, TGLUtil::fgGrey);
100 }
101 // Draw white center sphere
102 TGLUtil::DrawSphere(box.Center(), baseScale/2.0, TGLUtil::fgWhite);
103
104 glEnable(GL_CULL_FACE);
105 glDisable(GL_BLEND);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Handle mouse button event over manipulator - returns kTRUE if
110/// redraw required kFALSE otherwise.
111
113 const TGLCamera & camera)
114{
115 if (event.fType == kButtonPress && fSelectedWidget != 0) {
116 fStartScale = fShape->GetScale();
117 }
118
119 return TGLManip::HandleButton(event, camera);
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Handle mouse motion over manipulator - if active (selected
124/// widget) scale physical along selected widget (axis) of the
125/// manipulator, so it tracks mouse action. Returns kTRUE if redraw
126/// required kFALSE otherwise.
127
129 const TGLCamera & camera)
130{
131 if (fActive) {
132 // Find mouse delta projected into world at attached object center
133 TGLVector3 shift = camera.ViewportDeltaToWorld(fShape->BoundingBox().Center(),
134 event.fX - fFirstMouse.GetX(),
135 -event.fY + fFirstMouse.GetY()); // Y inverted
136
137 UInt_t axisIndex = fSelectedWidget - 1; // Ugg sort out axis / widget id mapping
138 TGLVector3 widgetAxis = fShape->BoundingBox().Axis(axisIndex, kTRUE);
139
140 // Scale by projected screen factor
141 TGLVector3 screenScale = camera.ViewportDeltaToWorld(fShape->BoundingBox().Center(), 500, 500);
142 Double_t factor = -5.0*Dot(shift, widgetAxis) / screenScale.Mag();
143
144 TGLVector3 newScale = fStartScale;
145 newScale[axisIndex] += factor;
146 LimitScale(newScale[axisIndex]);
147 fShape->Scale(newScale);
148
149 fLastMouse.SetX(event.fX);
150 fLastMouse.SetY(event.fY);
151
152 return kTRUE;
153 }
154 return kFALSE;
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Clamp scale to sizable values: 1000 - 1/1000
159/// Guards against div by zero problems.
160
162{
163 if (factor < 1e-4) {
164 factor = 1e-4;
165 }
166 if (factor > 1e+4) {
167 factor = 1e+4;
168 }
169}
@ kButtonPress
Definition GuiTypes.h:61
#define e(i)
Definition RSha256.hxx:103
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
TPoint fFirstMouse
! first (start) mouse position (in WINDOW coords)
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:114
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.
TGLVector3 fStartScale
! initial scaling factors
~TGLScaleManip() override
Destroy the scale manipulator.
void LimitScale(Double_t &factor) const
Clamp scale to sizable values: 1000 - 1/1000 Guards against div by zero problems.
Bool_t HandleMotion(const Event_t &event, const TGLCamera &camera) override
Handle mouse motion over manipulator - if active (selected widget) scale physical along selected widg...
TGLScaleManip()
Construct scale manipulator not bound to any physical shape.
void Draw(const TGLCamera &camera) const override
Draw scale manipulator - tubes with box heads, in local axes of attached shape, in red(X),...
Bool_t HandleButton(const Event_t &event, const TGLCamera &camera) override
Handle mouse button event over manipulator - returns kTRUE if redraw required kFALSE otherwise.
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
@ kLineHeadBox
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
Double_t Mag() const
Definition TGLUtil.h:298
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
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:176
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:179
Int_t fX
Definition GuiTypes.h:179