1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include <OSGConfig.h>
48 #include "OSGReplicateTransform.h"
49 #include "OSGVolume.h"
50 #include "OSGIntersectAction.h"
52 #include "OSGRenderAction.h"
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 /***************************************************************************\
63 \***************************************************************************/
65 /***************************************************************************\
67 \***************************************************************************/
69 void ReplicateTransform::initMethod(InitPhase ePhase
)
71 Inherited::initMethod(ePhase
);
73 if(ePhase
== TypeObject::SystemPost
)
75 IntersectAction::registerEnterDefault(
77 reinterpret_cast<Action::Callback
>(
78 &ReplicateTransform::intersectEnter
));
80 IntersectAction::registerLeaveDefault(
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 /***************************************************************************\
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
)
119 void ReplicateTransform::accumulateMatrix(Matrix
&result
)
121 result
.mult(_invWorld
);
124 void ReplicateTransform::adjustVolume(Volume
&volume
)
126 volume
.transform(_invWorld
);
129 /*-------------------------------------------------------------------------*/
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 /*-------------------------------------------------------------------------*/
161 Action::ResultE
ReplicateTransform::intersectEnter(Action
*action
)
163 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
164 Matrix m
= _invWorld
;
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
;
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 /*-------------------------------------------------------------------------*\
199 \*-------------------------------------------------------------------------*/
201 /*----------------------- constructors & destructors ----------------------*/
203 ReplicateTransform::ReplicateTransform(void) :
207 _invWorld
.setIdentity();
210 ReplicateTransform::ReplicateTransform(const ReplicateTransform
&source
) :
212 _invWorld (source
._invWorld
)
216 ReplicateTransform::~ReplicateTransform(void)
220 /*----------------------------- class specific ----------------------------*/
222 void ReplicateTransform::changed(ConstFieldMaskArg whichField
,
226 if(whichField
& TargetFieldMask
)
231 Inherited::changed(whichField
, origin
, details
);
234 void ReplicateTransform::dump( UInt32
,
235 const BitVector
) const
237 SLOG
<< "Dump ReplicateTransform NI" << std::endl
;