Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveTriangleSetGL.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 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 "TEveTriangleSetGL.h"
13#include "TEveTriangleSet.h"
14#include "TVector3.h"
15
16#include "TGLIncludes.h"
17
18/** \class TEveTriangleSetGL
19\ingroup TEve
20GL-renderer for TEveTriangleSet class.
21
22See also: TGLObject, TGLLogicalShape.
23*/
24
26
27////////////////////////////////////////////////////////////////////////////////
28/// Constructor.
29
31{
32 // fDLCache = false; // Disable display list.
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// Destructor.
38
40{
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// Set model object.
45
47{
48 fM = SetModelDynCast<TEveTriangleSet>(obj);
49 return kTRUE;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Set bounding-box from the model.
54
56{
57 // !! This ok if master sub-classed from TAttBBox
59}
60
61
62////////////////////////////////////////////////////////////////////////////////
63/// Low-level GL rendering.
64
66{
67 TEveTriangleSet& refTS = *fM;
68 Bool_t isScaled = refTS.RefMainTrans().IsScale();
69
70 GLint ex_shade_model;
71 glGetIntegerv(GL_SHADE_MODEL, &ex_shade_model);
72 glShadeModel(GL_FLAT);
73
74 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
75
76 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
77 glEnable(GL_COLOR_MATERIAL);
78 glDisable(GL_CULL_FACE);
79 if (isScaled) glEnable(GL_NORMALIZE);
80 glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
81 glVertexPointer(3, GL_FLOAT, 0, refTS.fVerts);
82 glEnableClientState(GL_VERTEX_ARRAY);
83
84 Int_t* tng = refTS.fTrings;
85 Float_t* nrm = refTS.fTringNorms;
86 UChar_t* col = refTS.fTringCols;
87
88 TVector3 e1, e2, n;
89
90 glBegin(GL_TRIANGLES);
91 for(Int_t t=0; t<refTS.fNTrings; ++t) {
92 if (nrm) {
93 glNormal3fv(nrm); nrm += 3;
94 } else {
95 Float_t* v0 = refTS.Vertex(tng[0]);
96 Float_t* v1 = refTS.Vertex(tng[1]);
97 Float_t* v2 = refTS.Vertex(tng[2]);
98 e1.SetXYZ(v1[0]-v0[0], v1[1]-v0[1], v1[2]-v0[2]);
99 e2.SetXYZ(v2[0]-v0[0], v2[1]-v0[1], v2[2]-v0[2]);
100 n = e1.Cross(e2);
101 if (!isScaled) n.SetMag(1);
102 glNormal3d(n.x(), n.y(), n.z());
103 }
104 if (col) {
105 TGLUtil::Color3ubv(col); col += 3;
106 }
107 glArrayElement(tng[0]);
108 glArrayElement(tng[1]);
109 glArrayElement(tng[2]);
110 tng += 3;
111 }
112 glEnd();
113
114 glPopClientAttrib();
115 glPopAttrib();
116 glShadeModel(ex_shade_model);
117}
#define GL_TRIANGLES
Definition GL_glu.h:287
unsigned char UChar_t
Definition RtypesCore.h:38
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
Bool_t IsScale(Double_t low=0.9, Double_t high=1.1) const
Test if the transformation is a scale.
GL-renderer for TEveTriangleSet class.
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Low-level GL rendering.
TEveTriangleSetGL()
Constructor.
TEveTriangleSet * fM
virtual ~TEveTriangleSetGL()
Destructor.
virtual Bool_t SetModel(TObject *obj, const Option_t *opt=nullptr)
Set model object.
virtual void SetBBox()
Set bounding-box from the model.
Made from a list of vertices and a list of triangles (triplets of vertex indices).
Float_t * fTringNorms
Float_t * Vertex(Int_t i)
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
static void Color3ubv(const UChar_t *rgb)
Wrapper for glColor3ubv.
Definition TGLUtil.cxx:1771
Mother of all ROOT objects.
Definition TObject.h:41
void SetXYZ(Double_t x, Double_t y, Double_t z)
Definition TVector3.h:227
void SetMag(Double_t)
Definition TVector3.h:376
TVector3 Cross(const TVector3 &) const
Definition TVector3.h:335
const Int_t n
Definition legend1.C:16