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.

362 lines
7.6 KiB

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