Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
27
28////////////////////////////////////////////////////////////////////////////////
29/// Constructor.
30
32 ERole role, EState state) :
33 TGLOverlayElement(role, state),
34 fXPos(x), fYPos(y), fSize(s),
35 fSelAxis(-1), fInDrag(kFALSE)
36{
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Mouse has entered overlay area.
41
46
47////////////////////////////////////////////////////////////////////////////////
48/// Handle overlay event.
49/// Return TRUE if event was handled.
50
53 Event_t* event)
54{
55 if (selRec.GetN() < 2) return kFALSE;
56 Int_t recID = selRec.GetItem(1);
57
58 if (recID == 4)
59 fSelAxis = 4;
60 else
61 fSelAxis = 0;
62
63 switch (event->fType)
64 {
65 case kButtonPress:
66 {
67 if (recID == 4)
68 fInDrag = kTRUE;
69 return kTRUE;
70 }
71 case kButtonRelease:
72 {
74 return kTRUE;
75 }
76 case kMotionNotify:
77 {
78 if (fInDrag)
79 {
80 const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
81 if (vp.Width() == 0 || vp.Height() == 0) return kFALSE;
82
83 fXPos = TMath::Range(0.0f, 1.0f, (Float_t)(event->fX) / vp.Width());
84 fYPos = TMath::Range(0.0f, 1.0f, 1.0f - (Float_t)(event->fY) / vp.Height());
85 }
86 return kTRUE;
87 }
88 default:
89 {
90 return kFALSE;
91 }
92 }
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Mouse has left overlay area.
97
99{
100 fSelAxis = -1;
101 fInDrag = kFALSE;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Render the camera axis arrows.
106
108{
110
111 rnrCtx.ProjectionMatrixPushIdentity();
112 glPushMatrix();
114 glTranslatef(-1.0f, -1.0f, 0.0f);
115 glScalef(2.0f, 2.0f, -2.0f);
116 glTranslatef(fXPos, fYPos, -0.25f);
117
118 Float_t aspect= rnrCtx.RefCamera().RefViewport().Aspect();
119 if (aspect > 1)
120 glScalef(1.0f / aspect, 1.0f, 1.0f);
121 else if (aspect < 1)
122 glScalef(1.0f, aspect, 1.0f);
123
124 Float_t dr[2];
126 glDepthRange(0, 0.01);
127
130 const TGLMatrix &mv = rnrCtx.RefCamera().RefModelViewMatrix();
131
132 glPushName(1);
133 mv.GetBaseVec(1, e);
134 e *= fSize;
137
138 glLoadName(2);
139 mv.GetBaseVec(2, e);
140 e *= fSize;
143
144 glLoadName(3);
145 mv.GetBaseVec(3, e);
146 e *= fSize;
149
150 glLoadName(4);
152 fSelAxis == 4 ? TGLUtil::fgYellow : rnrCtx.ColorSet().Foreground().CArr());
153
154 glPopName();
155
156 glDepthRange(dr[0], dr[1]);
157
158 glPopMatrix();
159 rnrCtx.ProjectionMatrixPop();
160}
dim_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
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Render(TGLRnrCtx &rnrCtx) override
Render the camera axis arrows.
Bool_t MouseEnter(TGLOvlSelectRecord &selRec) override
Mouse has entered overlay area.
void MouseLeave() override
Mouse has left overlay area.
TGLCameraGuide(const TGLCameraGuide &)=delete
Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event) override
Handle overlay event.
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
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
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 fgRed[4]
Definition TGLUtil.h:1421
@ 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 fgBlue[4]
Definition TGLUtil.h:1423
static const UChar_t fgGreen[4]
Definition TGLUtil.h:1422
static const UChar_t fgYellow[4]
Definition TGLUtil.h:1424
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
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Returns x if lb < x < up, lb if x < lb and ub if x > ub.
Definition TMathBase.h:303
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Int_t fX
Definition GuiTypes.h:178