We help IT Professionals succeed at work.

OpenGL - Convert Latitude Longitude and Altitude to x,y,z

dslamb
dslamb used Ask the Experts™
on
I've seen a number of examples converting Latitude and Longitude into an OpenGL coordinate system.  For example, this one is particularly useful.  However, I haven't found relevant examples that include elevation/altitude.  I was hoping someone might provide me with an example.

The original lat, long, and altitude will be in the WGS 84 ellipsoid, and OpenGL will be using the right-hand Y-Up coordinate system.  Basically, I'm looking at using OpenGL to render models from Google's 3D warehouse that are associated with Google Earth.  These come as collada files with a Z-Up orientation.

Thanks for any help.

Regards,
David
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
wouldn't altitude be the same value as z?  It's only a matter of units translation (feet vs meters, for instance) unless I've completely misunderstood your question.

Author

Commented:
Typically, in z-up alititude is z.  But if my understanding is correct openGL is y-up, so I need to convert latitude longitude and altitude from spherical coordinates to cartesia and swap those around.
Top Expert 2014

Commented:

Author

Commented:
That's an ESRI ArcGlobe specific tool that uses a function GeographictoGeocentric conversion.  Do you know what the conversion does?
Top Expert 2014

Commented:
>>Do you know what the conversion does?
No.
In OpenGL (or Direct X) whether Y is up or not depends on the transforms involved.  There is nothing to fix OpenGL with y being up.  I think the functions default to creating the matrices you describe, no reason you have to use those functions or leave the matrices in the default orientation.

If you normalise the vector returned from your longtitude and latitude calculations, scale it to the altitude you want and add that to the original vector, that should give you the answer you want.  Or I am missing something?

I guess the conversion you mention will be using long and lat as angles and calculating the vector with sine and cosine.  The math should be straighforward.

Author

Commented:
I think this is the closest to what I found as well.