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.

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