CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
902 stars 287 forks source link

CesiumFlyToComponent "jumps" at the end due to spherical math that doesn't quite work on an ellipsoid #1332

Closed kring closed 7 months ago

kring commented 7 months ago

Here's a diagram to try to illustrate the problem:

image

The blue oval is a highly exaggerated ellipsoidal model of the Earth. To do a flight between the start and end points marked, CesiumFlyToComponent first computes a rotation axis and angle between those two points. At each step, it interpolates the angle and rotates the initial direction by that angle to produce the direction of the path at this step. It then scales this direction to the ellipsoid surface and adds a separately-computed height to it to get the actual position for the flight.

The problem, as shown in the diagram, is that scaling the final direction to the ellipsoid and then adding the final position's height does not actually result in the final position. It would on a sphere, but not on an ellipsoid. It's our old friend geocentric versus geodetic angles.

As a result, flights often appear to jump to a new position just as they complete, because the final position along the curve is quite different from the real final position. This can be seen quite obviously by opening the Google Photorealistic 3D Tiles level in Cesium for Unreal Samples, hitting Play-In-Editor, pressing 3 to fly to Tokyo, then moving the camera a good distance up and away from Tokyo before pressing 3 to fly toward it again. When the intial position of the camera is fairly high, the jump at the end should be very obvious.

It's probably easy to fix this, but I'm not sure it's worth the trouble. I'm inclined to just port the camera flight code from CesiumJS rather than trying to fix this approach.

csciguy8 commented 7 months ago

Nice catch and explanation.

A little surprised that I didn't see this when testing cesium-unreal-samples, 04_MAIN_CesiumSublevels. The symptom may only be noticeable in certain areas of the globe though.

I suspect the calculation of _sourceDirectionand _totalAngleneed to be modified to take into account start / end height offsets. https://github.com/CesiumGS/cesium-unreal/blob/1107e6fc747cd4a275fce4664a25b1f3f1285c2d/Source/CesiumRuntime/Private/CesiumFlyToComponent.cpp#L83