CesiumSunSky - jgoffeney/Cesium4Unreal GitHub Wiki

Back

Description

The CesiumSunSky is an Unreal Actor is that adds a Sun as a directional light and it is geospatially aware. In the C++ class the variables and functions are currently protected so to adjust them in code you will need to create a subclass and create your own public accessor functions.

Setting Sun Light

UpdateSun

The CesiumSunSky::UpdateSun() function is required whenever you update any of the class's properties to actually update the sun's position.

TimeZone

Setting the time zone moves the sun to the corresponding longitude. In the editor the acceptable value ranges from -12 to 14. The function below computes the time zone for a given longitude.

int timeZone = (int)floor((targetLongitudeDegrees + 7.5) / 15.0);

As mentioned above the time zone variable is protected in the class therefore you need to create a subclass to access it from code.

  • 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();

Direction

The sun by default points at the Unreal origin based on the CesiumGeoreference. Therefore you can use the SetGeoreferenceOrigin method to reset the Unreal origin to the current geospatial position. Note this is done without requiring the UpdateSun() method.

geoReference->SetGeoreferenceOrigin(targetGeoPoint);