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