00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041
00042 #include <OSGConfig.h>
00043
00044 #include <OSGAction.h>
00045 #include <OSGDrawAction.h>
00046 #include <OSGCamera.h>
00047 #include <OSGRenderAction.h>
00048
00049
00050 #include <iostream>
00051
00052
00053 #include "OSGDistanceLOD.h"
00054
00055 OSG_USING_NAMESPACE
00056
00099
00100
00101
00102 void DistanceLOD::changed(BitVector whichField, UInt32 origin)
00103 {
00104 Inherited::changed(whichField, origin);
00105 }
00106
00107
00108
00109
00110 void DistanceLOD::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00111 const BitVector OSG_CHECK_ARG(bvFlags )) const
00112 {
00113 SLOG << "Dump DistanceLOD NI" << std::endl;
00114 }
00115
00116
00117
00118
00119 DistanceLOD::DistanceLOD(void) :
00120 Inherited()
00121 {
00122 }
00123
00124 DistanceLOD::DistanceLOD(const DistanceLOD &source) :
00125 Inherited(source)
00126 {
00127 }
00128
00129
00130
00131
00132 DistanceLOD::~DistanceLOD(void)
00133 {
00134 }
00135
00136
00137
00138
00139 Action::ResultE DistanceLOD::draw(Action *action)
00140 {
00141 DrawActionBase *da = dynamic_cast<DrawActionBase *>(action);
00142 RenderAction *ra = dynamic_cast<RenderAction *>(action);
00143
00144 UInt32 numLevels = action->getNNodes();
00145 UInt32 numRanges = getMFRange()->size();
00146
00147 UInt32 limit = osgMin(numLevels, numRanges);
00148
00149 Int32 index = -1;
00150
00151 Pnt3f eyepos(0.f, 0.f, 0.f);
00152 Pnt3f objpos;
00153
00154 da->getCameraToWorld().mult(eyepos);
00155
00156 if(ra != NULL)
00157 {
00158 ra->top_matrix() .mult(getCenter(), objpos);
00159 }
00160 else
00161 {
00162 da->getActNode()->getToWorld().mult(getCenter(), objpos);
00163 }
00164
00165 Real32 dist = osgsqrt((eyepos[0] - objpos[0])*(eyepos[0] - objpos[0]) +
00166 (eyepos[1] - objpos[1])*(eyepos[1] - objpos[1]) +
00167 (eyepos[2] - objpos[2])*(eyepos[2] - objpos[2]));
00168
00169 da->useNodeList();
00170
00171 if(numRanges != 0 && numLevels!=0 )
00172 {
00173 if(dist < (*(getMFRange()))[0])
00174 {
00175 index = 0;
00176 }
00177 else if(dist >= (*(getMFRange()))[numRanges-1])
00178 {
00179 index = (numLevels > numRanges) ? numRanges : (limit-1);
00180 }
00181 else
00182 {
00183 UInt32 i = 1;
00184
00185 while( (i < numRanges) &&
00186 !( ((*(getMFRange()))[i-1] <= dist) &&
00187 (dist < (*(getMFRange()))[i] ) ) )
00188 {
00189 i++;
00190 }
00191
00192 index = osgMin(i, limit-1);
00193 }
00194
00195 if(da->isVisible(action->getNode(index).getCPtr()))
00196 {
00197 da->addNode(action->getNode(index));
00198 }
00199 }
00200
00201 return Action::Continue;
00202 }
00203
00204
00205
00206
00207 void DistanceLOD::initMethod (void)
00208 {
00209 DrawAction::registerEnterDefault(
00210 getClassType(),
00211 osgTypedMethodFunctor2BaseCPtrRef<
00212 Action::ResultE,
00213 DistanceLODPtr ,
00214 CNodePtr ,
00215 Action *>(&DistanceLOD::draw));
00216
00217 RenderAction::registerEnterDefault(
00218 getClassType(),
00219 osgTypedMethodFunctor2BaseCPtrRef<
00220 Action::ResultE,
00221 DistanceLODPtr ,
00222 CNodePtr ,
00223 Action *>(&DistanceLOD::draw));
00224 }
00225
00226
00227
00228
00229
00230 #ifdef __sgi
00231 #pragma set woff 1174
00232 #endif
00233
00234 #ifdef OSG_LINUX_ICC
00235 #pragma warning( disable : 177 )
00236 #endif
00237
00238 namespace
00239 {
00240 static Char8 cvsid_cpp[] = "@(#)$Id: OSGDistanceLOD.cpp,v 1.22 2002/06/30 05:04:22 vossg Exp $";
00241 static Char8 cvsid_hpp[] = OSGDISTANCELOD_HEADER_CVSID;
00242 static Char8 cvsid_inl[] = OSGDISTANCELOD_INLINE_CVSID;
00243 }
00244
00245
00246