| 1 | // Copyright (C) 2009 - 2012 Mathias Froehlich - [email protected] |
| 2 | // |
| 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. |
| 7 | // |
| 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. |
| 12 | // |
| 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. |
| 16 | // |
| 17 | |
| 18 | #ifdef HAVE_CONFIG_H |
| 19 | #include <config.h> |
| 20 | #endif |
| 21 | |
| 22 | #include "HLAMPAircraft.hxx" |
| 23 | |
| 24 | #include "HLAMPAircraftClass.hxx" |
| 25 | |
| 26 | namespace fgviewer { |
| 27 | |
| 28 | HLAMPAircraft::HLAMPAircraft(HLASceneObjectClass* objectClass, const SGWeakPtr<simgear::HLAFederate>& federate) : |
| 29 | HLASceneObject(objectClass, federate), |
| 30 | _simTimeOffset(SGLimitsd::max()) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | HLAMPAircraft::~HLAMPAircraft() |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void |
| 39 | HLAMPAircraft::reflectAttributeValues(const simgear::HLAIndexList& indexList, const simgear::RTIData& tag) |
| 40 | { |
| 41 | HLASceneObject::reflectAttributeValues(indexList, tag); |
| 42 | } |
| 43 | |
| 44 | void |
| 45 | HLAMPAircraft::reflectAttributeValues(const simgear::HLAIndexList& indexList, const SGTimeStamp& timeStamp, const simgear::RTIData& tag) |
| 46 | { |
| 47 | HLASceneObject::reflectAttributeValues(indexList, timeStamp, tag); |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | HLAMPAircraft::createAttributeDataElements() |
| 52 | { |
| 53 | /// FIXME at some point we should not need that anymore |
| 54 | HLASceneObject::createAttributeDataElements(); |
| 55 | |
| 56 | assert(dynamic_cast<HLAMPAircraftClass*>(getObjectClass().get())); |
| 57 | HLAMPAircraftClass& objectClass = static_cast<HLAMPAircraftClass&>(*getObjectClass()); |
| 58 | |
| 59 | setAttributeDataElement(objectClass.getSimTimeIndex(), _simTime.getDataElement()); |
| 60 | setAttributeDataElement(objectClass.getModelPathIndex(), getModelDataElement()); |
| 61 | } |
| 62 | |
| 63 | SGLocationd |
| 64 | HLAMPAircraft::getLocation(const SGTimeStamp& timeStamp) const |
| 65 | { |
| 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; |
| 71 | else |
| 72 | _simTimeOffset = 0.999*_simTimeOffset + 0.001*simTimeOffset; |
| 73 | _lastTimeStamp = timeStamp; |
| 74 | } |
| 75 | double dt = timeStamp.toSecs() - _simTime.getValue() - _simTimeOffset; |
| 76 | |
| 77 | SGLocationd location = HLASceneObject::getLocation(timeStamp); |
| 78 | location.eulerStepBodyVelocitiesMidOrientation(dt, _getRelativeLinearVelocity(), _getRelativeAngularVelocity()); |
| 79 | return location; |
| 80 | } |
| 81 | |
| 82 | } // namespace fgviewer |