Logo ROOT   6.16/01
Reference Guide
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
27Implements a native ROOT-GL sphere that can be rendered at
28different levels of detail.
29*/
30
32
33////////////////////////////////////////////////////////////////////////////////
34/// Default ctor
35
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
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
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
92void 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}
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
long Long_t
Definition: RtypesCore.h:50
short Short_t
Definition: RtypesCore.h:35
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:363
R__EXTERN Int_t gDebug
Definition: Rtypes.h:90
void Info(const char *location, const char *msgfmt,...)
Sphere description class - see TBuffer3DTypes for producer classes Supports hollow and cut spheres.
Definition: TBuffer3D.h:129
Double_t fRadiusOuter
Definition: TBuffer3D.h:144
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
Int_t fDLSize
display-list id base
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:41
GLUquadric * GetGluQuadric()
Initialize fQuadric.
Definition: TGLRnrCtx.cxx:405
Short_t ShapeLOD() const
Definition: TGLRnrCtx.h:177
Implements a native ROOT-GL sphere that can be rendered at different levels of detail.
Definition: TGLSphere.h:22
Double_t fRadius
Definition: TGLSphere.h:24
TGLSphere(const TBuffer3DSphere &buffer)
Default ctor.
Definition: TGLSphere.cxx:36
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Debug tracing.
Definition: TGLSphere.cxx:92
virtual UInt_t DLOffset(Short_t lod) const
Return display-list offset for given LOD.
Definition: TGLSphere.cxx:56
virtual Short_t QuantizeShapeLOD(Short_t shapeLOD, Short_t combiLOD) const
Factor in scene/viewer LOD and quantize.
Definition: TGLSphere.cxx:68
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:146