OSGDistanceLOD.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *                     Copyright 2000-2002 by OpenSG Forum                   *
00006  *                                                                           *
00007  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00008  *                                                                           *
00009 \*---------------------------------------------------------------------------*/
00010 /*---------------------------------------------------------------------------*\
00011  *                                License                                    *
00012  *                                                                           *
00013  * This library is free software; you can redistribute it and/or modify it   *
00014  * under the terms of the GNU Library General Public License as published    *
00015  * by the Free Software Foundation, version 2.                               *
00016  *                                                                           *
00017  * This library is distributed in the hope that it will be useful, but       *
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00020  * Library General Public License for more details.                          *
00021  *                                                                           *
00022  * You should have received a copy of the GNU Library General Public         *
00023  * License along with this library; if not, write to the Free Software       *
00024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00025  *                                                                           *
00026 \*---------------------------------------------------------------------------*/
00027 /*---------------------------------------------------------------------------*\
00028  *                                Changes                                    *
00029  *                                                                           *
00030  *                                                                           *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035 \*---------------------------------------------------------------------------*/
00036
00037 OSG_BEGIN_NAMESPACE
00038
00039 template<class RenderActionT> inline
00040 ActionBase::ResultE DistanceLOD::render(Action *action)
00041 {
00042     action->useNodeList();
00043
00044     Int32 numLevels = action->getNNodes();
00045
00046     if(numLevels == 0)
00047         return Action::Continue;
00048
00049     RenderActionT  *ra        = dynamic_cast<RenderActionT  *>(action);
00050     Int32           index     = -1;
00051
00052     const MFReal32 *range = getMFRange();
00053
00054     Int32 numRanges = range->size();
00055
00056     if (numRanges == 0)
00057     {
00058         index = 0;
00059     }
00060     else
00061     {
00062         Pnt3f eyepos;
00063
00064         ra->getActivePartition()->getCameraToWorld().mult(eyepos, eyepos);
00065
00066         Pnt3f objpos;
00067
00068         ra->topMatrix().mult(getCenter(), objpos);
00069
00070         Real32 dist = eyepos.dist(objpos);
00071
00072         if(numRanges >= numLevels)
00073             numRanges = numLevels - 1;
00074
00075         if(dist >= (*range)[numRanges - 1])
00076         {
00077             index = numRanges;
00078         }
00079         else
00080         {
00081             for(index = 0; index < numRanges; ++index)
00082             {
00083                 if(dist < (*range)[index])
00084                     break;
00085             }
00086         }
00087     }
00088
00089     Node *nodePtr = action->getNode(index);
00090
00091     if(ra->isVisible(nodePtr))
00092     {
00093         ra->addNode(nodePtr);
00094     }
00095
00096     return ActionBase::Continue;
00097 }
00098
00099 OSG_END_NAMESPACE
00100
00101