changed: gcc8 base update
[opensg.git] / Source / Contrib / ComplexSceneManager / Sensor / InterfaceSensors / OSGTransformationInterfaceSensor.cpp
blob4bfc8abd4eb1f1f7fd0992fe6752d75812e3e69c
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 "OSGTransformationInterfaceSensor.h"
49 #include "OSGTransformationDeviceInterface.h"
51 OSG_BEGIN_NAMESPACE
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 /***************************************************************************\
60 * Class variables *
61 \***************************************************************************/
63 /***************************************************************************\
64 * Class methods *
65 \***************************************************************************/
67 void TransformationInterfaceSensor::initMethod(InitPhase ePhase)
69 Inherited::initMethod(ePhase);
71 if(ePhase == TypeObject::SystemPost)
77 /***************************************************************************\
78 * Instance methods *
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
82 - private -
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 TransformationInterfaceSensor::TransformationInterfaceSensor(void) :
88 Inherited( ),
89 _pTrDevice(NULL)
93 TransformationInterfaceSensor::TransformationInterfaceSensor(
94 const TransformationInterfaceSensor &source) :
96 Inherited(source),
97 _pTrDevice(NULL )
101 TransformationInterfaceSensor::~TransformationInterfaceSensor(void)
105 /*----------------------------- class specific ----------------------------*/
107 void TransformationInterfaceSensor::changed(ConstFieldMaskArg whichField,
108 UInt32 origin,
109 BitVector details)
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;
124 Real32 cx;
125 Real32 cy;
126 Real32 cz;
127 Real32 sx;
128 Real32 sy;
129 Real32 sz;
130 Real32 sc;
131 Real32 cs;
132 Real32 cc;
133 Real32 ss;
135 rX /= 2.0;
136 rY /= 2.0;
137 rZ /= 2.0;
139 cx = osgCos(rX);
140 sx = osgSin(rX);
142 cy = osgCos(rY);
143 sy = osgSin(rY);
145 cz = osgCos(rZ);
146 sz = osgSin(rZ);
148 sc = sx * cy;
149 ss = sx * sy;
150 cs = cx * sy;
151 cc = cx * cy;
153 returnValue.setValueAsQuat(sc * cz - cs * sz,
154 cs * cz + sc * sz,
155 cc * sz - ss * cz,
156 cc * cz + ss * sz);
158 return returnValue;
161 void TransformationInterfaceSensor::frame(Time tTime, UInt32 uiFrame)
163 if(_pTrDevice == NULL)
164 return;
166 Matrix mMat = _sfTransformation.getValue();
168 _pTrDevice->lock();
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)
212 _pTrDevice =
213 dynamic_cast<TransformationDeviceInterface *>(_pDevice.get());
215 if(_pTrDevice == NULL)
217 returnValue = false;
219 FWARNING(("device is not a transformation device\n"));
223 return returnValue;
226 void TransformationInterfaceSensor::shutdown(void)
228 Inherited::shutdown();
230 _pTrDevice = NULL;
233 OSG_END_NAMESPACE