Logo ROOT   6.14/05
Reference Guide
TGLCameraGuide.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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 "TGLCameraGuide.h"
13 #include "TGLRnrCtx.h"
14 #include "TGLCamera.h"
15 #include "TGLUtil.h"
16 #include "TGLIncludes.h"
17 #include "TGLSelectRecord.h"
18 
19 #include "TMath.h"
20 
21 /** \class TGLCameraGuide
22 \ingroup opengl
23 Draws arrows showing camera orientation in the overlay.
24 X, Y position is in range 0, 1.
25 */
26 
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Constructor.
31 
33  ERole role, EState state) :
34  TGLOverlayElement(role, state),
35  fXPos(x), fYPos(y), fSize(s),
36  fSelAxis(-1), fInDrag(kFALSE)
37 {
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Mouse has entered overlay area.
42 
44 {
45  return kTRUE;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Handle overlay event.
50 /// Return TRUE if event was handled.
51 
53  TGLOvlSelectRecord& selRec,
54  Event_t* event)
55 {
56  if (selRec.GetN() < 2) return kFALSE;
57  Int_t recID = selRec.GetItem(1);
58 
59  if (recID == 4)
60  fSelAxis = 4;
61  else
62  fSelAxis = 0;
63 
64  switch (event->fType)
65  {
66  case kButtonPress:
67  {
68  if (recID == 4)
69  fInDrag = kTRUE;
70  return kTRUE;
71  }
72  case kButtonRelease:
73  {
74  fInDrag = kFALSE;
75  return kTRUE;
76  }
77  case kMotionNotify:
78  {
79  if (fInDrag)
80  {
81  const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
82  if (vp.Width() == 0 || vp.Height() == 0) return kFALSE;
83 
84  fXPos = TMath::Range(0.0f, 1.0f, (Float_t)(event->fX) / vp.Width());
85  fYPos = TMath::Range(0.0f, 1.0f, 1.0f - (Float_t)(event->fY) / vp.Height());
86  }
87  return kTRUE;
88  }
89  default:
90  {
91  return kFALSE;
92  }
93  }
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Mouse has left overlay area.
98 
100 {
101  fSelAxis = -1;
102  fInDrag = kFALSE;
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Render the camera axis arrows.
107 
109 {
110  TGLCapabilitySwitch lgt_off(GL_LIGHTING, kFALSE);
111 
113  glPushMatrix();
114  glLoadIdentity();
115  glTranslatef(-1.0f, -1.0f, 0.0f);
116  glScalef(2.0f, 2.0f, -2.0f);
117  glTranslatef(fXPos, fYPos, -0.25f);
118 
119  Float_t aspect= rnrCtx.RefCamera().RefViewport().Aspect();
120  if (aspect > 1)
121  glScalef(1.0f / aspect, 1.0f, 1.0f);
122  else if (aspect < 1)
123  glScalef(1.0f, aspect, 1.0f);
124 
125  Float_t dr[2];
126  glGetFloatv(GL_DEPTH_RANGE, dr);
127  glDepthRange(0, 0.01);
128 
129  TGLVertex3 c;
130  TGLVector3 e;
131  const TGLMatrix &mv = rnrCtx.RefCamera().RefModelViewMatrix();
132 
133  glPushName(1);
134  mv.GetBaseVec(1, e);
135  e *= fSize;
138 
139  glLoadName(2);
140  mv.GetBaseVec(2, e);
141  e *= fSize;
144 
145  glLoadName(3);
146  mv.GetBaseVec(3, e);
147  e *= fSize;
150 
151  glLoadName(4);
152  TGLUtil::DrawSphere(c, 0.08*fSize,
153  fSelAxis == 4 ? TGLUtil::fgYellow : rnrCtx.ColorSet().Foreground().CArr());
154 
155  glPopName();
156 
157  glDepthRange(dr[0], dr[1]);
158 
159  glPopMatrix();
160  rnrCtx.ProjectionMatrixPop();
161 }
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
static const UChar_t fgYellow[4]
Definition: TGLUtil.h:1050
void ProjectionMatrixPushIdentity()
Definition: TGLRnrCtx.cxx:423
float Float_t
Definition: RtypesCore.h:53
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:596
static void DrawLine(const TGLLine3 &line, ELineHeadShape head, Double_t size, const UChar_t rgba[4])
Draw thick line (tube) defined by &#39;line&#39;, with head at end shape &#39;head&#39; - box/arrow/none, (head) size &#39;size&#39;, color &#39;rgba&#39;.
Definition: TGLUtil.cxx:2333
TGLCamera & RefCamera()
Definition: TGLRnrCtx.h:157
Int_t fY
Definition: GuiTypes.h:177
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Definition: TMathBase.h:232
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TGLRect & RefViewport()
Definition: TGLCamera.h:128
Double_t Aspect() const
Definition: TGLUtil.h:501
An overlay element.
Definition: TGLOverlay.h:22
static const UChar_t fgRed[4]
Definition: TGLUtil.h:1047
Double_t x[n]
Definition: legend1.C:17
const TGLMatrix & RefModelViewMatrix() const
Definition: TGLCamera.h:121
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:82
static void DrawSphere(const TGLVertex3 &position, Double_t radius, const UChar_t rgba[4])
Draw sphere, centered on vertex &#39;position&#39;, with radius &#39;radius&#39;, color &#39;rgba&#39;.
Definition: TGLUtil.cxx:2318
const UChar_t * CArr() const
Definition: TGLUtil.h:799
Viewport (pixel base) 2D rectangle class.
Definition: TGLUtil.h:422
3 component (x/y/z) vector class.
Definition: TGLUtil.h:246
void ProjectionMatrixPop()
Definition: TGLRnrCtx.cxx:438
static const UChar_t fgBlue[4]
Definition: TGLUtil.h:1049
EGEventType fType
Definition: GuiTypes.h:174
virtual Bool_t MouseEnter(TGLOvlSelectRecord &selRec)
Mouse has entered overlay area.
virtual Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event)
Handle overlay event.
Int_t Width() const
Definition: TGLUtil.h:451
static const UChar_t fgGreen[4]
Definition: TGLUtil.h:1048
const Bool_t kFALSE
Definition: RtypesCore.h:88
Draws arrows showing camera orientation in the overlay.
#define ClassImp(name)
Definition: Rtypes.h:359
virtual void MouseLeave()
Mouse has left overlay area.
UInt_t GetItem(Int_t i) const
Double_t y[n]
Definition: legend1.C:17
static constexpr double s
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
TGLCameraGuide(const TGLCameraGuide &)
Int_t GetN() const
#define c(i)
Definition: RSha256.hxx:101
Selection record for overlay objects.
Int_t Height() const
Definition: TGLUtil.h:453
TGLColorSet & ColorSet()
Return reference to current color-set (top of the stack).
Definition: TGLRnrCtx.cxx:278
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void Render(TGLRnrCtx &rnrCtx)
Render the camera axis arrows.
TGLColor & Foreground()
Definition: TGLUtil.h:850
Int_t fX
Definition: GuiTypes.h:177
TGLVector3 GetBaseVec(Int_t b) const
Definition: TGLUtil.h:753