Cesium For Unreal: Transition Between Locations on the Globe - jgoffeney/Cesium4Unreal GitHub Wiki

Back

Transition Between Locations on the Globe

Tutorial for smoothly flying between two locations.

Source

Description

Create A Level

  • Create a default level: Quickstart.
    • It should have a CesiumGeoReference and a DynamicPawn.

CesiumSunSky

The CesiumSunSky object creates a light (the sun) and controls its position via the time zone and time of day. However, at the time of this writing, within C++ the accessor functions / variables are not directly accessible. So you need to create a sub class to expose the variable of interest. Whenever the properties of the CesiumSunSky are changed then follow it by calling its UpdateSun() function.

  • MyCesiumSunSky.h
#pragma once

#include "CoreMinimal.h"
#include "CesiumSunSky.h"
#include "MyCesiumSunSky.generated.h"

/**
 * 
 */
UCLASS()
class CESIUMCPPSTARTER_API AMyCesiumSunSky : public ACesiumSunSky
{
	GENERATED_BODY()

public:
	
	AMyCesiumSunSky();
	
	void SetTimeZone(int timeZone);
};

  • MyCesiumSunSky.cpp
#include "MyCesiumSunSky.h"

AMyCesiumSunSky::AMyCesiumSunSky() {

}

void AMyCesiumSunSky::SetTimeZone(int timeZone) {
	TimeZone = timeZone;
}
  • Updating Time Zone
int timeZone = (int)floor((targetLonDegrees + 7.5) / 15.0);
_sunSky->SetTimeZone(timeZone);
_sunSky->UpdateSun();

FlyingToLocation

The moving between two location is handled by the DynamicPawn object through its FlyToLocationLongitudeLatitudeHeight function. When it is called then the position and angles of the current location and target location are interpoled over a set of intervals which creates the appearance of flying between from one point to another.

  • FlyToLocationLongitudeLatitudeHeight(const glm::dvec3& LongitudeLatitudeHeightDestination, float YawAtDestination, float PitchAtDestination, bool CanInterruptByMoving)
    • LongitudeLatitudeHeightDestination: a vector of the target longitude, latitude and height in degrees and meters
    • YawAtDestination: the target yaw (rotation in the ground plane) in degrees
    • PitchAtDestination: the target pitch (head tilt with respect to ground) in degrees
    • CanInterruptByMoving: set true to allow player movement to halt the automatic movement.