Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGDistanceLOD.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
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 //just for debug
00050 #include <iostream>
00051 //just for debug
00052 
00053 #include "OSGDistanceLOD.h"
00054 
00055 OSG_USING_NAMESPACE
00056 
00099 /*-------------------------------------------------------------------------*/
00100 /*                               Sync                                      */
00101 
00102 void DistanceLOD::changed(BitVector whichField, UInt32 origin)
00103 {
00104     Inherited::changed(whichField, origin);
00105 }
00106 
00107 /*-------------------------------------------------------------------------*/
00108 /*                               Dump                                      */
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 /*                            Constructors                                 */
00118 
00119 DistanceLOD::DistanceLOD(void) :
00120     Inherited()
00121 {
00122 }
00123 
00124 DistanceLOD::DistanceLOD(const DistanceLOD &source) :
00125     Inherited(source)
00126 {
00127 }
00128 
00129 /*-------------------------------------------------------------------------*/
00130 /*                             Destructor                                  */
00131 
00132 DistanceLOD::~DistanceLOD(void)
00133 {
00134 }
00135 
00136 /*-------------------------------------------------------------------------*/
00137 /*                                Draw                                     */
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 /*                               Init                                      */
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 /*                              cvs id's                                   */
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 

Generated on Thu Aug 25 04:02:56 2005 for OpenSG by  doxygen 1.4.3