forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveTriangleSetGL.cxx
117 lines (93 loc) · 3.32 KB
/
TEveTriangleSetGL.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveTriangleSetGL.h"
#include "TEveTriangleSet.h"
#include "TVector3.h"
#include "TGLIncludes.h"
/** \class TEveTriangleSetGL
\ingroup TEve
GL-renderer for TEveTriangleSet class.
See also: TGLObject, TGLLogicalShape.
*/
ClassImp(TEveTriangleSetGL);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveTriangleSetGL::TEveTriangleSetGL() : TGLObject(), fM(0)
{
// fDLCache = false; // Disable display list.
fMultiColor = kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveTriangleSetGL::~TEveTriangleSetGL()
{
}
////////////////////////////////////////////////////////////////////////////////
/// Set model object.
Bool_t TEveTriangleSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
{
fM = SetModelDynCast<TEveTriangleSet>(obj);
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Set bounding-box from the model.
void TEveTriangleSetGL::SetBBox()
{
// !! This ok if master sub-classed from TAttBBox
SetAxisAlignedBBox(((TEveTriangleSet*)fExternalObj)->AssertBBox());
}
////////////////////////////////////////////////////////////////////////////////
/// Low-level GL rendering.
void TEveTriangleSetGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const
{
TEveTriangleSet& refTS = *fM;
Bool_t isScaled = refTS.RefMainTrans().IsScale();
GLint ex_shade_model;
glGetIntegerv(GL_SHADE_MODEL, &ex_shade_model);
glShadeModel(GL_FLAT);
glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE);
if (isScaled) glEnable(GL_NORMALIZE);
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
glVertexPointer(3, GL_FLOAT, 0, refTS.fVerts);
glEnableClientState(GL_VERTEX_ARRAY);
Int_t* tng = refTS.fTrings;
Float_t* nrm = refTS.fTringNorms;
UChar_t* col = refTS.fTringCols;
TVector3 e1, e2, n;
glBegin(GL_TRIANGLES);
for(Int_t t=0; t<refTS.fNTrings; ++t) {
if (nrm) {
glNormal3fv(nrm); nrm += 3;
} else {
Float_t* v0 = refTS.Vertex(tng[0]);
Float_t* v1 = refTS.Vertex(tng[1]);
Float_t* v2 = refTS.Vertex(tng[2]);
e1.SetXYZ(v1[0]-v0[0], v1[1]-v0[1], v1[2]-v0[2]);
e2.SetXYZ(v2[0]-v0[0], v2[1]-v0[1], v2[2]-v0[2]);
n = e1.Cross(e2);
if (!isScaled) n.SetMag(1);
glNormal3d(n.x(), n.y(), n.z());
}
if (col) {
TGLUtil::Color3ubv(col); col += 3;
}
glArrayElement(tng[0]);
glArrayElement(tng[1]);
glArrayElement(tng[2]);
tng += 3;
}
glEnd();
glPopClientAttrib();
glPopAttrib();
glShadeModel(ex_shade_model);
}