1 // Copyright (C) 2009 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "HLAMPAircraft.hxx"
24 #include "HLAMPAircraftClass.hxx"
28 HLAMPAircraft::HLAMPAircraft(HLASceneObjectClass* objectClass, const SGWeakPtr<simgear::HLAFederate>& federate) :
29 HLASceneObject(objectClass, federate),
30 _simTimeOffset(SGLimitsd::max())
34 HLAMPAircraft::~HLAMPAircraft()
39 HLAMPAircraft::reflectAttributeValues(const simgear::HLAIndexList& indexList, const simgear::RTIData& tag)
41 HLASceneObject::reflectAttributeValues(indexList, tag);
45 HLAMPAircraft::reflectAttributeValues(const simgear::HLAIndexList& indexList, const SGTimeStamp& timeStamp, const simgear::RTIData& tag)
47 HLASceneObject::reflectAttributeValues(indexList, timeStamp, tag);
51 HLAMPAircraft::createAttributeDataElements()
53 /// FIXME at some point we should not need that anymore
54 HLASceneObject::createAttributeDataElements();
56 assert(dynamic_cast<HLAMPAircraftClass*>(getObjectClass().get()));
57 HLAMPAircraftClass& objectClass = static_cast<HLAMPAircraftClass&>(*getObjectClass());
59 setAttributeDataElement(objectClass.getSimTimeIndex(), _simTime.getDataElement());
60 setAttributeDataElement(objectClass.getModelPathIndex(), getModelDataElement());
64 HLAMPAircraft::getLocation(const SGTimeStamp& timeStamp) const
66 // FIXME: puh, is frame rate dependent. Think about something more robust ...
67 if (_lastTimeStamp != timeStamp) {
68 double simTimeOffset = timeStamp.toSecs() - _simTime.getValue();
69 if (2 < fabs(simTimeOffset - _simTimeOffset))
70 _simTimeOffset = simTimeOffset;
72 _simTimeOffset = 0.999*_simTimeOffset + 0.001*simTimeOffset;
73 _lastTimeStamp = timeStamp;
75 double dt = timeStamp.toSecs() - _simTime.getValue() - _simTimeOffset;
77 SGLocationd location = HLASceneObject::getLocation(timeStamp);
78 location.eulerStepBodyVelocitiesMidOrientation(dt, _getRelativeLinearVelocity(), _getRelativeAngularVelocity());
82 } // namespace fgviewer