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"
50 #include "OSGIntersectAction.h"
52 #include "OSGRenderAction.h"
54 #ifdef OSG_HAVE_ACTION //CHECK
55 #include "OSGIntersectActor.h"
58 #include "OSGDoubleTransform.h"
59 #include "OSGVolume.h"
63 // Documentation for this class is emitted in the
64 // OSGDoubleTransformBase.cpp file.
65 // To modify it, please change the .fcd file (OSGDoubleTransform.fcd) and
66 // regenerate the base file.
68 /*-------------------------------------------------------------------------*/
71 void DoubleTransform::changed(ConstFieldMaskArg whichField
,
75 if(whichField
& MatrixFieldMask
)
80 Inherited::changed(whichField
, origin
, details
);
83 /***************************************************************************\
85 \***************************************************************************/
87 /***************************************************************************\
89 \***************************************************************************/
91 /***************************************************************************\
93 \***************************************************************************/
95 /*----------------------------- class specific ----------------------------*/
97 void DoubleTransform::accumulateMatrix(Matrix
&result
)
99 result
.mult(getMatrix());
102 void DoubleTransform::adjustVolume(Volume
&volume
)
105 temp
.convertFrom(_sfMatrix
.getValue());
106 volume
.transform(temp
);
109 void DoubleTransform::dump( UInt32 uiIndent
,
110 const BitVector bvFlags
) const
112 Inherited::dump(uiIndent
, bvFlags
);
115 /*-------------------------------------------------------------------------*\
117 \*-------------------------------------------------------------------------*/
119 /*----------------------- constructors & destructors ----------------------*/
121 DoubleTransform::DoubleTransform(void) :
124 _sfMatrix
.getValue().setIdentity();
127 DoubleTransform::DoubleTransform(const DoubleTransform
&source
) :
132 DoubleTransform::~DoubleTransform(void)
136 /*-------------------------------------------------------------------------*/
139 Action::ResultE
DoubleTransform::renderEnter(Action
*action
)
141 RenderAction
*pAction
= dynamic_cast<RenderAction
*>(action
);
143 pAction
->pushVisibility();
145 pAction
->pushMatrix(this->getMatrix());
147 return Action::Continue
;
150 Action::ResultE
DoubleTransform::renderLeave(Action
*action
)
152 RenderAction
*pAction
= dynamic_cast<RenderAction
*>(action
);
154 pAction
->popVisibility();
156 pAction
->popMatrix();
158 return Action::Continue
;
161 /*-------------------------------------------------------------------------*/
164 Action::ResultE
DoubleTransform::intersectEnter(Action
*action
)
166 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
167 Matrix4d matd
= this->getMatrix();
177 m
.multFull(ia
->getLine().getPosition (), pos
);
178 m
.mult (ia
->getLine().getDirection(), dir
);
180 ia
->setLine(Line(pos
, dir
), ia
->getMaxDist());
181 ia
->scale(dir
.length());
183 return Action::Continue
;
186 Action::ResultE
DoubleTransform::intersectLeave(Action
*action
)
188 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
189 Matrix4d matd
= this->getMatrix();
197 m
.multFull(ia
->getLine().getPosition (), pos
);
198 m
.mult (ia
->getLine().getDirection(), dir
);
200 ia
->setLine(Line(pos
, dir
), ia
->getMaxDist());
201 ia
->scale(dir
.length());
203 return Action::Continue
;
206 #ifdef OSG_HAVE_ACTION //CHECK
207 NewActionTypes::ResultE
Transform::intersectActorEnter(
208 ActorBase::FunctorArgumentType
&funcArg
)
210 IntersectActor
*pIA
= dynamic_cast<IntersectActor
*>(
212 Matrix matrix
= this->getMatrix();
219 matrix
.multFullMatrixPnt(pIA
->getRay().getPosition (), pos
);
220 matrix
.multMatrixVec (pIA
->getRay().getDirection(), dir
);
222 transLine
.setValue(pos
, dir
);
224 pIA
->beginEditState();
226 pIA
->setRay (transLine
);
227 pIA
->setScaleFactor(pIA
->getScaleFactor() / dir
.length());
229 pIA
->endEditState ();
231 pIA
->setupChildrenPriorities();
233 return NewActionTypes::Continue
;
236 NewActionTypes::ResultE
Transform::intersectActorLeave(
237 ActorBase::FunctorArgumentType
&funcArg
)
239 IntersectActor
*pIA
= dynamic_cast<IntersectActor
*>(
241 const Matrix
&matrix
= this->getMatrix();
245 matrix
.multFullMatrixPnt(pIA
->getRay().getPosition (), pos
);
246 matrix
.multMatrixVec (pIA
->getRay().getDirection(), dir
);
248 pIA
->beginEditState();
250 pIA
->setRay (Line(pos
, dir
) );
251 pIA
->setScaleFactor(pIA
->getScaleFactor() / dir
.length());
253 pIA
->endEditState ();
255 return NewActionTypes::Continue
;
259 /*-------------------------------------------------------------------------*/
262 void DoubleTransform::initMethod(InitPhase ePhase
)
264 Inherited::initMethod(ePhase
);
266 if(ePhase
== TypeObject::SystemPost
)
268 IntersectAction::registerEnterDefault(
270 reinterpret_cast<Action::Callback
>(&DoubleTransform::intersectEnter
));
272 IntersectAction::registerLeaveDefault(
274 reinterpret_cast<Action::Callback
>(&DoubleTransform::intersectLeave
));
276 RenderAction::registerEnterDefault(
278 reinterpret_cast<Action::Callback
>(&DoubleTransform::renderEnter
));
280 RenderAction::registerLeaveDefault(
282 reinterpret_cast<Action::Callback
>(&DoubleTransform::renderLeave
));
284 #ifdef OSG_HAVE_ACTION //CHECK
285 IntersectActor::regClassEnter(
286 osgTypedMethodFunctor2BaseCPtr
<
287 NewActionTypes::ResultE
,
290 ActorBase::FunctorArgumentType
&>(&DoubleTransform::intersectActorEnter
),
293 IntersectActor::regClassLeave(
294 osgTypedMethodFunctor2BaseCPtr
<
295 NewActionTypes::ResultE
,
298 ActorBase::FunctorArgumentType
&>(&DoubleTransform::intersectActorLeave
),