]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLALocation.hxx
HTTP: Rename urlretrieve/urlload to save/load.
[simgear.git] / simgear / hla / HLALocation.hxx
1 // Copyright (C) 2009 - 2010  Mathias Froehlich - Mathias.Froehlich@web.de
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 #ifndef HLALocation_hxx
19 #define HLALocation_hxx
20
21 #include <simgear/math/SGMath.hxx>
22 #include "HLABasicDataElement.hxx"
23 #include "HLATypes.hxx"
24
25 namespace simgear {
26
27 class HLAObjectInstance;
28
29 class HLAAbstractLocation : public SGReferenced {
30 public:
31     virtual ~HLAAbstractLocation() {}
32
33     virtual SGLocationd getLocation() const = 0;
34     virtual void setLocation(const SGLocationd&) = 0;
35
36     virtual SGVec3d getCartPosition() const = 0;
37     virtual void setCartPosition(const SGVec3d&) = 0;
38
39     virtual SGQuatd getCartOrientation() const = 0;
40     virtual void setCartOrientation(const SGQuatd&) = 0;
41
42     virtual SGVec3d getAngularBodyVelocity() const = 0;
43     virtual void setAngularBodyVelocity(const SGVec3d&) = 0;
44
45     virtual SGVec3d getLinearBodyVelocity() const = 0;
46     virtual void setLinearBodyVelocity(const SGVec3d&) = 0;
47
48     virtual double getTimeDifference(const SGTimeStamp&) const
49     { return 0; }
50
51     // Get the position and orientation extrapolated to the given time stamp.
52     SGLocationd getLocation(const SGTimeStamp& timeStamp) const
53     {
54         SGLocationd location = getLocation();
55         location.eulerStepBodyVelocitiesMidOrientation(getTimeDifference(timeStamp), getLinearBodyVelocity(), getAngularBodyVelocity());
56         return location;
57     }
58 };
59
60 class HLACartesianLocation : public HLAAbstractLocation {
61 public:
62     HLACartesianLocation();
63     virtual ~HLACartesianLocation();
64
65     virtual SGLocationd getLocation() const;
66     virtual void setLocation(const SGLocationd& location);
67
68     virtual SGVec3d getCartPosition() const;
69     virtual void setCartPosition(const SGVec3d& position);
70
71     virtual SGQuatd getCartOrientation() const;
72     virtual void setCartOrientation(const SGQuatd& orientation);
73
74     virtual SGVec3d getAngularBodyVelocity() const;
75     virtual void setAngularBodyVelocity(const SGVec3d& angularVelocity);
76
77     virtual SGVec3d getLinearBodyVelocity() const;
78     virtual void setLinearBodyVelocity(const SGVec3d& linearVelocity);
79
80     virtual double getTimeDifference(const SGTimeStamp& timeStamp) const;
81
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);
90
91 private:
92     HLADoubleData _position[3];
93     HLADoubleData _imag[3];
94
95     HLADoubleData _angularVelocity[3];
96     HLADoubleData _linearVelocity[3];
97 };
98
99 class HLAAbstractLocationFactory : public SGReferenced {
100 public:
101     virtual ~HLAAbstractLocationFactory();
102     virtual HLAAbstractLocation* createLocation(HLAObjectInstance&) const = 0;
103 };
104
105 typedef HLAAbstractLocationFactory HLALocationFactory;
106
107 class HLACartesianLocationFactory : public HLAAbstractLocationFactory {
108 public:
109     HLACartesianLocationFactory();
110     virtual ~HLACartesianLocationFactory();
111
112     virtual HLACartesianLocation* createLocation(HLAObjectInstance& objectInstance) const;
113
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);
118
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);
123
124 private:
125     HLADataElementIndex _positionIndex[3];
126     HLADataElementIndex _orientationIndex[3];
127
128     HLADataElementIndex _angularVelocityIndex[3];
129     HLADataElementIndex _linearVelocityIndex[3];
130 };
131
132 class HLAGeodeticLocationFactory : public HLAAbstractLocationFactory {
133 public:
134     enum Semantic {
135         LatitudeDeg,
136         LatitudeRad,
137         LongitudeDeg,
138         LongitudeRad,
139         ElevationM,
140         ElevationFt,
141         HeadingDeg,
142         HeadingRad,
143         PitchDeg,
144         PitchRad,
145         RollDeg,
146         RollRad,
147         GroundTrackDeg,
148         GroundTrackRad,
149         GroundSpeedKnots,
150         GroundSpeedFtPerSec,
151         GroundSpeedMPerSec,
152         VerticalSpeedFtPerSec,
153         VerticalSpeedFtPerMin,
154         VerticalSpeedMPerSec
155     };
156
157     HLAGeodeticLocationFactory();
158     virtual ~HLAGeodeticLocationFactory();
159
160     virtual HLAAbstractLocation* createLocation(HLAObjectInstance& objectInstance) const;
161
162     void setIndex(Semantic semantic, const HLADataElementIndex& index)
163     { _indexSemanticMap[index] = semantic; }
164
165 private:
166     class Location;
167
168     typedef std::map<HLADataElementIndex, Semantic> IndexSemanticMap;
169     IndexSemanticMap _indexSemanticMap;
170 };
171
172 } // namespace simgear
173
174 #endif