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

#include "basicPosition.h"
#include "string.h"
position3D::position3D() {
x = y = z = lat = lon = rot_z = rot_y = rot_z = speed = 0.f;
utmZone = 0;
};
position3D::position3D( C3D_WGS84_LOC loc, C3D_ORIENT_DEG orient ){
coordConverter CC;
lat = loc.lat;
lon = loc.lon;
z = loc.alt;
#ifdef FLOAT_64
double A, B;
CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
x = A;
y = B;
#else
CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
#endif
rot_x = deg2rad(orient.rot_x);
rot_y = deg2rad(orient.rot_y);
rot_z = deg2rad(orient.rot_z);
};
position3D::position3D( C3D_WGS84_LOC loc, C3D_ORIENT_RAD orient ){
coordConverter CC;
lat = loc.lat;
lon = loc.lon;
z = loc.alt;
#ifdef FLOAT_64
double A, B;
CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
x = A;
y = B;
#else
CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
#endif
rot_x = orient.rot_x;
rot_y = orient.rot_y;
rot_z = orient.rot_z;
};
position3D::position3D( int UTM_Zone, C3D_DECART loc, C3D_ORIENT_DEG orient ){
coordConverter CC;
utmZone = UTM_Zone;
x = loc.x;
y = loc.y;
z = loc.z;
#ifdef FLOAT_64
double A, B;
CC.UTMXYToLatLon(x, y, utmZone, A, B);
lat = A;
lon = B;
#else
CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
#endif
rot_x = deg2rad(orient.rot_x);
rot_y = deg2rad(orient.rot_y);
rot_z = deg2rad(orient.rot_z);
};
position3D::position3D( int UTM_Zone, C3D_DECART loc, C3D_ORIENT_RAD orient ){
coordConverter CC;
utmZone = UTM_Zone;
x = loc.x;
y = loc.y;
z = loc.z;
#ifdef FLOAT_64
double A, B;
CC.UTMXYToLatLon(x, y, utmZone, A, B);
lat = A;
lon = B;
#else
CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
#endif
rot_x = orient.rot_x;
rot_y = orient.rot_y;
rot_z = orient.rot_z;
};
position3D::~position3D() {
};
void position3D::setPositionWGS84(C3D_FLOAT Lat, C3D_FLOAT Lon, C3D_FLOAT Alt) {
coordConverter CC;
lat = Lat;
lon = Lon;
z = Alt;
#ifdef FLOAT_64
double A, B;
CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
x = A;
y = B;
#else
CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
#endif
};
void position3D::setPositionXYZ(C3D_FLOAT X, C3D_FLOAT Y, C3D_FLOAT Z, int zone) {
coordConverter CC;
if (zone != 0) utmZone = zone;
x = X;
y = Y;
z = Z;
#ifdef FLOAT_64
double A, B;
CC.UTMXYToLatLon(x, y, utmZone, false, A, B);
lat = A;
lon = B;
#else
CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
#endif
};
C3D_WGS84_LOC position3D::getWGS84( void ){
C3D_WGS84_LOC retVal;
retVal.lat = lat;
retVal.lon = lon;
retVal.alt = z;
return retVal;
};
C3D_DECART position3D::getXYZ( void ){
C3D_DECART retVal;
retVal.x = x;
retVal.y = y;
retVal.z = z;
return retVal;
};
void position3D::setOrientationRad(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ) {
rot_x = RotX;
rot_y = RotY;
rot_z = RotZ;
};
void position3D::setOrientationDeg(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ) {
rot_x = deg2rad(RotX);
rot_y = deg2rad(RotY);
rot_z = deg2rad(RotZ);
};
void position3D::setSpeed(C3D_FLOAT Speed) {
speed = Speed;
};
// Constructor implementation
basicPosition::basicPosition(): position3D() {
m_pTransform = NULL;
updateMatrix();
};
basicPosition::basicPosition(const basicPosition& src){
memcpy(this, &src, sizeof(basicPosition));
updateMatrix();
};
basicPosition& basicPosition::operator=(const basicPosition& src){
if( this == &src ){
return *this;
};
memcpy(this, &src, sizeof(basicPosition));
updateMatrix();
return *this;
};
basicPosition::basicPosition( C3D_WGS84_LOC loc, C3D_ORIENT_DEG orient ): position3D( loc, orient ){
m_pTransform = NULL;
position3D::setSpeed( 0.0f );
updateMatrix();
};
basicPosition::basicPosition( C3D_WGS84_LOC loc, C3D_ORIENT_RAD orient ): position3D( loc, orient ){
m_pTransform = NULL;
position3D::setSpeed( 0.0f );
updateMatrix();
};
basicPosition::basicPosition( int UTM_Zone, C3D_DECART loc, C3D_ORIENT_DEG orient ): position3D( UTM_Zone, loc, orient ){
m_pTransform = NULL;
position3D::setSpeed( 0.0f );
updateMatrix();
};
basicPosition::basicPosition( int UTM_Zone, C3D_DECART loc, C3D_ORIENT_RAD orient ): position3D( UTM_Zone, loc, orient ){
m_pTransform = NULL;
position3D::setSpeed( 0.0f );
updateMatrix();
};
basicPosition::basicPosition( float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed ) : position3D() {
m_pTransform = NULL;
position3D::setPositionWGS84( Lat, Lon, Alt );
position3D::setOrientationRad( h_lat, h_lon, h_alt );
position3D::setSpeed( Speed );
updateMatrix();
};
void basicPosition::setPositionRad(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed ){
position3D::setPositionWGS84(Lat, Lon, Alt);
position3D::setOrientationRad(h_lat, h_lon, h_alt);
position3D::setSpeed(Speed);
updateMatrix();
};
void basicPosition::setPositionDeg(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed){
position3D::setPositionWGS84(Lat, Lon, Alt);
position3D::setOrientationDeg(h_lat, h_lon, h_alt);
position3D::setSpeed(Speed);
updateMatrix();
};
void basicPosition::updateMatrix( void ){
/// @todo Valgrind is showing several memory leaks from this function.
//Tait-Bryan angles
//X1Y2Z3
// C2C3 -C2S3 S2
// C1S3+C3S1S2 C1C3-S1S2S3 -C2S1
// S1S3-C1C3S2 C3S1+C1S2S3 C1C2
if( m_pTransform != NULL ){
delete( m_pTransform );
m_pTransform = NULL;
};
m_pTransform = new transform_3( x, y, z, rot_x, rot_y, rot_z );
/*
float X, Z, Y;
X = rot_x;
Y = rot_y;
Z = rot_z;
//m_sMatrix.AA = cosf(Y)*cosf(P) - sinf(P)*cosf(R)*sinf(Y);
//m_sMatrix.AB = -cosf(P)*sinf(Y) - sinf(P)*cosf(R)*cosf(Y);
//m_sMatrix.AC = sinf(P)*sinf(R);
m_sMatrix.AA = cosf(Y)*cosf(Z);
m_sMatrix.AB = -sinf(Z);
m_sMatrix.AC = sinf(Y);
m_sMatrix.AD = x;
//m_sMatrix.BA = sinf(P)*cosf(Y) + cosf(P)*cosf(R)*sinf(Y);
//m_sMatrix.BB = -sinf(P)*sinf(Y) + cosf(P)*cosf(R)*cosf(Y);
//m_sMatrix.BC = -cosf(P)*sinf(R);
m_sMatrix.BA = sinf(Z);
m_sMatrix.BB = cosf(Z)*cosf(X);
m_sMatrix.BC = -sinf(X);
m_sMatrix.BD = y;
//m_sMatrix.CA = sinf(R)*sinf(Y);
//m_sMatrix.CB = sinf(R)*cosf(Y);
//m_sMatrix.CC = cosf(R);
m_sMatrix.CA = -sinf(Y);
m_sMatrix.CB = sinf(X);
m_sMatrix.CC = cosf(X)*cosf(Y);
m_sMatrix.CD = z;
m_sMatrix.DA = -x;
m_sMatrix.DB = -y;
m_sMatrix.DC = -z;
m_sMatrix.DD = 1.f;
*/
};
/*
void basicPosition::convertLocalXYZ( C3D_DECART POS, C3D_SPH_DEGREES& LOÑ ){
float T = (POS.x*POS.x)+(POS.y*POS.y);
LOC.r = sqrtf(T+(POS.z*POS.z));
if( POS.x > 0 ) {
LOC.fi = 1 / tanf( POS.y / POS.x );
} else LOC.fi = 0;
if( POS.z > 0 ) {
LOC.teta = 1 / tanf( sqrtf( T ) / POS.z );
} else LOC.teta = 0;
LOC = rad2deg( TT );
};
void basicPosition::convertLocalXYZ( C3D_DECART POS, C3D_SPH_RADIANS& LOÑ ){
float T = (POS.x*POS.x)+(POS.y*POS.y);
LOC.r = sqrtf(T+(POS.z*POS.z));
if( POS.x > 0 ) {
LOC.fi = 1 / tanf( POS.y / POS.x );
} else LOC.fi = 0;
if( POS.z > 0 ) {
LOC.teta = 1 / tanf( sqrtf( T ) / POS.z );
} else LOC.teta = 0;
};
*/
// Destructor implementation
basicPosition::~basicPosition(){
if( m_pTransform != NULL ){
delete( m_pTransform );
m_pTransform = NULL;
};
};