Ok so I have inserted a new group node into my scene graph just under the header. I added two transform nodes to this new group node: fltXmTranslate and fltXmRotate. Do I need to change the Projection Type from Flat Earth to Geocentric on the header record? Are there any other 'gotchas' that I should consider? Thanks in advance.
I had a problem with my rotation matrix. I was using NED instead of ENU. Thanks
Focusing first on your Transform function... the code there looks reasonable. I copied snippets from it and verified it was working correctly in Creator 4.2.
Have you tried to load the file and debug the values in the rotation xform to make sure they are correct on re-read?
Obvious, but have to make sure... The fltXmRotate angle is degrees, not radians.
The interesting this was that the object appeared exactly the same as when I had a rotation added.
Are you looking at it in Creator or some other viz app?
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.
//Converts from geodetic to geocentric (lat,lon in radians)
Point GeodeticToGeocentric( double latitude, double longitude, double height )
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;
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);
mgrec* newNode = mgNewRec(fltGroup);
//Set Header - change projection type to Geocentric
//get the newly created group node
node = mgGetChild(node);
//Add the following transformations to this new group node
mgrec* xformTranslate = mgNewRec(fltXmTranslate);
mgrec* xformRotate = mgNewRec (fltXmRotate);
mgSetCoord3d (xformRotate, fltXmRotateCenter, 0, 0, 0);
mgSetAttList (xformRotate, fltXmRotateAngle, angle, mgNULL);
mgrec* nestedAttrib = mgGetAttRec(xformRotate,fltXmRotateAxis,MG_NULL);
mgAppend (node, xformRotate);
int main(int argc, char* argv)
float u = 32*PI/180;
float i = -126*PI/180;
Matrix3x3* m = new Matrix3x3();
Quat* q = new Quat((Matrix3x3*) m);
//look at w,v
Vector3* axis = new Vector3();
Float angle = 0;
char *id = idname;
if (!(db = mgOpenDb(argv)))
printf("\nError in mgOpenDb(%s)\n", argv);
result = GeodeticToGeocentric(u,i,0);
cout<<"Calculated coordinates (x,y,z): " << result.x << "," << result.y << "," << result.z << endl;
Thanks for the clarification... makes sense.
You do need to set the fltHeader fltProjection field to specify how to interpret the vertex coordinates.
Sorry I was unclear. What I am trying to do is take a flt file that is in local coordinates and convert it to geocentric coordinates. I attempted to do this by creating a new group node just under the header record and attaching the rest of the scene graph to this new group node. I then add transforms to this new group node so that it is in geocentric coordinates. I was wondering if it was necessary to set the fltProjectionType record to Geocentric now that I have done this. I hope this is a better explanation. thanks
Sorry... it's not clear what you are asking... can you provide more information on what you are trying to do? Thanks