Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveBoxGL.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Matevz Tadel, 2010
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 "TEveBoxGL.h"
13#include "TEveBox.h"
14
15#include "TGLRnrCtx.h"
16#include "TGLIncludes.h"
17
18#include "TMath.h"
19
20/** \class TEveBoxGL
21\ingroup TEve
22OpenGL renderer class for TEveBox.
23*/
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor.
28
30 TGLObject(), fM(nullptr)
31{
32 // fDLCache = kFALSE; // Disable display list.
33}
34
35////////////////////////////////////////////////////////////////////////////////
36/// Set model object.
37
39{
41 return kTRUE;
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Set bounding box.
46
48{
49 // !! This ok if master sub-classed from TAttBBox
50 SetAxisAlignedBBox(((TEveBox*)fExternalObj)->AssertBBox());
51}
52
53namespace
54{
55 void subtract_and_normalize(const Float_t a[3], const Float_t b[3],
56 Float_t o[3])
57 {
58 // Calculate a - b and normalize the result.
59 o[0] = a[0] - b[0];
60 o[1] = a[1] - b[1];
61 o[2] = a[2] - b[2];
62 Float_t d = sqrtf(o[0]*o[0] + o[1]*o[1] + o[2]*o[2]);
63 if (d != 0)
64 {
65 d = 1.0f / d;
66 o[0] *= d;
67 o[1] *= d;
68 o[2] *= d;
69 }
70 }
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Render box with without normals.
75/// To be used with lightning off, for outline.
76
77void TEveBoxGL::RenderOutline(const Float_t p[8][3]) const
78{
79 glBegin(GL_LINE_STRIP);
80 glVertex3fv(p[0]); glVertex3fv(p[1]);
81 glVertex3fv(p[5]); glVertex3fv(p[6]);
82 glVertex3fv(p[2]); glVertex3fv(p[3]);
83 glVertex3fv(p[7]); glVertex3fv(p[4]);
84 glVertex3fv(p[0]); glVertex3fv(p[3]);
85 glEnd();
86
87 glBegin(GL_LINES);
88 glVertex3fv(p[1]); glVertex3fv(p[2]);
89 glVertex3fv(p[4]); glVertex3fv(p[5]);
90 glVertex3fv(p[6]); glVertex3fv(p[7]);
91 glEnd();
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Render box with standard axis-aligned normals.
96
97void TEveBoxGL::RenderBoxStdNorm(const Float_t p[8][3]) const
98{
100
101 // bottom: 0123
102 glNormal3f(0, 0, -1);
103 glVertex3fv(p[0]); glVertex3fv(p[1]);
104 glVertex3fv(p[2]); glVertex3fv(p[3]);
105 // top: 7654
106 glNormal3f(0, 0, 1);
107 glVertex3fv(p[7]); glVertex3fv(p[6]);
108 glVertex3fv(p[5]); glVertex3fv(p[4]);
109 // back: 0451
110 glNormal3f(0, 1, 0);
111 glVertex3fv(p[0]); glVertex3fv(p[4]);
112 glVertex3fv(p[5]); glVertex3fv(p[1]);
113 // front: 3267
114 glNormal3f(0, -1, 0);
115 glVertex3fv(p[3]); glVertex3fv(p[2]);
116 glVertex3fv(p[6]); glVertex3fv(p[7]);
117 // left: 0374
118 glNormal3f(-1, 0, 0);
119 glVertex3fv(p[0]); glVertex3fv(p[3]);
120 glVertex3fv(p[7]); glVertex3fv(p[4]);
121 // right: 1562
122 glNormal3f(1, 0, 0);
123 glVertex3fv(p[1]); glVertex3fv(p[5]);
124 glVertex3fv(p[6]); glVertex3fv(p[2]);
125
126 glEnd();
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Render box, calculate normals on the fly from first three points.
131
133{
134 Float_t e[6][3], n[3];
135 subtract_and_normalize(p[1], p[0], e[0]);
136 subtract_and_normalize(p[3], p[0], e[1]);
137 subtract_and_normalize(p[4], p[0], e[2]);
138 subtract_and_normalize(p[5], p[6], e[3]);
139 subtract_and_normalize(p[7], p[6], e[4]);
140 subtract_and_normalize(p[2], p[6], e[5]);
141
143
144 // bottom: 0123
145 glNormal3fv(TMath::Cross(e[0], e[1], n));
146 glVertex3fv(p[0]); glVertex3fv(p[1]);
147 glVertex3fv(p[2]); glVertex3fv(p[3]);
148 // top: 7654
149 glNormal3fv(TMath::Cross(e[3], e[4], n));
150 glVertex3fv(p[7]); glVertex3fv(p[6]);
151 glVertex3fv(p[5]); glVertex3fv(p[4]);
152 // back: 0451
153 glNormal3fv(TMath::Cross(e[2], e[0], n));
154 glVertex3fv(p[0]); glVertex3fv(p[4]);
155 glVertex3fv(p[5]); glVertex3fv(p[1]);
156 // front: 3267
157 glNormal3fv(TMath::Cross(e[4], e[5], n));
158 glVertex3fv(p[3]); glVertex3fv(p[2]);
159 glVertex3fv(p[6]); glVertex3fv(p[7]);
160 // left: 0374
161 glNormal3fv(TMath::Cross(e[1], e[2], n));
162 glVertex3fv(p[0]); glVertex3fv(p[3]);
163 glVertex3fv(p[7]); glVertex3fv(p[4]);
164 // right: 1562
165 glNormal3fv(TMath::Cross(e[5], e[3], n));
166 glVertex3fv(p[1]); glVertex3fv(p[5]);
167 glVertex3fv(p[6]); glVertex3fv(p[2]);
168
169 glEnd();
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Render with OpenGL.
174
176{
177 if (rnrCtx.IsDrawPassOutlineLine())
178 {
180 return;
181 }
182
183 if (fM->fHighlightFrame && rnrCtx.Highlight())
184 {
185 if (fM->fDrawFrame)
186 {
190 }
192 }
193 else
194 {
196 }
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Render with OpenGL, create display-list.
201
224
225
226/** \class TEveBoxProjectedGL
227\ingroup TEve
228OpenGL renderer class for TEveBoxProjected.
229*/
230
231
232////////////////////////////////////////////////////////////////////////////////
233/// Constructor.
234
236 TGLObject(), fM(nullptr)
237{
238 // fDLCache = kFALSE; // Disable display list.
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Set model object.
243
245{
247 return kTRUE;
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Set bounding box.
252
257
258////////////////////////////////////////////////////////////////////////////////
259/// Render points with given GL mode.
260/// This is used for polygon and outline drawing.
261
263{
264 Int_t B = fM->fBreakIdx;
265 Int_t N = fM->fPoints.size();
266 if (B != 0)
267 {
268 glBegin(mode);
269 for (Int_t i = 0; i < B; ++i)
270 {
272 }
273 glEnd();
274 }
275 glBegin(mode);
276 for (Int_t i = B; i < N; ++i)
277 {
279 }
280 glEnd();
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Render with OpenGL.
285
287{
288 if (rnrCtx.IsDrawPassOutlineLine())
289 return;
290
291 glPushMatrix();
292 glTranslatef(0.0f, 0.0f, fM->fDepth);
293
294 if (fM->fHighlightFrame && rnrCtx.Highlight())
295 {
296 if (fM->fDrawFrame)
297 {
301 }
302 RenderPoints(GL_LINE_LOOP);
303 }
304 else
305 {
307 }
308
310 {
311 glColor3f(1,0,0);
312 Int_t N = fM->fDebugPoints.size();
313 glPointSize(4);
314 glBegin(GL_POINTS);
315 for (Int_t i = 0; i < N; ++i)
316 {
318 }
319 glEnd();
320 }
321
322 glPopMatrix();
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Render with OpenGL, create display-list.
327
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char mode
TEveBox * fM
Definition TEveBoxGL.h:34
void RenderBoxAutoNorm(const Float_t p[8][3]) const
Render box, calculate normals on the fly from first three points.
void RenderOutline(const Float_t p[8][3]) const
Render box with without normals.
Definition TEveBoxGL.cxx:77
TEveBoxGL()
Constructor.
Definition TEveBoxGL.cxx:29
void RenderBoxStdNorm(const Float_t p[8][3]) const
Render box with standard axis-aligned normals.
Definition TEveBoxGL.cxx:97
void DirectDraw(TGLRnrCtx &rnrCtx) const override
Render with OpenGL, create display-list.
void Draw(TGLRnrCtx &rnrCtx) const override
Render with OpenGL.
Bool_t SetModel(TObject *obj, const Option_t *opt=nullptr) override
Set model object.
Definition TEveBoxGL.cxx:38
void SetBBox() override
Set bounding box.
Definition TEveBoxGL.cxx:47
void SetBBox() override
Set bounding box.
void DirectDraw(TGLRnrCtx &rnrCtx) const override
Render with OpenGL, create display-list.
TEveBoxProjectedGL()
Constructor.
void Draw(TGLRnrCtx &rnrCtx) const override
Render with OpenGL.
TEveBoxProjected * fM
Definition TEveBoxGL.h:71
Bool_t SetModel(TObject *obj, const Option_t *opt=nullptr) override
Set model object.
void RenderPoints(Int_t mode) const
Render points with given GL mode.
Projection of TEveBox.
Definition TEveBox.h:58
static Bool_t fgDebugCornerPoints
Definition TEveBox.h:72
Int_t fBreakIdx
Definition TEveBox.h:67
vVector2_t fDebugPoints
Definition TEveBox.h:68
vVector2_t fPoints
Definition TEveBox.h:66
3D box with arbitrary vertices (cuboid).
Definition TEveBox.h:22
Float_t fVertices[8][3]
Definition TEveBox.h:30
Color_t fFillColor
Definition TEveShape.h:38
Bool_t fDrawFrame
Definition TEveShape.h:42
Bool_t fHighlightFrame
Definition TEveShape.h:43
Float_t fLineWidth
Definition TEveShape.h:40
Color_t fLineColor
Definition TEveShape.h:39
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw the GL drawable, using draw flags.
TObject * fExternalObj
first replica
Base-class for direct OpenGL renderers.
Definition TGLObject.h:22
Bool_t fMultiColor
Definition TGLObject.h:28
void SetAxisAlignedBBox(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax)
Set axis-aligned bounding-box.
Definition TGLObject.cxx:85
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition TGLUtil.cxx:1688
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition TGLUtil.cxx:1934
Mother of all ROOT objects.
Definition TObject.h:41
const Int_t n
Definition legend1.C:16
T * Cross(const T v1[3], const T v2[3], T out[3])
Calculates the Cross Product of two vectors: out = [v1 x v2].
Definition TMath.h:1284