You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
7.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "basicPosition.h"
  2. #include "string.h"
  3. position3D::position3D()
  4. {
  5. x = y = z = lat = lon = rot_x = rot_y = rot_z = speed = 0.f;
  6. utmZone = 0;
  7. SouthHemisphere = false;
  8. }
  9. position3D::position3D(C3D_WGS84_LOC loc, C3D_ORIENT_DEG orient)
  10. {
  11. coordConverter CC;
  12. lat = loc.lat;
  13. lon = loc.lon;
  14. z = loc.alt;
  15. SouthHemisphere = (lat < 0.0);
  16. #ifdef FLOAT_64
  17. double A, B;
  18. CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
  19. x = A;
  20. y = B;
  21. #else
  22. CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
  23. #endif
  24. rot_x = deg2rad(orient.rot_x);
  25. rot_y = deg2rad(orient.rot_y);
  26. rot_z = deg2rad(orient.rot_z);
  27. }
  28. position3D::position3D(C3D_WGS84_LOC loc, C3D_ORIENT_RAD orient)
  29. {
  30. coordConverter CC;
  31. lat = loc.lat;
  32. lon = loc.lon;
  33. z = loc.alt;
  34. SouthHemisphere = (lat < 0.0);
  35. #ifdef FLOAT_64
  36. double A, B;
  37. CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
  38. x = A;
  39. y = B;
  40. #else
  41. CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
  42. #endif
  43. rot_x = orient.rot_x;
  44. rot_y = orient.rot_y;
  45. rot_z = orient.rot_z;
  46. }
  47. position3D::position3D( bool shs, int UTM_Zone, C3D_DECART loc, C3D_ORIENT_DEG orient)
  48. {
  49. coordConverter CC;
  50. utmZone = UTM_Zone;
  51. x = loc.x;
  52. y = loc.y;
  53. z = loc.z;
  54. SouthHemisphere = shs;
  55. #ifdef FLOAT_64
  56. double A, B;
  57. CC.UTMXYToLatLon(x, y, utmZone, SouthHemisphere, A, B);
  58. lat = A;
  59. lon = B;
  60. #else
  61. CC.UTMXYToLatLon(x, y, utmZone, SouthHemisphere, lat, lon);
  62. #endif
  63. rot_x = deg2rad(orient.rot_x);
  64. rot_y = deg2rad(orient.rot_y);
  65. rot_z = deg2rad(orient.rot_z);
  66. }
  67. position3D::position3D( bool shs, int UTM_Zone, C3D_DECART loc, C3D_ORIENT_RAD orient)
  68. {
  69. coordConverter CC;
  70. utmZone = UTM_Zone;
  71. x = loc.x;
  72. y = loc.y;
  73. z = loc.z;
  74. #ifdef FLOAT_64
  75. double A, B;
  76. CC.UTMXYToLatLon(x, y, utmZone, SouthHemisphere, A, B);
  77. lat = A;
  78. lon = B;
  79. #else
  80. CC.UTMXYToLatLon(x, y, utmZone, SouthHemisphere, lat, lon);
  81. #endif
  82. rot_x = orient.rot_x;
  83. rot_y = orient.rot_y;
  84. rot_z = orient.rot_z;
  85. }
  86. position3D::~position3D() {}
  87. void position3D::setPositionWGS84(C3D_FLOAT Lat, C3D_FLOAT Lon, C3D_FLOAT Alt)
  88. {
  89. coordConverter CC;
  90. lat = Lat;
  91. lon = Lon;
  92. z = Alt;
  93. SouthHemisphere = ( Lat < 0.0 );
  94. #ifdef FLOAT_64
  95. double A, B;
  96. utmZone = CC.LatLonToUTMXY(lat, lon, 0, A, B);
  97. x = A;
  98. y = B;
  99. #else
  100. utmZone = CC.LatLonToUTMXY(lat, lon, 0, x, y);
  101. #endif
  102. }
  103. void position3D::setPositionXYZ(C3D_FLOAT X, C3D_FLOAT Y, C3D_FLOAT Z, bool shs, int zone )
  104. {
  105. coordConverter CC;
  106. if (zone != 0)
  107. {
  108. utmZone = zone;
  109. }
  110. x = X;
  111. y = Y;
  112. z = Z;
  113. SouthHemisphere = shs;
  114. #ifdef FLOAT_64
  115. double A, B;
  116. CC.UTMXYToLatLon(x, y, utmZone, SouthHemisphere, A, B);
  117. lat = A;
  118. lon = B;
  119. #else
  120. CC.UTMXYToLatLon(x, y, utmZone, SouthHemisphere, lat, lon);
  121. #endif
  122. }
  123. C3D_WGS84_LOC position3D::getWGS84(void)
  124. {
  125. C3D_WGS84_LOC retVal;
  126. retVal.lat = lat;
  127. retVal.lon = lon;
  128. retVal.alt = z;
  129. return retVal;
  130. }
  131. C3D_DECART position3D::getXYZ(void)
  132. {
  133. C3D_DECART retVal;
  134. retVal.x = x;
  135. retVal.y = y;
  136. retVal.z = z;
  137. return retVal;
  138. }
  139. void position3D::setOrientationRad(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ)
  140. {
  141. rot_x = RotX;
  142. rot_y = RotY;
  143. rot_z = RotZ;
  144. }
  145. void position3D::setOrientationDeg(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ)
  146. {
  147. rot_x = deg2rad(RotX);
  148. rot_y = deg2rad(RotY);
  149. rot_z = deg2rad(RotZ);
  150. }
  151. void position3D::setSpeed(C3D_FLOAT Speed)
  152. {
  153. speed = Speed;
  154. }
  155. // Constructor implementation
  156. basicPosition::basicPosition() :
  157. position3D()
  158. {
  159. m_pTransform = NULL;
  160. updateMatrix();
  161. }
  162. basicPosition::basicPosition(const basicPosition & src): position3D()
  163. {
  164. x = src.x;
  165. y = src.y;
  166. z = src.z;
  167. rot_x = src.rot_x;
  168. rot_y = src.rot_y;
  169. rot_z = src.rot_z;
  170. lat = src.lat;
  171. lon = src.lon;
  172. speed = src.speed;
  173. utmZone = src.utmZone;
  174. m_nZoneID = src.m_nZoneID;
  175. m_pTransform = NULL;
  176. updateMatrix();
  177. }
  178. basicPosition & basicPosition::operator=(const basicPosition & src)
  179. {
  180. if (this == &src)
  181. {
  182. return *this;
  183. };
  184. x = src.x;
  185. y = src.y;
  186. z = src.z;
  187. rot_x = src.rot_x;
  188. rot_y = src.rot_y;
  189. rot_z = src.rot_z;
  190. lat = src.lat;
  191. lon = src.lon;
  192. speed = src.speed;
  193. utmZone = src.utmZone;
  194. m_nZoneID = src.m_nZoneID;
  195. m_pTransform = NULL;
  196. updateMatrix();
  197. return *this;
  198. }
  199. basicPosition::basicPosition(C3D_WGS84_LOC loc, C3D_ORIENT_DEG orient) :
  200. position3D(loc, orient)
  201. {
  202. m_pTransform = NULL;
  203. position3D::setSpeed(0.0f);
  204. updateMatrix();
  205. }
  206. basicPosition::basicPosition(C3D_WGS84_LOC loc, C3D_ORIENT_RAD orient) :
  207. position3D(loc, orient)
  208. {
  209. m_pTransform = NULL;
  210. position3D::setSpeed(0.0f);
  211. updateMatrix();
  212. }
  213. basicPosition::basicPosition(bool shs, int UTM_Zone, C3D_DECART loc, C3D_ORIENT_DEG orient) :
  214. position3D(shs, UTM_Zone, loc, orient)
  215. {
  216. m_pTransform = NULL;
  217. position3D::setSpeed(0.0f);
  218. updateMatrix();
  219. }
  220. basicPosition::basicPosition(bool shs, int UTM_Zone, C3D_DECART loc, C3D_ORIENT_RAD orient) :
  221. position3D(shs, UTM_Zone, loc, orient)
  222. {
  223. m_pTransform = NULL;
  224. position3D::setSpeed(0.0f);
  225. updateMatrix();
  226. }
  227. basicPosition::basicPosition(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed) :
  228. position3D()
  229. {
  230. m_pTransform = NULL;
  231. position3D::setPositionWGS84(Lat, Lon, Alt);
  232. position3D::setOrientationRad(h_lat, h_lon, h_alt);
  233. position3D::setSpeed(Speed);
  234. updateMatrix();
  235. }
  236. void basicPosition::setPositionRad(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed)
  237. {
  238. position3D::setPositionWGS84(Lat, Lon, Alt);
  239. position3D::setOrientationRad(h_lat, h_lon, h_alt);
  240. position3D::setSpeed(Speed);
  241. updateMatrix();
  242. }
  243. void basicPosition::setPositionDeg(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed)
  244. {
  245. position3D::setPositionWGS84(Lat, Lon, Alt);
  246. position3D::setOrientationDeg(h_lat, h_lon, h_alt);
  247. position3D::setSpeed(Speed);
  248. updateMatrix();
  249. }
  250. void basicPosition::updateMatrix(void)
  251. {
  252. /// @todo Valgrind is showing several memory leaks from this function.
  253. // Tait-Bryan angles
  254. // X1Y2Z3
  255. // C2C3 -C2S3 S2
  256. // C1S3+C3S1S2 C1C3-S1S2S3 -C2S1
  257. // S1S3-C1C3S2 C3S1+C1S2S3 C1C2
  258. if (m_pTransform != NULL)
  259. {
  260. delete(m_pTransform);
  261. m_pTransform = NULL;
  262. };
  263. m_pTransform = new transform_3(x, y, z, rot_x, rot_y, rot_z);
  264. /*
  265. float X, Z, Y;
  266. X = rot_x;
  267. Y = rot_y;
  268. Z = rot_z;
  269. //m_sMatrix.AA = cosf(Y)*cosf(P) - sinf(P)*cosf(R)*sinf(Y);
  270. //m_sMatrix.AB = -cosf(P)*sinf(Y) - sinf(P)*cosf(R)*cosf(Y);
  271. //m_sMatrix.AC = sinf(P)*sinf(R);
  272. m_sMatrix.AA = cosf(Y)*cosf(Z);
  273. m_sMatrix.AB = -sinf(Z);
  274. m_sMatrix.AC = sinf(Y);
  275. m_sMatrix.AD = x;
  276. //m_sMatrix.BA = sinf(P)*cosf(Y) + cosf(P)*cosf(R)*sinf(Y);
  277. //m_sMatrix.BB = -sinf(P)*sinf(Y) + cosf(P)*cosf(R)*cosf(Y);
  278. //m_sMatrix.BC = -cosf(P)*sinf(R);
  279. m_sMatrix.BA = sinf(Z);
  280. m_sMatrix.BB = cosf(Z)*cosf(X);
  281. m_sMatrix.BC = -sinf(X);
  282. m_sMatrix.BD = y;
  283. //m_sMatrix.CA = sinf(R)*sinf(Y);
  284. //m_sMatrix.CB = sinf(R)*cosf(Y);
  285. //m_sMatrix.CC = cosf(R);
  286. m_sMatrix.CA = -sinf(Y);
  287. m_sMatrix.CB = sinf(X);
  288. m_sMatrix.CC = cosf(X)*cosf(Y);
  289. m_sMatrix.CD = z;
  290. m_sMatrix.DA = -x;
  291. m_sMatrix.DB = -y;
  292. m_sMatrix.DC = -z;
  293. m_sMatrix.DD = 1.f;
  294. */
  295. }
  296. /*
  297. void basicPosition::convertLocalXYZ( C3D_DECART POS, C3D_SPH_DEGREES& LO� ){
  298. float T = (POS.x*POS.x)+(POS.y*POS.y);
  299. LOC.r = sqrtf(T+(POS.z*POS.z));
  300. if( POS.x > 0 ) {
  301. LOC.fi = 1 / tanf( POS.y / POS.x );
  302. } else LOC.fi = 0;
  303. if( POS.z > 0 ) {
  304. LOC.teta = 1 / tanf( sqrtf( T ) / POS.z );
  305. } else LOC.teta = 0;
  306. LOC = rad2deg( TT );
  307. };
  308. void basicPosition::convertLocalXYZ( C3D_DECART POS, C3D_SPH_RADIANS& LO� ){
  309. float T = (POS.x*POS.x)+(POS.y*POS.y);
  310. LOC.r = sqrtf(T+(POS.z*POS.z));
  311. if( POS.x > 0 ) {
  312. LOC.fi = 1 / tanf( POS.y / POS.x );
  313. } else LOC.fi = 0;
  314. if( POS.z > 0 ) {
  315. LOC.teta = 1 / tanf( sqrtf( T ) / POS.z );
  316. } else LOC.teta = 0;
  317. };
  318. */
  319. // Destructor implementation
  320. basicPosition::~basicPosition()
  321. {
  322. if (m_pTransform != NULL)
  323. {
  324. delete(m_pTransform);
  325. m_pTransform = NULL;
  326. };
  327. }