Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLSphere.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov 03/08/2004
3 // NOTE: This code moved from obsoleted TGLSceneObject.h / .cxx - see these
4 // attic files for previous CVS history
5 
6 /*************************************************************************
7  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
8  * All rights reserved. *
9  * *
10  * For the licensing terms see $ROOTSYS/LICENSE. *
11  * For the list of contributors see $ROOTSYS/README/CREDITS. *
12  *************************************************************************/
13 #include "TGLSphere.h"
14 #include "TGLRnrCtx.h"
15 #include "TGLQuadric.h"
16 #include "TGLIncludes.h"
17 
18 #include "TBuffer3D.h"
19 #include "TBuffer3DTypes.h"
20 
21 // For debug tracing
22 #include "TClass.h"
23 #include "TError.h"
24 
25 /** \class TGLSphere
26 \ingroup opengl
27 Implements a native ROOT-GL sphere that can be rendered at
28 different levels of detail.
29 */
30 
31 ClassImp(TGLSphere);
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Default ctor
35 
36 TGLSphere::TGLSphere(const TBuffer3DSphere &buffer) :
37  TGLLogicalShape(buffer)
38 {
39  fDLSize = 14;
40 
41  fRadius = buffer.fRadiusOuter;
42 
43  // TODO:
44  // Support hollow & cut spheres
45  // buffer.fRadiusInner;
46  // buffer.fThetaMin;
47  // buffer.fThetaMax;
48  // buffer.fPhiMin;
49  // buffer.fPhiMax;
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Return display-list offset for given LOD.
54 /// Calculation based on what is done in virtual QuantizeShapeLOD below.
55 
56 UInt_t TGLSphere::DLOffset(Short_t lod) const
57 {
58  UInt_t off = 0;
59  if (lod >= 100) off = 0;
60  else if (lod < 10) off = lod / 2;
61  else off = lod / 10 + 4;
62  return off;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Factor in scene/viewer LOD and quantize.
67 
68 Short_t TGLSphere::QuantizeShapeLOD(Short_t shapeLOD, Short_t combiLOD) const
69 {
70  Int_t lod = ((Int_t)shapeLOD * (Int_t)combiLOD) / 100;
71 
72  if (lod >= 100)
73  {
74  lod = 100;
75  }
76  else if (lod > 10)
77  { // Round LOD above 10 to nearest 10
78  Double_t quant = 0.1 * ((static_cast<Double_t>(lod)) + 0.5);
79  lod = 10 * static_cast<Int_t>(quant);
80  }
81  else
82  { // Round LOD below 10 to nearest 2
83  Double_t quant = 0.5 * ((static_cast<Double_t>(lod)) + 0.5);
84  lod = 2 * static_cast<Int_t>(quant);
85  }
86  return static_cast<Short_t>(lod);
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Debug tracing
91 
92 void TGLSphere::DirectDraw(TGLRnrCtx & rnrCtx) const
93 {
94  if (gDebug > 4) {
95  Info("TGLSphere::DirectDraw", "this %ld (class %s) LOD %d", (Long_t)this, IsA()->GetName(), rnrCtx.ShapeLOD());
96  }
97 
98  // 4 stack/slice min for gluSphere to work
99  UInt_t divisions = rnrCtx.ShapeLOD();
100  if (divisions < 4) {
101  divisions = 4;
102  }
103  gluSphere(rnrCtx.GetGluQuadric(), fRadius, divisions, divisions);
104 }