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 "OSGTransformationInterfaceSensor.h"
49 #include "OSGTransformationDeviceInterface.h"
53 // Documentation for this class is emitted in the
54 // OSGTransformationInterfaceSensorBase.cpp file.
55 // To modify it, please change the .fcd file
56 // (OSGTransformationInterfaceSensor.fcd) and
57 // regenerate the base file.
59 /***************************************************************************\
61 \***************************************************************************/
63 /***************************************************************************\
65 \***************************************************************************/
67 void TransformationInterfaceSensor::initMethod(InitPhase ePhase
)
69 Inherited::initMethod(ePhase
);
71 if(ePhase
== TypeObject::SystemPost
)
77 /***************************************************************************\
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 TransformationInterfaceSensor::TransformationInterfaceSensor(void) :
93 TransformationInterfaceSensor::TransformationInterfaceSensor(
94 const TransformationInterfaceSensor
&source
) :
101 TransformationInterfaceSensor::~TransformationInterfaceSensor(void)
105 /*----------------------------- class specific ----------------------------*/
107 void TransformationInterfaceSensor::changed(ConstFieldMaskArg whichField
,
111 Inherited::changed(whichField
, origin
, details
);
114 void TransformationInterfaceSensor::dump( UInt32
,
115 const BitVector
) const
117 SLOG
<< "Dump TransformationInterfaceSensor NI" << std::endl
;
120 Quaternion
quatFromEul(Real32 rX
, Real32 rY
, Real32 rZ
)
122 Quaternion returnValue
;
153 returnValue
.setValueAsQuat(sc
* cz
- cs
* sz
,
161 void TransformationInterfaceSensor::frame(Time tTime
, UInt32 uiFrame
)
163 if(_pTrDevice
== NULL
)
166 Matrix mMat
= _sfTransformation
.getValue();
170 if(_pTrDevice
->hasNewData() == true)
172 Real32 rScale
= _sfTranslationScale
.getValue();
174 editSField(TransformationFieldMask
);
175 editSField(TranslationFieldMask
);
176 editSField(RotationFieldMask
);
178 _sfTranslation
.getValue().setValues(
179 _pTrDevice
->getTranslate()[0] * rScale
,
180 _pTrDevice
->getTranslate()[1] * rScale
,
181 _pTrDevice
->getTranslate()[2] * rScale
);
183 rScale
= _sfRotationScale
.getValue() * Pi
* 2.0f
;
185 _sfRotation
.getValue().setValue(
186 quatFromEul(_pTrDevice
->getRotate()[0] * rScale
,
187 _pTrDevice
->getRotate()[1] * rScale
,
188 _pTrDevice
->getRotate()[2] * rScale
));
191 _sfRotation
.getValue().getValue(_sfTransformation
.getValue());
193 _pTrDevice
->clearNewData();
195 _sfTransformation
.getValue()[3][0] = _sfTranslation
.getValue()[0];
196 _sfTransformation
.getValue()[3][1] = _sfTranslation
.getValue()[1];
197 _sfTransformation
.getValue()[3][2] = _sfTranslation
.getValue()[2];
199 _sfTransformation
.getValue().multLeft(mMat
);
203 _pTrDevice
->unlock();
206 bool TransformationInterfaceSensor::init(void)
208 bool returnValue
= Inherited::init();
210 if(returnValue
== true)
213 dynamic_cast<TransformationDeviceInterface
*>(_pDevice
.get());
215 if(_pTrDevice
== NULL
)
219 FWARNING(("device is not a transformation device\n"));
226 void TransformationInterfaceSensor::shutdown(void)
228 Inherited::shutdown();