TEveTriangleSetGL.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveTriangleSetGL.cxx 36384 2010-10-20 14:26:41Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveTriangleSetGL.h"
00013 #include "TEveTriangleSet.h"
00014 #include "TVector3.h"
00015 
00016 #include "TGLIncludes.h"
00017 
00018 //==============================================================================
00019 // TEveTriangleSetGL
00020 //==============================================================================
00021 
00022 //______________________________________________________________________________
00023 //
00024 // GL-renderer for TEveTriangleSet class.
00025 //
00026 // See also: TGLObject, TGLLogicalShape.
00027 
00028 ClassImp(TEveTriangleSetGL);
00029 
00030 //______________________________________________________________________________
00031 TEveTriangleSetGL::TEveTriangleSetGL() : TGLObject(), fM(0)
00032 {
00033    // Constructor.
00034 
00035    // fDLCache = false; // Disable display list.
00036    fMultiColor = kTRUE;
00037 }
00038 
00039 //______________________________________________________________________________
00040 TEveTriangleSetGL::~TEveTriangleSetGL()
00041 {
00042    // Destructor.
00043 }
00044 
00045 /******************************************************************************/
00046 
00047 //______________________________________________________________________________
00048 Bool_t TEveTriangleSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
00049 {
00050    // Set model object.
00051 
00052    fM = SetModelDynCast<TEveTriangleSet>(obj);
00053    return kTRUE;
00054 }
00055 
00056 //______________________________________________________________________________
00057 void TEveTriangleSetGL::SetBBox()
00058 {
00059    // Set bounding-box from the model.
00060 
00061    // !! This ok if master sub-classed from TAttBBox
00062    SetAxisAlignedBBox(((TEveTriangleSet*)fExternalObj)->AssertBBox());
00063 }
00064 
00065 /******************************************************************************/
00066 
00067 //______________________________________________________________________________
00068 void TEveTriangleSetGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const
00069 {
00070    // Low-level GL rendering.
00071 
00072    TEveTriangleSet& refTS = *fM;
00073    Bool_t isScaled = refTS.RefMainTrans().IsScale();
00074 
00075    GLint ex_shade_model;
00076    glGetIntegerv(GL_SHADE_MODEL, &ex_shade_model);
00077    glShadeModel(GL_FLAT);
00078 
00079    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
00080 
00081    glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
00082    glEnable(GL_COLOR_MATERIAL);
00083    glDisable(GL_CULL_FACE);
00084    if (isScaled) glEnable(GL_NORMALIZE);
00085    glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
00086    glVertexPointer(3, GL_FLOAT, 0, refTS.fVerts);
00087    glEnableClientState(GL_VERTEX_ARRAY);
00088 
00089    Int_t*   tng = refTS.fTrings;
00090    Float_t* nrm = refTS.fTringNorms;
00091    UChar_t* col = refTS.fTringCols;
00092 
00093    TVector3 e1, e2, n;
00094 
00095    glBegin(GL_TRIANGLES);
00096    for(Int_t t=0; t<refTS.fNTrings; ++t) {
00097       if (nrm) {
00098          glNormal3fv(nrm); nrm += 3;
00099       } else {
00100          Float_t* v0 = refTS.Vertex(tng[0]);
00101          Float_t* v1 = refTS.Vertex(tng[1]);
00102          Float_t* v2 = refTS.Vertex(tng[2]);
00103          e1.SetXYZ(v1[0]-v0[0], v1[1]-v0[1], v1[2]-v0[2]);
00104          e2.SetXYZ(v2[0]-v0[0], v2[1]-v0[1], v2[2]-v0[2]);
00105          n = e1.Cross(e2);
00106          if (!isScaled) n.SetMag(1);
00107          glNormal3d(n.x(), n.y(), n.z());
00108       }
00109       if (col) {
00110          TGLUtil::Color3ubv(col);  col += 3;
00111       }
00112       glArrayElement(tng[0]);
00113       glArrayElement(tng[1]);
00114       glArrayElement(tng[2]);
00115       tng += 3;
00116    }
00117    glEnd();
00118 
00119    glPopClientAttrib();
00120    glPopAttrib();
00121    glShadeModel(ex_shade_model);
00122 }

Generated on Tue Jul 5 14:16:15 2011 for ROOT_528-00b_version by  doxygen 1.5.1