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
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor.
28
30{
31 // fDLCache = false; // Disable display list.
33}
34
35////////////////////////////////////////////////////////////////////////////////
36/// Destructor.
37
41
42////////////////////////////////////////////////////////////////////////////////
43/// Set model object.
44
50
51////////////////////////////////////////////////////////////////////////////////
52/// Set bounding-box from the model.
53
55{
56 // !! This ok if master sub-classed from TAttBBox
58}
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// Low-level GL rendering.
63
65{
66 TEveTriangleSet& refTS = *fM;
67 Bool_t isScaled = refTS.RefMainTrans().IsScale();
68
69 GLint ex_shade_model;
70 glGetIntegerv(GL_SHADE_MODEL, &ex_shade_model);
71 glShadeModel(GL_FLAT);
72
73 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
74
75 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
76 glEnable(GL_COLOR_MATERIAL);
77 glDisable(GL_CULL_FACE);
78 if (isScaled) glEnable(GL_NORMALIZE);
79 glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
80 glVertexPointer(3, GL_FLOAT, 0, refTS.fVerts);
81 glEnableClientState(GL_VERTEX_ARRAY);
82
83 Int_t* tng = refTS.fTrings;
84 Float_t* nrm = refTS.fTringNorms;
85 UChar_t* col = refTS.fTringCols;
86
87 TVector3 e1, e2, n;
88
89 glBegin(GL_TRIANGLES);
90 for(Int_t t=0; t<refTS.fNTrings; ++t) {
91 if (nrm) {
92 glNormal3fv(nrm); nrm += 3;
93 } else {
94 Float_t* v0 = refTS.Vertex(tng[0]);
95 Float_t* v1 = refTS.Vertex(tng[1]);
96 Float_t* v2 = refTS.Vertex(tng[2]);
97 e1.SetXYZ(v1[0]-v0[0], v1[1]-v0[1], v1[2]-v0[2]);
98 e2.SetXYZ(v2[0]-v0[0], v2[1]-v0[1], v2[2]-v0[2]);
99 n = e1.Cross(e2);
100 if (!isScaled) n.SetMag(1);
101 glNormal3d(n.x(), n.y(), n.z());
102 }
103 if (col) {
104 TGLUtil::Color3ubv(col); col += 3;
105 }
106 glArrayElement(tng[0]);
107 glArrayElement(tng[1]);
108 glArrayElement(tng[2]);
109 tng += 3;
110 }
111 glEnd();
112
113 glPopClientAttrib();
114 glPopAttrib();
115 glShadeModel(ex_shade_model);
116}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
Definition RtypesCore.h:52
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
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
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.
void SetBBox() override
Set bounding-box from the model.
void DirectDraw(TGLRnrCtx &rnrCtx) const override
Low-level GL rendering.
TEveTriangleSetGL()
Constructor.
TEveTriangleSet * fM
~TEveTriangleSetGL() override
Destructor.
Bool_t SetModel(TObject *obj, const Option_t *opt=nullptr) override
Set model object.
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
! Also plays the role of ID.
Bool_t fMultiColor
Definition TGLObject.h:28
TT * SetModelDynCast(TObject *obj)
Definition TGLObject.h:37
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 Color3ubv(const UChar_t *rgb)
Wrapper for glColor3ubv.
Definition TGLUtil.cxx:1762
Mother of all ROOT objects.
Definition TObject.h:42
void SetXYZ(Double_t x, Double_t y, Double_t z)
Definition TVector3.h:230
TVector3 Cross(const TVector3 &) const
Definition TVector3.h:338
const Int_t n
Definition legend1.C:16