1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 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 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
46 #include "OSGIntersectAction.h"
48 #include "OSGRenderAction.h"
49 #include "OSGTransform.h"
50 #include "OSGVolume.h"
54 // Documentation for this class is emited in the
55 // OSGTransformBase.cpp file.
56 // To modify it, please change the .fcd file (OSGTransform.fcd) and
57 // regenerate the base file.
59 /*-------------------------------------------------------------------------*/
62 void Transform::changed(ConstFieldMaskArg whichField
,
66 if(whichField
& MatrixFieldMask
)
71 Inherited::changed(whichField
, origin
, details
);
74 /*-------------------------------------------------------------------------*/
77 void Transform::accumulateMatrix(Matrix
&result
)
79 result
.mult(getMatrix());
82 void Transform::adjustVolume(Volume
&volume
)
84 volume
.transform(_sfMatrix
.getValue());
87 /*-------------------------------------------------------------------------*/
90 void Transform::dump( UInt32 uiIndent
,
91 const BitVector bvFlags
) const
93 Inherited::dump(uiIndent
, bvFlags
);
96 /*-------------------------------------------------------------------------*/
99 Transform::Transform(void) :
102 _sfMatrix
.getValue().setIdentity();
105 Transform::Transform(const Transform
&source
) :
110 /*-------------------------------------------------------------------------*/
113 Transform::~Transform(void)
118 /*-------------------------------------------------------------------------*/
121 Action::ResultE
Transform::renderEnter(Action
*action
)
123 RenderAction
*pAction
=
124 dynamic_cast<RenderAction
*>(action
);
126 pAction
->pushVisibility();
128 pAction
->pushMatrix(this->getMatrix());
130 return Action::Continue
;
133 Action::ResultE
Transform::renderLeave(Action
*action
)
135 RenderAction
*pAction
=
136 dynamic_cast<RenderAction
*>(action
);
138 pAction
->popVisibility();
140 pAction
->popMatrix();
142 return Action::Continue
;
145 /*-------------------------------------------------------------------------*/
148 Action::ResultE
Transform::intersectEnter(Action
*action
)
150 // Use parent class for trivial reject
151 if(Inherited::intersectEnter(action
) == Action::Skip
)
154 // Need to check children
155 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
156 Matrix m
= this->getMatrix();
163 m
.multFull(ia
->getLine().getPosition (), pos
);
164 m
.mult (ia
->getLine().getDirection(), dir
);
166 Real32 length
= dir
.length();
168 if(length
< TypeTraits
<Real32
>::getDefaultEps())
169 SWARNING
<< "Transform::intersectEnter: Near-zero scale!" << std::endl
;
171 ia
->setLine(Line(pos
, dir
), ia
->getMaxDist());
174 return Action::Continue
;
177 Action::ResultE
Transform::intersectLeave(Action
*action
)
179 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
180 Matrix m
= this->getMatrix();
185 m
.multFull(ia
->getLine().getPosition (), pos
);
186 m
.mult (ia
->getLine().getDirection(), dir
);
188 ia
->setLine(Line(pos
, dir
), ia
->getMaxDist());
189 ia
->scale(dir
.length());
191 return Action::Continue
;
193 /*-------------------------------------------------------------------------*/
196 void Transform::initMethod(InitPhase ePhase
)
198 Inherited::initMethod(ePhase
);
200 if(ePhase
== TypeObject::SystemPost
)
202 IntersectAction::registerEnterDefault(
204 reinterpret_cast<Action::Callback
>(&Transform::intersectEnter
));
205 IntersectAction::registerLeaveDefault(
207 reinterpret_cast<Action::Callback
>(&Transform::intersectLeave
));
209 RenderAction::registerEnterDefault(
210 Transform::getClassType(),
211 reinterpret_cast<Action::Callback
>(&Transform::renderEnter
));
212 RenderAction::registerLeaveDefault(
213 Transform::getClassType(),
214 reinterpret_cast<Action::Callback
>(&Transform::renderLeave
));