Am I setting CesiumGeorference properly at runtime in C++?

Hi all…
This may be my lack of fully understanding working with Cesium for Unreal and so I have a couple questions.

I have an Unreal cesium map. I have cesium and all that setup and it opens up at a football field in the suburbs of Denver Co…

I have mesh actor that I need to manipulate in the world that is set to 0,0,0. It sits right there on top of the cesium reference in the scene.

At runtime, I load up a file that has a new world coordinate in it. It will have longitude, latitude, and altitude. For this example, lets say I want to load a file that is at the Sydney Opera House (just a random location, I wanted something FAR away from the original location of Denver Colorado to test orientation on the other side of the globe.)

Internet search tells me that the Sydney Opera House is at
LONG: 151.215256
LAT: -33.856159
ALT : 13

At runtime, in C++ I am calling this function with the coordinates from the file, the values have already been converted to numerical data.

CesiumGeoreference->SetGeoreferenceOriginLongitudeLatitudeHeight( FVector( cesiumLng, cesiumLat, cesiumAlt ) );

What I’ve noticed is that when this starts, I always start at the proper long/lat, but my altitude is always under the cesium map/tile. I had to set the altitude all the way up to 26.5 in order for it to look like it’s sitting at ground level when it starts.

So, my question is, am I using the wrong function to set the cesium geo reference to this new location? And if so, what is a better, more accurate option and code base?

Thanks!
Rick

EDIT

This actually has me wondering something… The values that I get out of this file are in meters. What is Cesium working with? Is the altitude value in Unreal units or something else?

The Cesium height value is a height above the WGS84 ellipsoid. An altitude is usually a height above mean sea level (where the exact definition of mean sea level can vary). Because mean sea level is not a nice mathmetical surface, the difference between it and the WGS84 ellipsoid varies over the globe. It is usually on the order of tens of meters.

You can compute the difference between the ellipsoid and (some approximation of) mean sea level by using a geoid model. EGM96 and EGM2008 are popular choices. Here’s an online calculator for those:

The calculator indicates that, at your coordinates for the Syney Opera House, the geoid is above 22 meters above the ellipsoid. So if you set the georeference to 22+13=35 meters, it should be pretty close to ground level at that point.

Hi Kevin…

Thanks for the reply. Does Cesium by chance have this library built in and provide a function call that we can use? Or will we need to pre calculate this value prior to runtime for any new location that we might want to set as our origin point?

We don’t have that computation built in currently. But I imagine you can easily find some C++ code that can do it. I found this with a quick google:

I know nothing about it, but it looks promising.

Thanks Kevin…
I downloaded it, built a little exe. Very straight forward. I did run into two small issues… When compiling I got an error for an unknown symbol, M_PI… For some reason it was not defined, but needed it in the C code. So at the top of the EGM96.C file, I added a #define M_PI 3.14… defintion.

Second, when including the EGM96.H header into my AltitudeCalc.CPP (main app file) I had to wrap that include in an extern C… So it looked like this.

extern “C” {
#include EGM96.H
}

After that, it compiled with ease. Only one function to deal with… One thing to note… VS 2017 was complaining when I put that extern “C” statement all on one line. Got compile errors for some. So, I had to ensure that it was on separate lines as shown.