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 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
49 #include "OSGInverseTransform.h"
50 #include "OSGIntersectAction.h"
51 #include "OSGRenderAction.h"
56 // Documentation for this class is emited in the
57 // OSGInverseTransformBase.cpp file.
58 // To modify it, please change the .fcd file (OSGInverseTransform.fcd) and
59 // regenerate the base file.
61 /***************************************************************************\
63 \***************************************************************************/
65 /***************************************************************************\
67 \***************************************************************************/
69 void InverseTransform::initMethod(InitPhase ePhase
)
71 Inherited::initMethod(ePhase
);
73 if(ePhase
== TypeObject::SystemPost
)
75 IntersectAction::registerEnterDefault(
77 reinterpret_cast<Action::Callback
>(
78 &InverseTransform::intersectEnter
));
80 IntersectAction::registerLeaveDefault(
82 reinterpret_cast<Action::Callback
>(
83 &InverseTransform::intersectLeave
));
85 RenderAction::registerEnterDefault(
86 InverseTransform::getClassType(),
87 reinterpret_cast<Action::Callback
>(&InverseTransform::renderEnter
));
89 RenderAction::registerLeaveDefault(
90 InverseTransform::getClassType(),
91 reinterpret_cast<Action::Callback
>(&InverseTransform::renderLeave
));
96 /***************************************************************************\
98 \***************************************************************************/
100 /*-------------------------------------------------------------------------*\
102 \*-------------------------------------------------------------------------*/
104 /*----------------------- constructors & destructors ----------------------*/
106 InverseTransform::InverseTransform(void) :
112 InverseTransform::InverseTransform(const InverseTransform
&source
) :
114 _invWorld (source
._invWorld
)
118 InverseTransform::~InverseTransform(void)
122 /*----------------------------- class specific ----------------------------*/
124 void InverseTransform::changed(ConstFieldMaskArg whichField
,
128 Inherited::changed(whichField
, origin
, details
);
131 void InverseTransform::dump( UInt32 uiIndent
,
132 const BitVector bvFlags
) const
134 Inherited::dump(uiIndent
, bvFlags
);
137 /*------------------------- volume update -------------------------------*/
139 void InverseTransform::adjustVolume(Volume
&volume
)
141 volume
.transform(_invWorld
);
144 void InverseTransform::accumulateMatrix(Matrix
&result
)
146 result
.mult(_invWorld
);
149 /*------------------------- calc matrix ---------------------------------*/
151 void InverseTransform::calcMatrix(const Matrix
&mToWorld
,
154 mResult
.invertFrom(mToWorld
);
156 _invWorld
= mResult
; // remember dynamically set matrix field
159 void InverseTransform::initMatrix(const Matrix
&mToWorld
)
161 _invWorld
.invertFrom(mToWorld
);
164 /*-------------------------------------------------------------------------*/
167 /*-------------------------------------------------------------------------*/
170 Action::ResultE
InverseTransform::intersectEnter(Action
*action
)
172 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
180 m
.multFull(ia
->getLine().getPosition (), pos
);
181 m
.mult (ia
->getLine().getDirection(), dir
);
183 ia
->setLine(Line(pos
, dir
), ia
->getMaxDist());
184 ia
->scale(dir
.length());
186 return Action::Continue
;
189 Action::ResultE
InverseTransform::intersectLeave(Action
*action
)
191 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
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 /*-------------------------------------------------------------------------*/
209 Action::ResultE
InverseTransform::renderEnter(Action
*action
)
211 RenderAction
*pAction
=
212 dynamic_cast<RenderAction
*>(action
);
214 Matrix mMat
; // will be set to World^-1
216 calcMatrix(pAction
->topMatrix(), mMat
);
218 pAction
->pushVisibility();
220 pAction
->pushMatrix(mMat
);
222 return Action::Continue
;
225 Action::ResultE
InverseTransform::renderLeave(Action
*action
)
227 RenderAction
*pAction
=
228 dynamic_cast<RenderAction
*>(action
);
230 pAction
->popVisibility();
232 pAction
->popMatrix();
234 return Action::Continue
;