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.

299 lines
7.4 KiB

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