fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGDoubleTransform.cpp
blob9f2b73c7b0315cc804f260e8cacba35bd4e6e163
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 "OSGGL.h"
50 #include "OSGIntersectAction.h"
52 #include "OSGRenderAction.h"
54 #ifdef OSG_HAVE_ACTION //CHECK
55 #include "OSGIntersectActor.h"
56 #endif
58 #include "OSGDoubleTransform.h"
59 #include "OSGVolume.h"
61 OSG_BEGIN_NAMESPACE
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 /*-------------------------------------------------------------------------*/
69 /* Sync */
71 void DoubleTransform::changed(ConstFieldMaskArg whichField,
72 UInt32 origin,
73 BitVector details)
75 if(whichField & MatrixFieldMask)
77 invalidateVolume();
80 Inherited::changed(whichField, origin, details);
83 /***************************************************************************\
84 * Class variables *
85 \***************************************************************************/
87 /***************************************************************************\
88 * Class methods *
89 \***************************************************************************/
91 /***************************************************************************\
92 * Instance methods *
93 \***************************************************************************/
95 /*----------------------------- class specific ----------------------------*/
97 void DoubleTransform::accumulateMatrix(Matrix &result)
99 result.mult(getMatrix());
102 void DoubleTransform::adjustVolume(Volume &volume)
104 Matrix4f temp;
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 /*-------------------------------------------------------------------------*\
116 - private -
117 \*-------------------------------------------------------------------------*/
119 /*----------------------- constructors & destructors ----------------------*/
121 DoubleTransform::DoubleTransform(void) :
122 Inherited()
124 _sfMatrix.getValue().setIdentity();
127 DoubleTransform::DoubleTransform(const DoubleTransform &source) :
128 Inherited(source)
132 DoubleTransform::~DoubleTransform(void)
136 /*-------------------------------------------------------------------------*/
137 /* Render */
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 /*-------------------------------------------------------------------------*/
162 /* Intersect */
164 Action::ResultE DoubleTransform::intersectEnter(Action *action)
166 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
167 Matrix4d matd = this->getMatrix();
169 matd.invert();
171 Matrix4f m;
172 m.convertFrom(matd);
174 Pnt3f pos;
175 Vec3f dir;
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();
191 Matrix4f m;
192 m.convertFrom(matd);
194 Pnt3f pos;
195 Vec3f dir;
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 *>(
211 funcArg.getActor());
212 Matrix matrix = this->getMatrix();
213 Line transLine;
214 Pnt3f pos;
215 Vec3f dir;
217 matrix.invert();
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 *>(
240 funcArg.getActor());
241 const Matrix &matrix = this->getMatrix();
242 Pnt3f pos;
243 Vec3f dir;
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;
257 #endif
259 /*-------------------------------------------------------------------------*/
260 /* Init */
262 void DoubleTransform::initMethod(InitPhase ePhase)
264 Inherited::initMethod(ePhase);
266 if(ePhase == TypeObject::SystemPost)
268 IntersectAction::registerEnterDefault(
269 getClassType(),
270 reinterpret_cast<Action::Callback>(&DoubleTransform::intersectEnter));
272 IntersectAction::registerLeaveDefault(
273 getClassType(),
274 reinterpret_cast<Action::Callback>(&DoubleTransform::intersectLeave));
276 RenderAction::registerEnterDefault(
277 getClassType(),
278 reinterpret_cast<Action::Callback>(&DoubleTransform::renderEnter));
280 RenderAction::registerLeaveDefault(
281 getClassType(),
282 reinterpret_cast<Action::Callback>(&DoubleTransform::renderLeave));
284 #ifdef OSG_HAVE_ACTION //CHECK
285 IntersectActor::regClassEnter(
286 osgTypedMethodFunctor2BaseCPtr<
287 NewActionTypes::ResultE,
288 TransformPtr ,
289 NodeCorePtr ,
290 ActorBase::FunctorArgumentType &>(&DoubleTransform::intersectActorEnter),
291 getClassType());
293 IntersectActor::regClassLeave(
294 osgTypedMethodFunctor2BaseCPtr<
295 NewActionTypes::ResultE,
296 TransformPtr ,
297 NodeCorePtr ,
298 ActorBase::FunctorArgumentType &>(&DoubleTransform::intersectActorLeave),
299 getClassType());
300 #endif
305 OSG_END_NAMESPACE