Set the motion transform id in the collection step.
[flightgear.git] / tests / test-up.cxx
blob85811423cd99e6b493200d52f8ce326a4efd80c3
1 // do some test relating to the concept of "up"
3 #ifdef HAVE_CONFIG_H
4 # include <config.h>
5 #endif
7 #include <simgear/compiler.h>
9 #include <iostream>
11 #include <plib/sg.h>
13 #include <simgear/constants.h>
14 #include <simgear/math/sg_geodesy.hxx>
16 using std::cout;
17 using std::endl;
19 int main() {
20 // for each lat/lon given in goedetic coordinates, calculate
21 // geocentric coordinates, cartesian coordinates, the local "up"
22 // vector (based on original geodetic lat/lon), as well as the "Z"
23 // intercept (for which 0 = center of earth)
26 double lon = 0;
27 double alt = 0;
29 for ( double lat = 0; lat <= 90; lat += 5.0 ) {
30 cout << "lon = " << lon << " geod lat = " << lat;
32 double sl_radius, lat_geoc;
33 sgGeodToGeoc( lat * SGD_DEGREES_TO_RADIANS, alt, &sl_radius, &lat_geoc );
34 cout << " geoc lat = " << lat_geoc * SGD_RADIANS_TO_DEGREES << endl;
36 Point3D pgd( lon * SGD_DEGREES_TO_RADIANS, lat * SGD_DEGREES_TO_RADIANS, 0.0 );
37 Point3D pc = sgGeodToCart( pgd );
38 cout << " cartesian = " << pc << endl;
40 sgdMat4 GEOD_UP;
41 sgdVec3 geod_up;
42 sgdMakeRotMat4( GEOD_UP, lon, 0.0, -lat );
43 sgdSetVec3( geod_up, GEOD_UP[0][0], GEOD_UP[0][1], GEOD_UP[0][2] );
44 cout << " geod up = " << geod_up[0] << ", " << geod_up[1] << ", "
45 << geod_up[2] << endl;
47 sgdMat4 GEOC_UP;
48 sgdVec3 geoc_up;
49 sgdMakeRotMat4( GEOC_UP, lon, 0.0, -lat_geoc * SGD_RADIANS_TO_DEGREES );
50 sgdSetVec3( geoc_up, GEOC_UP[0][0], GEOC_UP[0][1], GEOC_UP[0][2] );
51 cout << " geoc up = " << geoc_up[0] << ", " << geoc_up[1] << ", "
52 << geoc_up[2] << endl;
54 double slope = geod_up[2] / geod_up[0];
55 double intercept = pc.z() - slope * pc.x();
56 cout << " Z intercept (based on geodetic up) = " << intercept << endl;
58 slope = geoc_up[2] / geoc_up[0];
59 intercept = pc.z() - slope * pc.x();
60 cout << " Z intercept (based on geocentric up) = " << intercept << endl;
64 return 0;