Cesium for Unreal 2.12.0
Loading...
Searching...
No Matches
CesiumGlobeAnchorComponent.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
5#include "CesiumGeospatial/GlobeAnchor.h"
6#include "Components/ActorComponent.h"
7#include "Delegates/IDelegateInstance.h"
8#include "CesiumGlobeAnchorComponent.generated.h"
9
11
20UCLASS(ClassGroup = Cesium, Meta = (BlueprintSpawnableComponent))
21class CESIUMRUNTIME_API UCesiumGlobeAnchorComponent : public UActorComponent {
22 GENERATED_BODY()
23
24#pragma region Properties
25private:
39 UPROPERTY(
40 EditAnywhere,
41 BlueprintReadWrite,
42 BlueprintGetter = GetGeoreference,
43 BlueprintSetter = SetGeoreference,
44 Category = "Cesium",
45 Meta = (AllowPrivateAccess))
46 TSoftObjectPtr<ACesiumGeoreference> Georeference = nullptr;
47
57 UPROPERTY(
58 Transient,
59 VisibleAnywhere,
60 BlueprintReadOnly,
61 BlueprintGetter = GetResolvedGeoreference,
62 Category = "Cesium",
63 Meta = (AllowPrivateAccess))
64 ACesiumGeoreference* ResolvedGeoreference = nullptr;
65
85 UPROPERTY(
86 EditAnywhere,
87 BlueprintReadWrite,
88 BlueprintGetter = GetAdjustOrientationForGlobeWhenMoving,
89 BlueprintSetter = SetAdjustOrientationForGlobeWhenMoving,
90 Category = "Cesium",
91 Meta = (AllowPrivateAccess))
92 bool AdjustOrientationForGlobeWhenMoving = true;
93
100 UPROPERTY(
101 EditAnywhere,
102 BlueprintReadWrite,
103 BlueprintGetter = GetTeleportWhenUpdatingTransform,
104 BlueprintSetter = SetTeleportWhenUpdatingTransform,
105 Category = "Cesium",
106 Meta = (AllowPrivateAccess))
107 bool TeleportWhenUpdatingTransform = true;
108
123 UPROPERTY(
124 BlueprintReadWrite,
125 BlueprintGetter = GetActorToEarthCenteredEarthFixedMatrix,
126 BlueprintSetter = SetActorToEarthCenteredEarthFixedMatrix,
127 Category = "Cesium",
128 Meta = (AllowPrivateAccess))
129 FMatrix ActorToEarthCenteredEarthFixedMatrix;
130
131#pragma endregion
132
133#pragma region Property Accessors
134public:
144 UFUNCTION(BlueprintGetter)
145 TSoftObjectPtr<ACesiumGeoreference> GetGeoreference() const;
146
156 UFUNCTION(BlueprintSetter)
157 void SetGeoreference(TSoftObjectPtr<ACesiumGeoreference> NewGeoreference);
158
168 UFUNCTION(BlueprintGetter)
169 ACesiumGeoreference* GetResolvedGeoreference() const;
170
178 UFUNCTION(BlueprintCallable, Category = "Cesium")
179 ACesiumGeoreference* ResolveGeoreference(bool bForceReresolve = false);
180
185 UFUNCTION(BlueprintGetter, Category = "Cesium")
187
198 UFUNCTION(BlueprintGetter, Category = "Cesium")
199 FMatrix GetActorToEarthCenteredEarthFixedMatrix() const;
200
214 UFUNCTION(BlueprintSetter, Category = "Cesium")
215 void SetActorToEarthCenteredEarthFixedMatrix(const FMatrix& Value);
216
223 UFUNCTION(BlueprintGetter, Category = "Cesium")
224 bool GetTeleportWhenUpdatingTransform() const;
225
232 UFUNCTION(BlueprintSetter, Category = "Cesium")
233 void SetTeleportWhenUpdatingTransform(bool Value);
234
254 UFUNCTION(BlueprintGetter, Category = "Cesium")
255 bool GetAdjustOrientationForGlobeWhenMoving() const;
256
276 UFUNCTION(BlueprintSetter, Category = "Cesium")
277 void SetAdjustOrientationForGlobeWhenMoving(bool Value);
278
279#pragma endregion
280
281#pragma region Public Methods
282
283public:
292 UFUNCTION(
293 BlueprintPure,
294 Category = "Cesium",
295 Meta = (ReturnDisplayName = "LongitudeLatitudeHeight"))
296 FVector GetLongitudeLatitudeHeight() const;
297
301 UFUNCTION(
302 BlueprintPure,
303 Category = "Cesium",
304 Meta = (ReturnDisplayName = "Longitude"))
305 double GetLongitude() const { return this->GetLongitudeLatitudeHeight().X; }
306
310 UFUNCTION(
311 BlueprintPure,
312 Category = "Cesium",
313 Meta = (ReturnDisplayName = "Latitude"))
314 double GetLatitude() const { return this->GetLongitudeLatitudeHeight().Y; }
315
323 UFUNCTION(
324 BlueprintPure,
325 Category = "Cesium",
326 Meta = (ReturnDisplayName = "Height"))
327 double GetHeight() const { return this->GetLongitudeLatitudeHeight().Z; }
328
341 UFUNCTION(BlueprintCallable, Category = "Cesium")
342 void MoveToLongitudeLatitudeHeight(const FVector& LongitudeLatitudeHeight);
343
348 UFUNCTION(
349 BlueprintPure,
350 Category = "Cesium",
351 meta = (ReturnDisplayName = "EarthCenteredEarthFixedPosition"))
352 FVector GetEarthCenteredEarthFixedPosition() const;
353
363 UFUNCTION(BlueprintCallable, Category = "Cesium")
364 void MoveToEarthCenteredEarthFixedPosition(
365 const FVector& EarthCenteredEarthFixedPosition);
366
373 UFUNCTION(
374 BlueprintPure,
375 Category = "Cesium",
376 meta = (ReturnDisplayName = "EastSouthUpRotation"))
377 FQuat GetEastSouthUpRotation() const;
378
390 UFUNCTION(BlueprintCallable, Category = "Cesium")
391 void SetEastSouthUpRotation(const FQuat& EastSouthUpRotation);
392
403 UFUNCTION(
404 BlueprintPure,
405 Category = "Cesium",
406 meta = (ReturnDisplayName = "EarthCenteredEarthFixedRotation"))
407 FQuat GetEarthCenteredEarthFixedRotation() const;
408
419 UFUNCTION(BlueprintCallable, Category = "Cesium")
420 void SetEarthCenteredEarthFixedRotation(
421 const FQuat& EarthCenteredEarthFixedRotation);
422
427 UFUNCTION(BlueprintCallable, Category = "Cesium")
428 void SnapLocalUpToEllipsoidNormal();
429
435 UFUNCTION(BlueprintCallable, Category = "Cesium")
436 void SnapToEastSouthUp();
437
455 UFUNCTION(BlueprintCallable, Category = "Cesium")
456 void Sync();
457
458#pragma endregion
459
460#pragma region Obsolete
461public:
468 UE_DEPRECATED(
469 "Cesium For Unreal v2.0",
470 "The resolved georeference can no longer be explicitly invalidated. To change the georeference, call SetGeoreference or ReregisterComponent.")
471 UFUNCTION(
472 BlueprintCallable,
473 Category = "Cesium",
474 Meta =
475 (DeprecatedFunction,
476 DeprecationMessage =
477 "The resolved georeference can no longer be explicitly invalidated. To change the georeference, call SetGeoreference or ReregisterComponent."))
478 void InvalidateResolvedGeoreference();
479#pragma endregion
480
481#pragma region Unreal Lifecycle
482protected:
491 virtual void Serialize(FArchive& Ar) override;
492
503 virtual void OnComponentCreated() override;
504
505#if WITH_EDITOR
506 virtual void
507 PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
508#endif
509
517 virtual void OnRegister() override;
518
526 virtual void OnUnregister() override;
527#pragma endregion
528
529#pragma region Implementation Details
530private:
531 CesiumGeospatial::GlobeAnchor _createNativeGlobeAnchor() const;
532
533 USceneComponent* _getRootComponent(bool warnIfNull) const;
534
535 FTransform _getCurrentRelativeTransform() const;
536
537 void _setCurrentRelativeTransform(const FTransform& relativeTransform);
538
540 _createOrUpdateNativeGlobeAnchorFromRelativeTransform(
541 const FTransform& newRelativeTransform);
542
544 _createOrUpdateNativeGlobeAnchorFromECEF(const FMatrix& newActorToECEFMatrix);
545
546 void _updateFromNativeGlobeAnchor(
547 const CesiumGeospatial::GlobeAnchor& nativeAnchor);
548
549 void _setNewActorToECEFFromRelativeTransform();
550
551#if WITH_EDITORONLY_DATA
552 // This is used only to preserve the transformation saved by old versions of
553 // Cesium for Unreal. See the Serialize method.
554 UPROPERTY(Meta = (DeprecatedProperty))
555 double _actorToECEF_Array_DEPRECATED[16];
556#endif
557
564 UPROPERTY()
565 bool _actorToECEFIsValid = false;
566
572 bool _updatingActorTransform = false;
573
574 bool _lastRelativeTransformIsValid = false;
575 FTransform _lastRelativeTransform{};
576
585 void _onActorTransformChanged(
586 USceneComponent* InRootComponent,
587 EUpdateTransformFlags UpdateTransformFlags,
588 ETeleportType Teleport);
589
596 UFUNCTION(CallInEditor)
597 void _onGeoreferenceChanged();
598
599 friend class FCesiumGlobeAnchorCustomization;
600#pragma endregion
601};
Controls how global geospatial coordinates are mapped to coordinates in the Unreal Engine level.
UCesiumEllipsoid * GetEllipsoid() const
Returns a pointer to the UCesiumEllipsoid currently being used by this georeference.
This component can be added to a movable actor to anchor it to the globe and maintain precise placeme...
virtual void OnUnregister() override
Called when a component is unregistered.
virtual void OnComponentCreated() override
Called when a component is created (not loaded).
virtual void Serialize(FArchive &Ar) override
Handles reading, writing, and reference collecting using FArchive.
virtual void OnRegister() override
Called when a component is registered.