I have a function to convert from Longitude, Laitude and Height and when I call it with same latitude and longitude but different height is giving me differente values in all the coordinates, is this correct?
This is my function:
Note there is an adjustment if the height that is coming is below the Y value of the 3DTileSet return the value of the map Y.
private Vector3 GetUnityPosition(double latitude, double longitude, double altitude)
{
var height = GeoidHeights.undulation(latitude, longitude);
var pos = new double3(longitude, latitude, height + altitude);
Debug.Log($" GetUnityPosition: Position {pos}");
var ecef = CesiumWgs84Ellipsoid.LongitudeLatitudeHeightToEarthCenteredEarthFixed(pos);
Debug.Log($" GetUnityPosition: ECEF {ecef}");
var unityPosition = CesiumComponent.GetComponent<CesiumGeoreference>().TransformEarthCenteredEarthFixedPositionToUnity(ecef);
Debug.Log($" GetUnityPosition: UnityPosition {unityPosition}");
var position = new Vector3((float)unityPosition.x, (float)unityPosition.y, (float)unityPosition.z);
var mapPosition = GetMapPosition(position);
if (position.y > (float)mapPosition.Item2.y)
{
return position;
}
else
{
var newUnityPosition = new Vector3(position.x, (float)mapPosition.Item2.y, position.z);
Debug.Log($" GetUnityPosition: NewUnityPosition {newUnityPosition}");
return newUnityPosition;
}
}
These are the logs for two calls with simiar longitude and altitude
GetUnityPosition: Position double3(-96.7676162719727, 32.8526954650879, 503.441769652035)
GetUnityPosition: ECEF double3(-632082.156804792, -5326404.26096664, 3440519.35399537)
GetUnityPosition: UnityPosition double3(24536.5783976775, 451.38818237558, 7897.70696547861)
GetUnityPosition: NewUnityPosition (24536.58, 451.39, 7897.71)
GetUnityPosition: Position double3(-96.7676162719727, 32.8526954650879, 903.441769652035)
GetUnityPosition: ECEF double3(-632121.755166528, -5326737.94683391, 3440736.34641859)
GetUnityPosition: UnityPosition double3(24538.1155527714, 851.384919896722, 7898.2040837938)
GetUnityPosition: NewUnityPosition (24538.12, 851.38, 7898.20)
Thanks!
Fernando