Logo ROOT   6.14/05
Reference Guide
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
20 GL-renderer for TEveTriangleSet class.
21 
22 See 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 
65 void TEveTriangleSetGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const
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 }
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
Float_t * fTringNorms
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
TEveTriangleSet * fM
GL-renderer for TEveTriangleSet class.
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
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t y() const
Definition: TVector3.h:214
virtual void SetBBox()
Set bounding-box from the model.
void SetXYZ(Double_t x, Double_t y, Double_t z)
Definition: TVector3.h:227
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:21
TObject * fExternalObj
first replica
virtual Bool_t SetModel(TObject *obj, const Option_t *opt=0)
Set model object.
Bool_t IsScale(Double_t low=0.9, Double_t high=1.1) const
Test if the transformation is a scale.
Definition: TEveTrans.cxx:1074
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition: TVector3.h:22
TVector3 Cross(const TVector3 &) const
Definition: TVector3.h:335
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Low-level GL rendering.
TEveTriangleSetGL()
Constructor.
Double_t z() const
Definition: TVector3.h:215
#define ClassImp(name)
Definition: Rtypes.h:359
Made from a list of vertices and a list of triangles (triplets of vertex indices).
virtual ~TEveTriangleSetGL()
Destructor.
Bool_t fMultiColor
Definition: TGLObject.h:28
Mother of all ROOT objects.
Definition: TObject.h:37
Float_t * Vertex(Int_t i)
Double_t x() const
Definition: TVector3.h:213
void SetMag(Double_t)
Definition: TVector3.h:376
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
unsigned char UChar_t
Definition: RtypesCore.h:34
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
static void Color3ubv(const UChar_t *rgb)
Wrapper for glColor3ubv.
Definition: TGLUtil.cxx:1732
UChar_t * fTringCols