changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGReplicateTransform.cpp
blob0877ecaf4b615d06a5d1f20eae5fd50fb14fd9a5
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include <OSGConfig.h>
48 #include "OSGReplicateTransform.h"
49 #include "OSGVolume.h"
50 #include "OSGIntersectAction.h"
52 #include "OSGRenderAction.h"
54 OSG_BEGIN_NAMESPACE
56 // Documentation for this class is emitted in the
57 // OSGReplicateTransformBase.cpp file.
58 // To modify it, please change the .fcd file (OSGReplicateTransform.fcd) and
59 // regenerate the base file.
61 /***************************************************************************\
62 * Class variables *
63 \***************************************************************************/
65 /***************************************************************************\
66 * Class methods *
67 \***************************************************************************/
69 void ReplicateTransform::initMethod(InitPhase ePhase)
71 Inherited::initMethod(ePhase);
73 if(ePhase == TypeObject::SystemPost)
75 IntersectAction::registerEnterDefault(
76 getClassType(),
77 reinterpret_cast<Action::Callback>(
78 &ReplicateTransform::intersectEnter));
80 IntersectAction::registerLeaveDefault(
81 getClassType(),
82 reinterpret_cast<Action::Callback>(
83 &ReplicateTransform::intersectLeave));
85 RenderAction::registerEnterDefault(
86 ReplicateTransform::getClassType(),
87 reinterpret_cast<Action::Callback>(
88 &ReplicateTransform::renderEnter));
90 RenderAction::registerLeaveDefault(
91 ReplicateTransform::getClassType(),
92 reinterpret_cast<Action::Callback>(
93 &ReplicateTransform::renderLeave));
98 /***************************************************************************\
99 * Instance methods *
100 \***************************************************************************/
102 void ReplicateTransform::calcMatrix(const Matrix &mToWorld)
104 Matrix prevValue = _invWorld;
106 _invWorld.invertFrom(mToWorld);
108 if(getTarget() != NULL)
110 _invWorld.mult(getTarget()->getToWorld());
113 if(_invWorld != prevValue)
115 invalidateVolume();
119 void ReplicateTransform::accumulateMatrix(Matrix &result)
121 result.mult(_invWorld);
124 void ReplicateTransform::adjustVolume(Volume &volume)
126 volume.transform(_invWorld);
129 /*-------------------------------------------------------------------------*/
130 /* Render */
132 Action::ResultE ReplicateTransform::renderEnter(Action *action)
134 RenderAction *pAction =
135 dynamic_cast<RenderAction *>(action);
137 calcMatrix(pAction->topMatrix());
139 pAction->pushVisibility();
141 pAction->pushMatrix(_invWorld);
143 return Action::Continue;
146 Action::ResultE ReplicateTransform::renderLeave(Action *action)
148 RenderAction *pAction =
149 dynamic_cast<RenderAction *>(action);
151 pAction->popVisibility();
153 pAction->popMatrix();
155 return Action::Continue;
158 /*-------------------------------------------------------------------------*/
159 /* Intersect */
161 Action::ResultE ReplicateTransform::intersectEnter(Action *action)
163 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
164 Matrix m = _invWorld;
166 m.invert();
168 Pnt3f pos;
169 Vec3f dir;
171 m.multFull(ia->getLine().getPosition (), pos);
172 m.mult (ia->getLine().getDirection(), dir);
174 ia->setLine(Line(pos, dir), ia->getMaxDist());
175 ia->scale(dir.length());
177 return Action::Continue;
180 Action::ResultE ReplicateTransform::intersectLeave(Action *action)
182 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
183 Matrix m = _invWorld;
185 Pnt3f pos;
186 Vec3f dir;
188 m.multFull(ia->getLine().getPosition (), pos);
189 m.mult (ia->getLine().getDirection(), dir);
191 ia->setLine(Line(pos, dir), ia->getMaxDist());
192 ia->scale(dir.length());
194 return Action::Continue;
197 /*-------------------------------------------------------------------------*\
198 - private -
199 \*-------------------------------------------------------------------------*/
201 /*----------------------- constructors & destructors ----------------------*/
203 ReplicateTransform::ReplicateTransform(void) :
204 Inherited(),
205 _invWorld ()
207 _invWorld.setIdentity();
210 ReplicateTransform::ReplicateTransform(const ReplicateTransform &source) :
211 Inherited(source ),
212 _invWorld (source._invWorld)
216 ReplicateTransform::~ReplicateTransform(void)
220 /*----------------------------- class specific ----------------------------*/
222 void ReplicateTransform::changed(ConstFieldMaskArg whichField,
223 UInt32 origin,
224 BitVector details)
226 if(whichField & TargetFieldMask)
228 invalidateVolume();
231 Inherited::changed(whichField, origin, details);
234 void ReplicateTransform::dump( UInt32 ,
235 const BitVector ) const
237 SLOG << "Dump ReplicateTransform NI" << std::endl;
240 OSG_END_NAMESPACE