Logo ROOT  
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
23Draws arrows showing camera orientation in the overlay.
24X, 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,
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 {
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
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);
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}
int Int_t
Definition: CPyCppyy.h:43
size_t fSize
@ kButtonRelease
Definition: GuiTypes.h:60
@ kButtonPress
Definition: GuiTypes.h:60
@ kMotionNotify
Definition: GuiTypes.h:61
#define c(i)
Definition: RSha256.hxx:101
#define e(i)
Definition: RSha256.hxx:103
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
float Float_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
Draws arrows showing camera orientation in the overlay.
virtual void Render(TGLRnrCtx &rnrCtx)
Render the camera axis arrows.
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.
virtual void MouseLeave()
Mouse has left overlay area.
TGLCameraGuide(const TGLCameraGuide &)
const TGLMatrix & RefModelViewMatrix() const
Definition: TGLCamera.h:121
TGLRect & RefViewport()
Definition: TGLCamera.h:128
TGLColor & Foreground()
Definition: TGLUtil.h:852
const UChar_t * CArr() const
Definition: TGLUtil.h:800
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:598
TGLVector3 GetBaseVec(Int_t b) const
Definition: TGLUtil.h:754
An overlay element.
Definition: TGLOverlay.h:23
Selection record for overlay objects.
Viewport (pixel base) 2D rectangle class.
Definition: TGLUtil.h:422
Int_t Height() const
Definition: TGLUtil.h:452
Int_t Width() const
Definition: TGLUtil.h:450
Double_t Aspect() const
Definition: TGLUtil.h:500
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:41
TGLCamera & RefCamera()
Definition: TGLRnrCtx.h:157
TGLColorSet & ColorSet()
Return reference to current color-set (top of the stack).
Definition: TGLRnrCtx.cxx:276
void ProjectionMatrixPushIdentity()
Definition: TGLRnrCtx.cxx:421
void ProjectionMatrixPop()
Definition: TGLRnrCtx.cxx:436
UInt_t GetItem(Int_t i) const
Int_t GetN() const
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:2351
static const UChar_t fgRed[4]
Definition: TGLUtil.h:1049
@ kLineHeadArrow
Definition: TGLUtil.h:948
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:2366
static const UChar_t fgBlue[4]
Definition: TGLUtil.h:1051
static const UChar_t fgGreen[4]
Definition: TGLUtil.h:1050
static const UChar_t fgYellow[4]
Definition: TGLUtil.h:1052
3 component (x/y/z) vector class.
Definition: TGLUtil.h:248
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:84
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
static constexpr double s
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Definition: TMathBase.h:244
Event structure.
Definition: GuiTypes.h:174