Skip to content

Commit

Permalink
Improvements from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Sep 14, 2023
1 parent bdcb2b5 commit a2b94a7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
2 changes: 0 additions & 2 deletions Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,6 @@ void ACesium3DTileset::OnFocusEditorViewportOnThis() {
ACesiumGeoreference* pGeoreference = this->ResolveGeoreference();

// calculate unreal camera position
const glm::dmat4& transform =
this->GetCesiumTilesetToUnrealRelativeWorldTransform();
glm::dvec3 ecefCameraPosition =
std::visit(CalculateECEFCameraPosition{}, boundingVolume);
FVector unrealCameraPosition =
Expand Down
7 changes: 3 additions & 4 deletions Source/CesiumRuntime/Private/CesiumGeoreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ ACesiumGeoreference::ComputeEastNorthUpToEcef(const FVector& ecef) const {
return UCesiumWgs84Ellipsoid::EastNorthUpToEarthCenteredEarthFixed(ecef);
}

ACesiumGeoreference::ACesiumGeoreference() : AActor(), _geoTransforms() {
ACesiumGeoreference::ACesiumGeoreference() : AActor() {
PrimaryActorTick.bCanEverTick = true;

this->Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
Expand Down Expand Up @@ -664,13 +664,12 @@ void ACesiumGeoreference::UpdateGeoreference() {
OnGeoreferenceUpdated.Broadcast();
}

const GeoTransforms& ACesiumGeoreference::GetGeoTransforms() const noexcept {
GeoTransforms ACesiumGeoreference::GetGeoTransforms() const noexcept {
// Because GeoTransforms is deprecated, we only lazily update it.
this->_geoTransforms = GeoTransforms(
return GeoTransforms(
Ellipsoid::WGS84,
glm::dvec3(this->_coordinateSystem.getLocalToEcefTransformation()[3]),
this->GetScale() / 100.0);
return this->_geoTransforms;
}

FName ACesiumGeoreference::DEFAULT_GEOREFERENCE_TAG =
Expand Down
55 changes: 34 additions & 21 deletions Source/CesiumRuntime/Private/GlobeAwareDefaultPawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ void AGlobeAwareDefaultPawn::MoveForward(float Val) {
}

void AGlobeAwareDefaultPawn::MoveUp_World(float Val) {
if (Val == 0.0f || !IsValid(this->GlobeAnchor)) {
if (Val == 0.0f) {
return;
}

ACesiumGeoreference* pGeoreference = this->GetGeoreference();
if (!IsValid(pGeoreference)) {
return;
}

FVector upEcef = UCesiumWgs84Ellipsoid::GeodeticSurfaceNormal(
this->GlobeAnchor->GetECEF());
FVector up = this->GlobeAnchor->ResolveGeoreference()
->TransformEarthCenteredEarthFixedDirectionToUnreal(upEcef);
FVector up =
pGeoreference->TransformEarthCenteredEarthFixedDirectionToUnreal(upEcef);

FTransform transform{};
USceneComponent* pRootComponent = this->GetRootComponent();
Expand All @@ -67,6 +72,11 @@ FRotator AGlobeAwareDefaultPawn::GetViewRotation() const {
return this->GetActorRotation();
}

ACesiumGeoreference* pGeoreference = this->GetGeoreference();
if (!pGeoreference) {
return this->GetActorRotation();
}

// The control rotation is expressed in a left-handed East-South-Up (ESU)
// coordinate system:
// * Yaw: Clockwise from East: 0 is East, 90 degrees is
Expand All @@ -90,8 +100,7 @@ FRotator AGlobeAwareDefaultPawn::GetViewRotation() const {
FVector globePosition =
transform.InverseTransformPosition(this->GetPawnViewLocation());
FMatrix esuAdjustmentMatrix =
this->GetGeoreference()->ComputeEastSouthUpToUnrealTransformation(
globePosition) *
pGeoreference->ComputeEastSouthUpToUnrealTransformation(globePosition) *
transform.ToMatrixNoScale();

return FRotator(esuAdjustmentMatrix.ToQuat() * localRotation.Quaternion());
Expand Down Expand Up @@ -166,6 +175,10 @@ void AGlobeAwareDefaultPawn::FlyToLocationECEF(
return;
}

if (!IsValid(this->GetGeoreference())) {
return;
}

PitchAtDestination = glm::clamp(PitchAtDestination, -89.99, 89.99);
// Compute source location in ECEF
glm::dvec3 ECEFSource = VecMath::createVector3D(this->GlobeAnchor->GetECEF());
Expand Down Expand Up @@ -256,13 +269,6 @@ void AGlobeAwareDefaultPawn::FlyToLocationLongitudeLatitudeHeight(
double PitchAtDestination,
bool CanInterruptByMoving) {

if (!IsValid(this->GetGeoreference())) {
UE_LOG(
LogCesium,
Warning,
TEXT("GlobeAwareDefaultPawn %s does not have a valid Georeference"),
*this->GetName());
}
FVector ecef =
UCesiumWgs84Ellipsoid::LongitudeLatitudeHeightToEarthCenteredEarthFixed(
VecMath::createVector(LongitudeLatitudeHeightDestination));
Expand Down Expand Up @@ -290,13 +296,7 @@ void AGlobeAwareDefaultPawn::FlyToLocationLongitudeLatitudeHeight(
bool AGlobeAwareDefaultPawn::ShouldTickIfViewportsOnly() const { return true; }

void AGlobeAwareDefaultPawn::_handleFlightStep(float DeltaSeconds) {
if (!IsValid(this->GlobeAnchor)) {
UE_LOG(
LogCesium,
Warning,
TEXT(
"GlobeAwareDefaultPawn %s does not have a valid GeoreferenceComponent"),
*this->GetName());
if (!IsValid(this->GetGeoreference())) {
return;
}

Expand Down Expand Up @@ -386,11 +386,24 @@ ACesiumGeoreference* AGlobeAwareDefaultPawn::GetGeoreference() const {
UE_LOG(
LogCesium,
Error,
TEXT("GlobeAwareDefaultPawn %s does not have a GlobeAnchorComponent"),
TEXT(
"GlobeAwareDefaultPawn %s does not have a valid GlobeAnchorComponent."),
*this->GetName());
return nullptr;
}
return this->GlobeAnchor->ResolveGeoreference();

ACesiumGeoreference* pGeoreference = this->GlobeAnchor->ResolveGeoreference();
if (!IsValid(pGeoreference)) {
UE_LOG(
LogCesium,
Error,
TEXT(
"GlobeAwareDefaultPawn %s does not have a valie CesiumGeoreference."),
*this->GetName());
pGeoreference = nullptr;
}

return pGeoreference;
}

void AGlobeAwareDefaultPawn::_moveAlongViewAxis(EAxis::Type axis, double Val) {
Expand Down
3 changes: 1 addition & 2 deletions Source/CesiumRuntime/Public/CesiumGeoreference.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ class CESIUMRUNTIME_API ACesiumGeoreference : public AActor {

public:
[[deprecated(
"Use transformation functions on ACesiumGeoreference and UCesiumWgs84Ellipsoid instead.")]] const GeoTransforms&
"Use transformation functions on ACesiumGeoreference and UCesiumWgs84Ellipsoid instead.")]] GeoTransforms
GetGeoTransforms() const noexcept;

private:
Expand Down Expand Up @@ -709,7 +709,6 @@ class CESIUMRUNTIME_API ACesiumGeoreference : public AActor {
*/
static FName DEFAULT_GEOREFERENCE_TAG;

mutable GeoTransforms _geoTransforms;
CesiumGeospatial::LocalHorizontalCoordinateSystem _coordinateSystem{
glm::dmat4(1.0)};

Expand Down

0 comments on commit a2b94a7

Please sign in to comment.