00001 // @(#)root/gl:$Id: TGLSphere.cxx 34245 2010-06-30 13:36:29Z brun $ 00002 // Author: Timur Pocheptsov 03/08/2004 00003 // NOTE: This code moved from obsoleted TGLSceneObject.h / .cxx - see these 00004 // attic files for previous CVS history 00005 00006 /************************************************************************* 00007 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * 00008 * All rights reserved. * 00009 * * 00010 * For the licensing terms see $ROOTSYS/LICENSE. * 00011 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00012 *************************************************************************/ 00013 #include "TGLSphere.h" 00014 #include "TGLRnrCtx.h" 00015 #include "TGLQuadric.h" 00016 #include "TGLIncludes.h" 00017 00018 #include "TBuffer3D.h" 00019 #include "TBuffer3DTypes.h" 00020 00021 // For debug tracing 00022 #include "TClass.h" 00023 #include "TError.h" 00024 00025 //______________________________________________________________________________ 00026 // 00027 // Implements a native ROOT-GL sphere that can be rendered at 00028 // different levels of detail. 00029 00030 ClassImp(TGLSphere); 00031 00032 //______________________________________________________________________________ 00033 TGLSphere::TGLSphere(const TBuffer3DSphere &buffer) : 00034 TGLLogicalShape(buffer) 00035 { 00036 // Default ctor 00037 00038 fDLSize = 14; 00039 00040 fRadius = buffer.fRadiusOuter; 00041 00042 // TODO: 00043 // Support hollow & cut spheres 00044 // buffer.fRadiusInner; 00045 // buffer.fThetaMin; 00046 // buffer.fThetaMax; 00047 // buffer.fPhiMin; 00048 // buffer.fPhiMax; 00049 } 00050 00051 //______________________________________________________________________________ 00052 UInt_t TGLSphere::DLOffset(Short_t lod) const 00053 { 00054 // Return display-list offset for given LOD. 00055 // Calculation based on what is done in virtual QuantizeShapeLOD below. 00056 00057 UInt_t off = 0; 00058 if (lod >= 100) off = 0; 00059 else if (lod < 10) off = lod / 2; 00060 else off = lod / 10 + 4; 00061 return off; 00062 } 00063 00064 //______________________________________________________________________________ 00065 Short_t TGLSphere::QuantizeShapeLOD(Short_t shapeLOD, Short_t combiLOD) const 00066 { 00067 // Factor in scene/viewer LOD and quantize. 00068 00069 Int_t lod = ((Int_t)shapeLOD * (Int_t)combiLOD) / 100; 00070 00071 if (lod >= 100) 00072 { 00073 lod = 100; 00074 } 00075 else if (lod > 10) 00076 { // Round LOD above 10 to nearest 10 00077 Double_t quant = 0.1 * ((static_cast<Double_t>(lod)) + 0.5); 00078 lod = 10 * static_cast<Int_t>(quant); 00079 } 00080 else 00081 { // Round LOD below 10 to nearest 2 00082 Double_t quant = 0.5 * ((static_cast<Double_t>(lod)) + 0.5); 00083 lod = 2 * static_cast<Int_t>(quant); 00084 } 00085 return static_cast<Short_t>(lod); 00086 } 00087 00088 //______________________________________________________________________________ 00089 void TGLSphere::DirectDraw(TGLRnrCtx & rnrCtx) const 00090 { 00091 // Debug tracing 00092 if (gDebug > 4) { 00093 Info("TGLSphere::DirectDraw", "this %ld (class %s) LOD %d", (Long_t)this, IsA()->GetName(), rnrCtx.ShapeLOD()); 00094 } 00095 00096 // 4 stack/slice min for gluSphere to work 00097 UInt_t divisions = rnrCtx.ShapeLOD(); 00098 if (divisions < 4) { 00099 divisions = 4; 00100 } 00101 gluSphere(rnrCtx.GetGluQuadric(), fRadius, divisions, divisions); 00102 }