1 // Copyright (C) 2009 - 2010 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.
18 #ifndef HLALocation_hxx
19 #define HLALocation_hxx
21 #include <simgear/math/SGMath.hxx>
22 #include "HLABasicDataElement.hxx"
23 #include "HLATypes.hxx"
27 class HLAObjectInstance;
29 class HLAAbstractLocation : public SGReferenced {
31 virtual ~HLAAbstractLocation() {}
33 virtual SGLocationd getLocation() const = 0;
34 virtual void setLocation(const SGLocationd&) = 0;
36 virtual SGVec3d getCartPosition() const = 0;
37 virtual void setCartPosition(const SGVec3d&) = 0;
39 virtual SGQuatd getCartOrientation() const = 0;
40 virtual void setCartOrientation(const SGQuatd&) = 0;
42 virtual SGVec3d getAngularBodyVelocity() const = 0;
43 virtual void setAngularBodyVelocity(const SGVec3d&) = 0;
45 virtual SGVec3d getLinearBodyVelocity() const = 0;
46 virtual void setLinearBodyVelocity(const SGVec3d&) = 0;
48 virtual double getTimeDifference(const SGTimeStamp&) const
51 // Get the position and orientation extrapolated to the given time stamp.
52 SGLocationd getLocation(const SGTimeStamp& timeStamp) const
54 SGLocationd location = getLocation();
55 location.eulerStepBodyVelocitiesMidOrientation(getTimeDifference(timeStamp), getLinearBodyVelocity(), getAngularBodyVelocity());
60 class HLACartesianLocation : public HLAAbstractLocation {
62 HLACartesianLocation();
63 virtual ~HLACartesianLocation();
65 virtual SGLocationd getLocation() const;
66 virtual void setLocation(const SGLocationd& location);
68 virtual SGVec3d getCartPosition() const;
69 virtual void setCartPosition(const SGVec3d& position);
71 virtual SGQuatd getCartOrientation() const;
72 virtual void setCartOrientation(const SGQuatd& orientation);
74 virtual SGVec3d getAngularBodyVelocity() const;
75 virtual void setAngularBodyVelocity(const SGVec3d& angularVelocity);
77 virtual SGVec3d getLinearBodyVelocity() const;
78 virtual void setLinearBodyVelocity(const SGVec3d& linearVelocity);
80 virtual double getTimeDifference(const SGTimeStamp& timeStamp) const;
82 HLADataElement* getPositionDataElement();
83 HLADataElement* getPositionDataElement(unsigned i);
84 HLADataElement* getOrientationDataElement();
85 HLADataElement* getOrientationDataElement(unsigned i);
86 HLADataElement* getAngularVelocityDataElement();
87 HLADataElement* getAngularVelocityDataElement(unsigned i);
88 HLADataElement* getLinearVelocityDataElement();
89 HLADataElement* getLinearVelocityDataElement(unsigned i);
92 HLADoubleData _position[3];
93 HLADoubleData _imag[3];
95 HLADoubleData _angularVelocity[3];
96 HLADoubleData _linearVelocity[3];
99 class HLAAbstractLocationFactory : public SGReferenced {
101 virtual ~HLAAbstractLocationFactory();
102 virtual HLAAbstractLocation* createLocation(HLAObjectInstance&) const = 0;
105 typedef HLAAbstractLocationFactory HLALocationFactory;
107 class HLACartesianLocationFactory : public HLAAbstractLocationFactory {
109 HLACartesianLocationFactory();
110 virtual ~HLACartesianLocationFactory();
112 virtual HLACartesianLocation* createLocation(HLAObjectInstance& objectInstance) const;
114 void setPositionIndex(const HLADataElementIndex& dataElementIndex);
115 void setPositionIndex(unsigned index, const HLADataElementIndex& dataElementIndex);
116 void setOrientationIndex(const HLADataElementIndex& dataElementIndex);
117 void setOrientationIndex(unsigned index, const HLADataElementIndex& dataElementIndex);
119 void setAngularVelocityIndex(const HLADataElementIndex& dataElementIndex);
120 void setAngularVelocityIndex(unsigned index, const HLADataElementIndex& dataElementIndex);
121 void setLinearVelocityIndex(const HLADataElementIndex& dataElementIndex);
122 void setLinearVelocityIndex(unsigned index, const HLADataElementIndex& dataElementIndex);
125 HLADataElementIndex _positionIndex[3];
126 HLADataElementIndex _orientationIndex[3];
128 HLADataElementIndex _angularVelocityIndex[3];
129 HLADataElementIndex _linearVelocityIndex[3];
132 class HLAGeodeticLocationFactory : public HLAAbstractLocationFactory {
152 VerticalSpeedFtPerSec,
153 VerticalSpeedFtPerMin,
157 HLAGeodeticLocationFactory();
158 virtual ~HLAGeodeticLocationFactory();
160 virtual HLAAbstractLocation* createLocation(HLAObjectInstance& objectInstance) const;
162 void setIndex(Semantic semantic, const HLADataElementIndex& index)
163 { _indexSemanticMap[index] = semantic; }
168 typedef std::map<HLADataElementIndex, Semantic> IndexSemanticMap;
169 IndexSemanticMap _indexSemanticMap;
172 } // namespace simgear