Cesium for Unreal 2.13.2
Loading...
Searching...
No Matches
GeoTransforms.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
5#include "CesiumGeospatial/Ellipsoid.h"
6#include "CesiumGeospatial/LocalHorizontalCoordinateSystem.h"
7#include "HAL/Platform.h"
8#include "Math/Matrix.h"
9#include <glm/fwd.hpp>
10#include <glm/vec3.hpp>
11
12/**
13 * @brief A lightweight structure to encapsulate coordinate transforms.
14 *
15 * It encapsulates the conversions between...
16 * - Earth-Centered, Earth-Fixed (ECEF) coordinates
17 * - Georeferenced coordinates (Latitude/Longitude/Height)
18 * - Unreal coordinates (relative to the unreal world origin)
19 *
20 */
21class CESIUMRUNTIME_API GeoTransforms {
22
23public:
24 /**
25 * @brief Creates a new instance.
26 */
28
29 /**
30 * @brief Creates a new instance.
31 *
32 * The center position is the position of the origin of the
33 * local coordinate system that is established by this instance.
34 *
35 * @param ellipsoid The ellipsoid to use for the georeferenced coordinates
36 * @param center The center position.
37 * @param scale The scale factor of the globe in the Unreal world.
38 */
40 const CesiumGeospatial::Ellipsoid& ellipsoid,
41 const glm::dvec3& center,
42 double scale);
43
44 /**
45 * @brief Set the center position of this instance
46 *
47 * The center position is the position of the origin of the
48 * local coordinate system that is established by this instance.
49 *
50 * @param center The center position.
51 */
52 void setCenter(const glm::dvec3& center) noexcept;
53
54 /**
55 * @brief Set the ellipsoid of this instance
56 *
57 * @param ellipsoid The ellipsoid
58 */
59 void setEllipsoid(const CesiumGeospatial::Ellipsoid& ellipsoid) noexcept;
60
61 /**
62 * Transforms the given longitude in degrees (x), latitude in
63 * degrees (y), and height in meters (z) into Earth-Centered, Earth-Fixed
64 * (ECEF) coordinates.
65 */
67 const glm::dvec3& LongitudeLatitudeHeight) const noexcept;
68
69 /**
70 * Transforms the given Earth-Centered, Earth-Fixed (ECEF) coordinates into
71 * longitude in degrees (x), latitude in degrees (y), and height in
72 * meters (z).
73 */
74 glm::dvec3
75 TransformEcefToLongitudeLatitudeHeight(const glm::dvec3& Ecef) const noexcept;
76
77 /**
78 * Transforms the given longitude in degrees (x), latitude in
79 * degrees (y), and height in meters (z) into Unreal world coordinates
80 * (relative to the floating origin).
81 */
83 const glm::dvec3& origin,
84 const glm::dvec3& LongitudeLatitudeHeight) const noexcept;
85
86 /**
87 * Transforms Unreal world coordinates (relative to the floating origin) into
88 * longitude in degrees (x), latitude in degrees (y), and height in
89 * meters (z).
90 */
92 const glm::dvec3& origin,
93 const glm::dvec3& Ue) const noexcept;
94
95 /**
96 * Transforms the given point from Earth-Centered, Earth-Fixed (ECEF) into
97 * Unreal world coordinates (relative to the floating origin).
98 */
100 const glm::dvec3& origin,
101 const glm::dvec3& Ecef) const noexcept;
102
103 /**
104 * Transforms the given point from Unreal world coordinates (relative to the
105 * floating origin) to Earth-Centered, Earth-Fixed (ECEF).
106 */
108 const glm::dvec3& origin,
109 const glm::dvec3& Ue) const noexcept;
110
111 /**
112 * Transforms a rotator from Unreal world to East-South-Up at the given
113 * Unreal relative world location (relative to the floating origin).
114 */
116 const glm::dvec3& origin,
117 const glm::dquat& UeRotator,
118 const glm::dvec3& UeLocation) const noexcept;
119
120 /**
121 * Transforms a rotator from East-South-Up to Unreal world at the given
122 * Unreal world location (relative to the floating origin).
123 */
125 const glm::dvec3& origin,
126 const glm::dquat& EnuRotator,
127 const glm::dvec3& UeLocation) const noexcept;
128
129 /**
130 * Computes the rotation matrix from the local East-South-Up to Unreal at the
131 * specified Unreal world location (relative to the floating
132 * origin). The returned transformation works in Unreal's left-handed
133 * coordinate system.
134 */
136 const glm::dvec3& origin,
137 const glm::dvec3& Ue) const noexcept;
138
139 /**
140 * Computes the rotation matrix from the local East-North-Up to
141 * Earth-Centered, Earth-Fixed (ECEF) at the specified ECEF location.
142 */
143 glm::dmat3 ComputeEastNorthUpToEcef(const glm::dvec3& Ecef) const noexcept;
144
145 /*
146 * GEOREFERENCE TRANSFORMS
147 */
148
149 /**
150 * @brief Gets the transformation from the _absolute_ "Unreal World" reference
151 * frame to the "Ellipsoid-centered" reference frame (i.e. ECEF).
152 *
153 * Gets a matrix that transforms coordinates from the absolute "Unreal World"
154 * reference frame (with respect to the absolute world origin, not the
155 * floating origin) to the "Ellipsoid-centered" reference frame (which is
156 * usually Earth-centered, Earth-fixed). See {@link reference-frames.md}.
157 */
158 const glm::dmat4&
160 return this->_coordinateSystem.getLocalToEcefTransformation();
161 }
162
163 /**
164 * @brief Gets the transformation from the "Ellipsoid-centered" reference
165 * frame (i.e. ECEF) to the absolute "Unreal World" reference frame.
166 *
167 * Gets a matrix that transforms coordinates from the "Ellipsoid-centered"
168 * reference frame (which is usually Earth-centered, Earth-fixed) to the
169 * absolute "Unreal world" reference frame (with respect to the absolute world
170 * origin, not the floating origin). See {@link reference-frames.md}.
171 */
172 const glm::dmat4&
174 return this->_coordinateSystem.getEcefToLocalTransformation();
175 }
176
177 /**
178 * @brief Computes the normal of the plane tangent to the surface of the
179 * ellipsoid that is used by this instance, at the provided position.
180 *
181 * @param position The cartesian position for which to to determine the
182 * surface normal.
183 * @return The normal.
184 */
185 glm::dvec3 ComputeGeodeticSurfaceNormal(const glm::dvec3& position) const {
186 return _ellipsoid.geodeticSurfaceNormal(position);
187 }
188
189 /**
190 * Computes the rotation in ellipsoid surface normal between an old position
191 * and a new position. This rotation is expressed in terms of Unreal world
192 * coordinates, and can be used to maintain an object's orientation relative
193 * to the local horizontal as it moves over the globe.
194 *
195 * @param oldPosition The old ECEF position that the object moved from.
196 * @param newPosition The new ECEF position that the object moved to.
197 * @return The rotation from the ellipsoid surface normal at the old position
198 * to the ellipsoid surface normal at the new position.
199 */
201 const glm::dvec3& oldPosition,
202 const glm::dvec3& newPosition) const;
203
204 /**
205 * Computes the rotation in ellipsoid surface normal between an old position
206 * and a new position. This rotation is expressed in terms of Unreal world
207 * coordinates, and can be used to maintain an object's orientation relative
208 * to the local horizontal as it moves over the globe.
209 *
210 * @param oldPosition The old ECEF position that the object moved from.
211 * @param newPosition The new ECEF position that the object moved to.
212 * @return The rotation from the ellipsoid surface normal at the old position
213 * to the ellipsoid surface normal at the new position.
214 */
216 const glm::dvec3& oldPosition,
217 const glm::dvec3& newPosition) const;
218
220 return this->_ecefToUnreal;
221 }
223 return this->_unrealToEcef;
224 }
225
226private:
227 /**
228 * Update the derived state (i.e. the local horizontal coordinate system) when
229 * either the center or the ellipsoid has changed.
230 */
231 void updateTransforms() noexcept;
232
233 CesiumGeospatial::LocalHorizontalCoordinateSystem _coordinateSystem;
234
235 // Modifiable state
236 CesiumGeospatial::Ellipsoid _ellipsoid;
237 glm::dvec3 _center;
238 double _scale;
239 FMatrix _ecefToUnreal;
240 FMatrix _unrealToEcef;
241};
A lightweight structure to encapsulate coordinate transforms.
glm::dquat ComputeSurfaceNormalRotationUnreal(const glm::dvec3 &oldPosition, const glm::dvec3 &newPosition) const
Computes the rotation in ellipsoid surface normal between an old position and a new position.
GeoTransforms()
Creates a new instance.
glm::dquat ComputeSurfaceNormalRotation(const glm::dvec3 &oldPosition, const glm::dvec3 &newPosition) const
Computes the rotation in ellipsoid surface normal between an old position and a new position.
glm::dvec3 ComputeGeodeticSurfaceNormal(const glm::dvec3 &position) const
Computes the normal of the plane tangent to the surface of the ellipsoid that is used by this instanc...
const FMatrix & GetEllipsoidCenteredToAbsoluteUnrealWorldMatrix() const
void setCenter(const glm::dvec3 &center) noexcept
Set the center position of this instance.
glm::dvec3 TransformUnrealToEcef(const glm::dvec3 &origin, const glm::dvec3 &Ue) const noexcept
Transforms the given point from Unreal world coordinates (relative to the floating origin) to Earth-C...
glm::dvec3 TransformLongitudeLatitudeHeightToUnreal(const glm::dvec3 &origin, const glm::dvec3 &LongitudeLatitudeHeight) const noexcept
Transforms the given longitude in degrees (x), latitude in degrees (y), and height in meters (z) into...
const glm::dmat4 & GetAbsoluteUnrealWorldToEllipsoidCenteredTransform() const noexcept
Gets the transformation from the absolute "Unreal World" reference frame to the "Ellipsoid-centered" ...
glm::dvec3 TransformEcefToUnreal(const glm::dvec3 &origin, const glm::dvec3 &Ecef) const noexcept
Transforms the given point from Earth-Centered, Earth-Fixed (ECEF) into Unreal world coordinates (rel...
glm::dquat TransformRotatorUnrealToEastSouthUp(const glm::dvec3 &origin, const glm::dquat &UeRotator, const glm::dvec3 &UeLocation) const noexcept
Transforms a rotator from Unreal world to East-South-Up at the given Unreal relative world location (...
glm::dvec3 TransformLongitudeLatitudeHeightToEcef(const glm::dvec3 &LongitudeLatitudeHeight) const noexcept
Transforms the given longitude in degrees (x), latitude in degrees (y), and height in meters (z) into...
const FMatrix & GetAbsoluteUnrealWorldToEllipsoidCenteredMatrix() const
const glm::dmat4 & GetEllipsoidCenteredToAbsoluteUnrealWorldTransform() const noexcept
Gets the transformation from the "Ellipsoid-centered" reference frame (i.e.
void setEllipsoid(const CesiumGeospatial::Ellipsoid &ellipsoid) noexcept
Set the ellipsoid of this instance.
glm::dmat3 ComputeEastNorthUpToEcef(const glm::dvec3 &Ecef) const noexcept
Computes the rotation matrix from the local East-North-Up to Earth-Centered, Earth-Fixed (ECEF) at th...
glm::dvec3 TransformEcefToLongitudeLatitudeHeight(const glm::dvec3 &Ecef) const noexcept
Transforms the given Earth-Centered, Earth-Fixed (ECEF) coordinates into longitude in degrees (x),...
glm::dmat4 ComputeEastSouthUpToUnreal(const glm::dvec3 &origin, const glm::dvec3 &Ue) const noexcept
Computes the rotation matrix from the local East-South-Up to Unreal at the specified Unreal world loc...
glm::dquat TransformRotatorEastSouthUpToUnreal(const glm::dvec3 &origin, const glm::dquat &EnuRotator, const glm::dvec3 &UeLocation) const noexcept
Transforms a rotator from East-South-Up to Unreal world at the given Unreal world location (relative ...
glm::dvec3 TransformUnrealToLongitudeLatitudeHeight(const glm::dvec3 &origin, const glm::dvec3 &Ue) const noexcept
Transforms Unreal world coordinates (relative to the floating origin) into longitude in degrees (x),...
GeoTransforms(const CesiumGeospatial::Ellipsoid &ellipsoid, const glm::dvec3 &center, double scale)
Creates a new instance.