Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UpdateTimeZoneFromLongitude to ACesiumSunSky #1590

Merged
merged 5 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
##### Additions :tada:

- Added `CesiumUrlTemplateRasterOverlay`, allowing a raster overlay to be added using tiles requested based on a specified URL template.
- Added `UpdateTimeZoneFromLongitude` method to `ACesiumSunSky` to naively update the `ACesiumSunSky`'s `TimeZone` property based on a given longitude.
azrogers marked this conversation as resolved.
Show resolved Hide resolved
- The "Place Georeference Origin Here" button on `ACesiumGeoreference` will now update the time zone of any `ACesiumSunSky` instances using that georeference based on the new origin's longitude.
azrogers marked this conversation as resolved.
Show resolved Hide resolved

##### Fixes :wrench:

Expand Down
18 changes: 18 additions & 0 deletions Source/CesiumRuntime/Private/CesiumGeoreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include "CesiumCommon.h"
#include "CesiumCustomVersion.h"
#include "CesiumGeospatial/Cartographic.h"
#include "CesiumGlobeAnchorComponent.h"
#include "CesiumOriginShiftComponent.h"
#include "CesiumRuntime.h"
#include "CesiumSubLevelComponent.h"
#include "CesiumSubLevelSwitcherComponent.h"
#include "CesiumSunSky.h"
#include "CesiumTransforms.h"
#include "CesiumUtility/Math.h"
#include "Engine/LevelStreaming.h"
Expand Down Expand Up @@ -426,6 +428,22 @@ void ACesiumGeoreference::PlaceGeoreferenceOriginHere() {
.Rotator());
pEditorViewportClient->SetViewLocation(
this->GetActorTransform().TransformPosition(FVector::ZeroVector));

const double NewLongitude = this->GetOriginLongitude();

// Find all CesiumSunSky instances using this georeference and update their
// time zones based on the new origin.
azrogers marked this conversation as resolved.
Show resolved Hide resolved
for (TActorIterator<ACesiumSunSky> It(pWorld); It; ++It) {
if (!IsValid(It->GlobeAnchor)) {
continue;
}

ACesiumGeoreference* ResolvedGeoreference =
It->GlobeAnchor->GetResolvedGeoreference();
if (IsValid(ResolvedGeoreference) && ResolvedGeoreference == this) {
It->UpdateTimeZoneFromLongitude(NewLongitude);
}
}
}

void ACesiumGeoreference::CreateSubLevelHere() {
Expand Down
5 changes: 5 additions & 0 deletions Source/CesiumRuntime/Private/CesiumSunSky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ void ACesiumSunSky::UpdateAtmosphereRadius() {
}
}

void ACesiumSunSky::UpdateTimeZoneFromLongitude(double InLongitude) {
this->TimeZone = FMath::Clamp(InLongitude, -180.0, 180.0) / 15.0;
this->UpdateSun();
}

void ACesiumSunSky::GetHMSFromSolarTime(
double InSolarTime,
int32& Hour,
Expand Down
15 changes: 15 additions & 0 deletions Source/CesiumRuntime/Public/CesiumSunSky.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,21 @@ class CESIUMRUNTIME_API ACesiumSunSky : public AActor {
UFUNCTION(CallInEditor, BlueprintCallable, Category = "Cesium")
void UpdateAtmosphereRadius();

/**
* Updates the time zone of this CesiumSunSky based on the given longitude.
azrogers marked this conversation as resolved.
Show resolved Hide resolved
*
* The time zone calculated here is naively based on the longitude, where
* every 15 degrees longitude equals 1 hour. This won't necessarily line up
* with the officially designated time zone at the location given.
azrogers marked this conversation as resolved.
Show resolved Hide resolved
*
* This method will call @ref UpdateSun automatically.
*
* @param InLongitude The longitude that the calculated time zone will be
* based on in degrees in the range [-180, 180].
*/
UFUNCTION(CallInEditor, BlueprintCallable, Category = "Cesium")
void UpdateTimeZoneFromLongitude(double InLongitude);
azrogers marked this conversation as resolved.
Show resolved Hide resolved

/**
* Convert solar time to Hours:Minutes:Seconds. Copied the implementation
* from the engine SunSkyBP class.
Expand Down
Loading