Thanks for the reply.
I am still having problems with the conversion from a local coordinate system to Geocentric. To recap what I have done so far:
• I converted from Geodetic to Geocentric coordinates
• I calculated the axis and angle to perform the rotation (ENU to Geocentric)
• I altered the existing scene graph by adding a new group node just under the header record and attached the rest of the scene graph to this new group node. Then I added the translation and rotation transformations to this new group node.
• I changed the Projection Type of the header record to Geocentric
The translation seems to work fine. The object in the flt file is appearing at the correct location. The problem is that the object seems to be rotated wrong. To troubleshoot, I created a separate file that had no rotation so it just used the identity matrix. The interesting this was that the object appeared exactly the same as when I had a rotation added. Since I cannot change the rotation, this makes me think that I am altering the scene graph incorrectly. I am attaching the code below. Can you (or anyone) tell me if there is something I am doing wrong? I appreciate the help.
struct Point
{
double x;
double y;
double z;
};
//Converts from geodetic to geocentric (lat,lon in radians)
Point GeodeticToGeocentric( double latitude, double longitude, double height )
{
Point result;
double semiMajorAxis = 6378137.0;
double flattening = 1 / 298.257223563;
double Geocent_e2 = 2 * flattening - flattening * flattening;
double Sin_Lat = sin(latitude);
double Cos_Lat = cos(latitude);
double Sin2_Lat = Sin_Lat * Sin_Lat;
double Rn = semiMajorAxis / (sqrt(1 - Geocent_e2 * Sin2_Lat));
result.x = (Rn + height) * Cos_Lat * cos(longitude);
result.y = (Rn + height) * Cos_Lat * sin(longitude);
result.z = ((Rn * (1 - Geocent_e2)) + height) * Sin_Lat;
return result;
}
void Transform (mgrec *node,Point translate,Matrix3x3* m,Vector3* axis, Float angle )
{
//Alter the scene graph to add a new group node just below the header record and the
//rest of the graph attached to this new group node
mgrec* g1 = mgGetChild(node);
mgrec* wt1frame = mgGetNext(g1);
mgrec* Dimensions10 = mgGetNext(wt1frame);
mgDetach(g1);
mgDetach(wt1frame);
mgDetach(Dimensions10);
mgrec* newNode = mgNewRec(fltGroup);
mgAttach(node,newNode);
mgAttach(newNode,g1);
mgAppend(newNode,wt1frame);
mgAppend(newNode,Dimensions10);
//Set Header - change projection type to Geocentric
mgSetAttList(node,fltProjection,6,MG_NULL);
//get the newly created group node
node = mgGetChild(node);
//Add the following transformations to this new group node
//Translate
mgrec* xformTranslate = mgNewRec(fltXmTranslate);
mgSetCoord3d(xformTranslate,fltXmTranslateFrom,0,0,0);
mgSetCoord3d(xformTranslate,fltXmTranslateDelta,translate.x,translate.y,translate.z);
mgAttach(node,xformTranslate);
//Rotate
mgrec* xformRotate = mgNewRec (fltXmRotate);
mgSetCoord3d (xformRotate, fltXmRotateCenter, 0, 0, 0);
mgSetAttList (xformRotate, fltXmRotateAngle, angle, mgNULL);
mgrec* nestedAttrib = mgGetAttRec(xformRotate,fltXmRotateAxis,MG_NULL);
mgSetAttList (nestedAttrib,
fltVectorI, axis->x,
fltVectorJ, axis->y,
fltVectorK, axis->z,
mgNULL);
mgAppend (node, xformRotate);
}
int main(int argc, char* argv[])
{
//lat
float u = 32*PI/180;
//lon
float i = -126*PI/180;
Matrix3x3* m = new Matrix3x3();
//ENU
m->row[0].set(-sin(i),cos(i),0);
m->row[1].set(-sin(u)*cos(i),-sin(u)*sin(i),cos(u));
m->row[2].set(cos(u)*cos(i),cos(u)*sin(i),sin(u));
Quat* q = new Quat((Matrix3x3*) m);
//look at w,v
Vector3* axis = new Vector3();
Float angle = 0;
m->getAxisAngle(axis,angle);
Point result;
mgrec* db;
char idname[80];
char *id = idname;
mgInit(&argc;, argv);
if (!(db = mgOpenDb(argv[1])))
{
printf("\nError in mgOpenDb(%s)\n", argv[1]);
exit(1);
}
result = GeodeticToGeocentric(u,i,0);
cout<<"Calculated coordinates (x,y,z): " << result.x << "," << result.y << "," << result.z << endl;
Transform(db,result,m,axis,angle);
mgWriteDb (db);
mgCloseDb (db);
mgExit();
return 0;
}