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
26
27////////////////////////////////////////////////////////////////////////////////
28/// Constructor.
29
31 TGLObject(), fM(nullptr)
32{
33 // fDLCache = kFALSE; // Disable display list.
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// Set model object.
38
40{
41 fM = SetModelDynCast<TEveBox>(obj);
42 return kTRUE;
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// Set bounding box.
47
49{
50 // !! This ok if master sub-classed from TAttBBox
51 SetAxisAlignedBBox(((TEveBox*)fExternalObj)->AssertBBox());
52}
53
54namespace
55{
56 void subtract_and_normalize(const Float_t a[3], const Float_t b[3],
57 Float_t o[3])
58 {
59 // Calculate a - b and normalize the result.
60 o[0] = a[0] - b[0];
61 o[1] = a[1] - b[1];
62 o[2] = a[2] - b[2];
63 Float_t d = sqrtf(o[0]*o[0] + o[1]*o[1] + o[2]*o[2]);
64 if (d != 0)
65 {
66 d = 1.0f / d;
67 o[0] *= d;
68 o[1] *= d;
69 o[2] *= d;
70 }
71 }
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Render box with without normals.
76/// To be used with lightning off, for outline.
77
78void TEveBoxGL::RenderOutline(const Float_t p[8][3]) const
79{
80 glBegin(GL_LINE_STRIP);
81 glVertex3fv(p[0]); glVertex3fv(p[1]);
82 glVertex3fv(p[5]); glVertex3fv(p[6]);
83 glVertex3fv(p[2]); glVertex3fv(p[3]);
84 glVertex3fv(p[7]); glVertex3fv(p[4]);
85 glVertex3fv(p[0]); glVertex3fv(p[3]);
86 glEnd();
87
88 glBegin(GL_LINES);
89 glVertex3fv(p[1]); glVertex3fv(p[2]);
90 glVertex3fv(p[4]); glVertex3fv(p[5]);
91 glVertex3fv(p[6]); glVertex3fv(p[7]);
92 glEnd();
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Render box with standard axis-aligned normals.
97
98void TEveBoxGL::RenderBoxStdNorm(const Float_t p[8][3]) const
99{
100 glBegin(GL_QUADS);
101
102 // bottom: 0123
103 glNormal3f(0, 0, -1);
104 glVertex3fv(p[0]); glVertex3fv(p[1]);
105 glVertex3fv(p[2]); glVertex3fv(p[3]);
106 // top: 7654
107 glNormal3f(0, 0, 1);
108 glVertex3fv(p[7]); glVertex3fv(p[6]);
109 glVertex3fv(p[5]); glVertex3fv(p[4]);
110 // back: 0451
111 glNormal3f(0, 1, 0);
112 glVertex3fv(p[0]); glVertex3fv(p[4]);
113 glVertex3fv(p[5]); glVertex3fv(p[1]);
114 // front: 3267
115 glNormal3f(0, -1, 0);
116 glVertex3fv(p[3]); glVertex3fv(p[2]);
117 glVertex3fv(p[6]); glVertex3fv(p[7]);
118 // left: 0374
119 glNormal3f(-1, 0, 0);
120 glVertex3fv(p[0]); glVertex3fv(p[3]);
121 glVertex3fv(p[7]); glVertex3fv(p[4]);
122 // right: 1562
123 glNormal3f(1, 0, 0);
124 glVertex3fv(p[1]); glVertex3fv(p[5]);
125 glVertex3fv(p[6]); glVertex3fv(p[2]);
126
127 glEnd();
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Render box, calculate normals on the fly from first three points.
132
134{
135 Float_t e[6][3], n[3];
136 subtract_and_normalize(p[1], p[0], e[0]);
137 subtract_and_normalize(p[3], p[0], e[1]);
138 subtract_and_normalize(p[4], p[0], e[2]);
139 subtract_and_normalize(p[5], p[6], e[3]);
140 subtract_and_normalize(p[7], p[6], e[4]);
141 subtract_and_normalize(p[2], p[6], e[5]);
142
143 glBegin(GL_QUADS);
144
145 // bottom: 0123
146 glNormal3fv(TMath::Cross(e[0], e[1], n));
147 glVertex3fv(p[0]); glVertex3fv(p[1]);
148 glVertex3fv(p[2]); glVertex3fv(p[3]);
149 // top: 7654
150 glNormal3fv(TMath::Cross(e[3], e[4], n));
151 glVertex3fv(p[7]); glVertex3fv(p[6]);
152 glVertex3fv(p[5]); glVertex3fv(p[4]);
153 // back: 0451
154 glNormal3fv(TMath::Cross(e[2], e[0], n));
155 glVertex3fv(p[0]); glVertex3fv(p[4]);
156 glVertex3fv(p[5]); glVertex3fv(p[1]);
157 // front: 3267
158 glNormal3fv(TMath::Cross(e[4], e[5], n));
159 glVertex3fv(p[3]); glVertex3fv(p[2]);
160 glVertex3fv(p[6]); glVertex3fv(p[7]);
161 // left: 0374
162 glNormal3fv(TMath::Cross(e[1], e[2], n));
163 glVertex3fv(p[0]); glVertex3fv(p[3]);
164 glVertex3fv(p[7]); glVertex3fv(p[4]);
165 // right: 1562
166 glNormal3fv(TMath::Cross(e[5], e[3], n));
167 glVertex3fv(p[1]); glVertex3fv(p[5]);
168 glVertex3fv(p[6]); glVertex3fv(p[2]);
169
170 glEnd();
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Render with OpenGL.
175
176void TEveBoxGL::Draw(TGLRnrCtx& rnrCtx) const
177{
178 if (rnrCtx.IsDrawPassOutlineLine())
179 {
181 return;
182 }
183
184 if (fM->fHighlightFrame && rnrCtx.Highlight())
185 {
186 if (fM->fDrawFrame)
187 {
188 glEnable(GL_BLEND);
191 }
193 }
194 else
195 {
196 TGLObject::Draw(rnrCtx);
197 }
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Render with OpenGL, create display-list.
202
204{
206
207 glPushAttrib(GL_ENABLE_BIT);
208
209 glEnable(GL_POLYGON_OFFSET_FILL);
210 glPolygonOffset(1.0f, 1.0f);
212 glDisable(GL_POLYGON_OFFSET_FILL);
213
214 // Frame
215 if (fM->fDrawFrame)
216 {
217 glEnable(GL_BLEND);
221 }
222
223 glPopAttrib();
224}
225
226
227/** \class TEveBoxProjectedGL
228\ingroup TEve
229OpenGL renderer class for TEveBoxProjected.
230*/
231
233
234////////////////////////////////////////////////////////////////////////////////
235/// Constructor.
236
238 TGLObject(), fM(nullptr)
239{
240 // fDLCache = kFALSE; // Disable display list.
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Set model object.
245
247{
248 fM = SetModelDynCast<TEveBoxProjected>(obj);
249 return kTRUE;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Set bounding box.
254
256{
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Render points with given GL mode.
262/// This is used for polygon and outline drawing.
263
265{
266 Int_t B = fM->fBreakIdx;
267 Int_t N = fM->fPoints.size();
268 if (B != 0)
269 {
270 glBegin(mode);
271 for (Int_t i = 0; i < B; ++i)
272 {
273 glVertex2fv(fM->fPoints[i]);
274 }
275 glEnd();
276 }
277 glBegin(mode);
278 for (Int_t i = B; i < N; ++i)
279 {
280 glVertex2fv(fM->fPoints[i]);
281 }
282 glEnd();
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Render with OpenGL.
287
289{
290 if (rnrCtx.IsDrawPassOutlineLine())
291 return;
292
293 glPushMatrix();
294 glTranslatef(0.0f, 0.0f, fM->fDepth);
295
296 if (fM->fHighlightFrame && rnrCtx.Highlight())
297 {
298 if (fM->fDrawFrame)
299 {
300 glEnable(GL_BLEND);
303 }
305 }
306 else
307 {
308 TGLObject::Draw(rnrCtx);
309 }
310
312 {
313 glColor3f(1,0,0);
314 Int_t N = fM->fDebugPoints.size();
315 glPointSize(4);
316 glBegin(GL_POINTS);
317 for (Int_t i = 0; i < N; ++i)
318 {
319 glVertex2fv(fM->fDebugPoints[i]);
320 }
321 glEnd();
322 }
323
324 glPopMatrix();
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Render with OpenGL, create display-list.
329
331{
333
334 glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
335
336 glDisable(GL_LIGHTING);
337
338 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
339 glEnable(GL_COLOR_MATERIAL);
340 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
341 glDisable(GL_CULL_FACE);
342
343 glEnable(GL_POLYGON_OFFSET_FILL);
344 glPolygonOffset(1.0f, 1.0f);
346 glDisable(GL_POLYGON_OFFSET_FILL);
347
348 // Frame
349 if (fM->fDrawFrame)
350 {
351 glEnable(GL_BLEND);
355 }
356
357 glPopAttrib();
358}
#define GL_QUADS
Definition GL_glu.h:290
#define GL_LINE_STRIP
Definition GL_glu.h:286
#define GL_LINES
Definition GL_glu.h:284
#define GL_POINTS
Definition GL_glu.h:283
#define GL_POLYGON
Definition GL_glu.h:292
#define GL_LINE_LOOP
Definition GL_glu.h:285
#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
Definition RtypesCore.h:57
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char mode
OpenGL renderer class for TEveBox.
Definition TEveBoxGL.h:28
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:78
TEveBoxGL()
Constructor.
Definition TEveBoxGL.cxx:30
void RenderBoxStdNorm(const Float_t p[8][3]) const
Render box with standard axis-aligned normals.
Definition TEveBoxGL.cxx:98
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:39
void SetBBox() override
Set bounding box.
Definition TEveBoxGL.cxx:48
OpenGL renderer class for TEveBoxProjected.
Definition TEveBoxGL.h:65
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:86
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
Bool_t IsDrawPassOutlineLine() const
Definition TGLRnrCtx.h:207
Bool_t Highlight() const
Definition TGLRnrCtx.h:218
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition TGLUtil.cxx:1697
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition TGLUtil.cxx:1943
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:1277