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.

247 lines
6.2 KiB

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_SPH_DEGREES 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. };
  21. position3D::position3D( C3D_WGS84_LOC loc, C3D_SPH_RADIANS orient ){
  22. coordConverter CC;
  23. lat = loc.lat;
  24. lon = loc.lon;
  25. z = loc.alt;
  26. #ifdef FLOAT_64
  27. double A, B;
  28. CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
  29. x = A;
  30. y = B;
  31. #else
  32. CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
  33. #endif
  34. rot_x = orient.r;
  35. rot_y = orient.fi;
  36. rot_z = orient.tetta;
  37. };
  38. position3D::position3D( int UTM_Zone, C3D_DECART loc, C3D_SPH_DEGREES orient ){
  39. coordConverter CC;
  40. utmZone = UTM_Zone;
  41. x = loc.x;
  42. y = loc.y;
  43. z = loc.z;
  44. #ifdef FLOAT_64
  45. double A, B;
  46. CC.UTMXYToLatLon(x, y, utmZone, A, B);
  47. lat = A;
  48. lon = B;
  49. #else
  50. CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
  51. #endif
  52. rot_x = deg2rad(orient.r);
  53. rot_y = deg2rad(orient.fi);
  54. rot_z = deg2rad(orient.tetta);
  55. };
  56. position3D::position3D( int UTM_Zone, C3D_DECART loc, C3D_SPH_RADIANS orient ){
  57. coordConverter CC;
  58. utmZone = UTM_Zone;
  59. x = loc.x;
  60. y = loc.y;
  61. z = loc.z;
  62. #ifdef FLOAT_64
  63. double A, B;
  64. CC.UTMXYToLatLon(x, y, utmZone, A, B);
  65. lat = A;
  66. lon = B;
  67. #else
  68. CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
  69. #endif
  70. };
  71. position3D::~position3D() {
  72. };
  73. void position3D::setPositionWGS84(C3D_FLOAT Lat, C3D_FLOAT Lon, C3D_FLOAT Alt) {
  74. coordConverter CC;
  75. lat = Lat;
  76. lon = Lon;
  77. z = Alt;
  78. #ifdef FLOAT_64
  79. double A, B;
  80. CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
  81. x = A;
  82. y = B;
  83. #else
  84. CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
  85. #endif
  86. };
  87. void position3D::setPositionXYZ(C3D_FLOAT X, C3D_FLOAT Y, C3D_FLOAT Z, int zone) {
  88. coordConverter CC;
  89. if (zone != 0) utmZone = zone;
  90. x = X;
  91. y = Y;
  92. z = Z;
  93. #ifdef FLOAT_64
  94. double A, B;
  95. CC.UTMXYToLatLon(x, y, utmZone, false, A, B);
  96. lat = A;
  97. lon = B;
  98. #else
  99. CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
  100. #endif
  101. };
  102. C3D_WGS84_LOC position3D::getWGS84( void ){
  103. C3D_WGS84_LOC retVal;
  104. retVal.lat = lat;
  105. retVal.lon = lon;
  106. retVal.alt = z;
  107. return retVal;
  108. };
  109. C3D_DECART position3D::getXYZ( void ){
  110. C3D_DECART retVal;
  111. retVal.x = x;
  112. retVal.y = y;
  113. retVal.z = z;
  114. return retVal;
  115. };
  116. void position3D::setOrientationRad(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ) {
  117. rot_x = RotX;
  118. rot_y = RotY;
  119. rot_z = RotZ;
  120. };
  121. void position3D::setOrientationDeg(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ) {
  122. rot_x = deg2rad(RotX);
  123. rot_y = deg2rad(RotY);
  124. rot_z = deg2rad(RotZ);
  125. };
  126. void position3D::setSpeed(C3D_FLOAT Speed) {
  127. speed = Speed;
  128. };
  129. // Constructor implementation
  130. basicPosition::basicPosition(): position3D() {
  131. m_pTransform = NULL;
  132. updateMatrix();
  133. };
  134. basicPosition::basicPosition(const basicPosition& src){
  135. memcpy(this, &src, sizeof(basicPosition));
  136. updateMatrix();
  137. };
  138. basicPosition& basicPosition::operator=(const basicPosition& src){
  139. if( this == &src ){
  140. return *this;
  141. };
  142. memcpy(this, &src, sizeof(basicPosition));
  143. updateMatrix();
  144. return *this;
  145. };
  146. basicPosition::basicPosition( C3D_WGS84_LOC loc, C3D_SPH_DEGREES orient ): position3D( loc, orient ){
  147. position3D::setSpeed( 0.0f );
  148. updateMatrix();
  149. };
  150. basicPosition::basicPosition( C3D_WGS84_LOC loc, C3D_SPH_RADIANS orient ): position3D( loc, orient ){
  151. position3D::setSpeed( 0.0f );
  152. updateMatrix();
  153. };
  154. basicPosition::basicPosition( int UTM_Zone, C3D_DECART loc, C3D_SPH_DEGREES orient ): position3D( UTM_Zone, loc, orient ){
  155. position3D::setSpeed( 0.0f );
  156. updateMatrix();
  157. };
  158. basicPosition::basicPosition( int UTM_Zone, C3D_DECART loc, C3D_SPH_RADIANS orient ): position3D( UTM_Zone, loc, orient ){
  159. position3D::setSpeed( 0.0f );
  160. updateMatrix();
  161. };
  162. basicPosition::basicPosition( float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed ) : position3D() {
  163. position3D::setPositionWGS84( Lat, Lon, Alt );
  164. position3D::setOrientationRad( h_lat, h_lon, h_alt );
  165. position3D::setSpeed( Speed );
  166. updateMatrix();
  167. };
  168. void basicPosition::setPositionRad(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed ){
  169. position3D::setPositionWGS84(Lat, Lon, Alt);
  170. position3D::setOrientationRad(h_lat, h_lon, h_alt);
  171. position3D::setSpeed(Speed);
  172. updateMatrix();
  173. };
  174. void basicPosition::setPositionDeg(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed){
  175. position3D::setPositionWGS84(Lat, Lon, Alt);
  176. position3D::setOrientationDeg(h_lat, h_lon, h_alt);
  177. position3D::setSpeed(Speed);
  178. updateMatrix();
  179. };
  180. void basicPosition::updateMatrix( void ){
  181. //Tait-Bryan angles
  182. //X1Y2Z3
  183. // C2C3 -C2S3 S2
  184. // C1S3+C3S1S2 C1C3-S1S2S3 -C2S1
  185. // S1S3-C1C3S2 C3S1+C1S2S3 C1C2
  186. if( m_pTransform != NULL ){
  187. delete( m_pTransform );
  188. m_pTransform = NULL;
  189. };
  190. m_pTransform = new transform_3( x, y, z, rot_x, rot_y, rot_z );
  191. /*
  192. float X, Z, Y;
  193. X = rot_x;
  194. Y = rot_y;
  195. Z = rot_z;
  196. //m_sMatrix.AA = cosf(Y)*cosf(P) - sinf(P)*cosf(R)*sinf(Y);
  197. //m_sMatrix.AB = -cosf(P)*sinf(Y) - sinf(P)*cosf(R)*cosf(Y);
  198. //m_sMatrix.AC = sinf(P)*sinf(R);
  199. m_sMatrix.AA = cosf(Y)*cosf(Z);
  200. m_sMatrix.AB = -sinf(Z);
  201. m_sMatrix.AC = sinf(Y);
  202. m_sMatrix.AD = x;
  203. //m_sMatrix.BA = sinf(P)*cosf(Y) + cosf(P)*cosf(R)*sinf(Y);
  204. //m_sMatrix.BB = -sinf(P)*sinf(Y) + cosf(P)*cosf(R)*cosf(Y);
  205. //m_sMatrix.BC = -cosf(P)*sinf(R);
  206. m_sMatrix.BA = sinf(Z);
  207. m_sMatrix.BB = cosf(Z)*cosf(X);
  208. m_sMatrix.BC = -sinf(X);
  209. m_sMatrix.BD = y;
  210. //m_sMatrix.CA = sinf(R)*sinf(Y);
  211. //m_sMatrix.CB = sinf(R)*cosf(Y);
  212. //m_sMatrix.CC = cosf(R);
  213. m_sMatrix.CA = -sinf(Y);
  214. m_sMatrix.CB = sinf(X);
  215. m_sMatrix.CC = cosf(X)*cosf(Y);
  216. m_sMatrix.CD = z;
  217. m_sMatrix.DA = -x;
  218. m_sMatrix.DB = -y;
  219. m_sMatrix.DC = -z;
  220. m_sMatrix.DD = 1.f;
  221. */
  222. };
  223. // Destructor implementation
  224. basicPosition::~basicPosition(){
  225. };