changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGDistanceLOD.cpp
blobbdf8b6d2fdd1c3bb7352df5bfd809328095c7a88
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include "OSGAction.h"
45 #include "OSGCamera.h"
46 #include "OSGRenderAction.h"
48 //just for debug
49 #include <iostream>
50 //just for debug
52 #include "OSGDistanceLOD.h"
54 OSG_USING_NAMESPACE
56 // Documentation for this class is emited in the
57 // OSGDistanceLODBase.cpp file.
58 // To modify it, please change the .fcd file (OSGDistanceLOD.fcd) and
59 // regenerate the base file.
61 /*-------------------------------------------------------------------------*/
62 /* Sync */
64 void DistanceLOD::changed(ConstFieldMaskArg whichField,
65 UInt32 origin,
66 BitVector details)
68 Inherited::changed(whichField, origin, details);
71 /*-------------------------------------------------------------------------*/
72 /* Dump */
74 void DistanceLOD::dump( UInt32 OSG_CHECK_ARG(uiIndent),
75 const BitVector OSG_CHECK_ARG(bvFlags )) const
77 SLOG << "Dump DistanceLOD NI" << std::endl;
80 /*-------------------------------------------------------------------------*/
81 /* Constructors */
83 DistanceLOD::DistanceLOD(void) :
84 Inherited()
88 DistanceLOD::DistanceLOD(const DistanceLOD &source) :
89 Inherited(source)
93 /*-------------------------------------------------------------------------*/
94 /* Destructor */
96 DistanceLOD::~DistanceLOD(void)
100 /*-------------------------------------------------------------------------*/
101 /* Init */
103 void DistanceLOD::initMethod(InitPhase ePhase)
105 Inherited::initMethod(ePhase);
107 if(ePhase == TypeObject::SystemPost)
109 RenderAction::registerEnterDefault(
110 DistanceLOD::getClassType(),
111 reinterpret_cast<Action::Callback>(&DistanceLOD::renderEnter));
115 Action::ResultE DistanceLOD::renderEnter(Action *action)
117 action->useNodeList();
119 Int32 numLevels = action->getNNodes();
121 if(numLevels == 0)
122 return Action::Continue;
124 RenderAction *ra = dynamic_cast<RenderAction *>(action);
125 Int32 index = 0;
127 const MFReal32 *range = getMFRange();
129 Int32 numRanges = range->size32();
131 if(numRanges == 0 || numLevels == 1)
133 index = 0;
135 else
137 Pnt3f eyepos;
139 ra->getActivePartition()->getCameraToWorld().mult(eyepos, eyepos);
141 Pnt3f objpos;
143 ra->topMatrix().mult(getCenter(), objpos);
145 Real32 dist = eyepos.dist(objpos);
147 if(numRanges >= numLevels && numLevels > 1)
148 numRanges = numLevels - 1;
150 if(dist >= (*range)[numRanges - 1])
152 index = numRanges;
154 else
156 for(index = 0; index < numRanges; ++index)
158 if(dist < (*range)[index])
159 break;
164 Node *nodePtr = action->getNode(index);
166 if(ra->isVisible(nodePtr))
168 ra->addNode(nodePtr);
171 return Action::Continue;