From 2ca3ae7aac6e139da3249d8e03d296bf5c60a428 Mon Sep 17 00:00:00 2001 From: "jerome.fayot" Date: Tue, 19 Nov 2024 07:23:23 +0100 Subject: [PATCH 1/2] feat: added TrackingReferenceFrame.ENU --- Apps/Sandcastle/gallery/Entity tracking.html | 7 +++++++ Apps/Sandcastle/gallery/Interpolation.html | 2 +- .../engine/Source/Core/TrackingReferenceFrame.js | 9 +++++++++ packages/engine/Source/DataSources/EntityView.js | 10 ++++++---- .../engine/Specs/DataSources/EntityViewSpec.js | 15 +++++++++++++++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Apps/Sandcastle/gallery/Entity tracking.html b/Apps/Sandcastle/gallery/Entity tracking.html index f5f21aa22a47..6e894c642e9d 100644 --- a/Apps/Sandcastle/gallery/Entity tracking.html +++ b/Apps/Sandcastle/gallery/Entity tracking.html @@ -94,6 +94,13 @@ drone.trackingReferenceFrame = Cesium.TrackingReferenceFrame.VELOCITY; }, }, + { + text: "Tracking reference frame: East-North-Up", + onselect: function () { + satellite.trackingReferenceFrame = Cesium.TrackingReferenceFrame.ENU; + drone.trackingReferenceFrame = Cesium.TrackingReferenceFrame.ENU; + }, + }, ]); //Sandcastle_End }; diff --git a/Apps/Sandcastle/gallery/Interpolation.html b/Apps/Sandcastle/gallery/Interpolation.html index 567ec12627ea..f21a5dd259c3 100644 --- a/Apps/Sandcastle/gallery/Interpolation.html +++ b/Apps/Sandcastle/gallery/Interpolation.html @@ -158,7 +158,7 @@ { text: "Tracking reference frame: East-North-Up", onselect: function () { - entity.trackingReferenceFrame = Cesium.TrackingReferenceFrame.EAST_NORTH_UP; + entity.trackingReferenceFrame = Cesium.TrackingReferenceFrame.ENU; }, }, { diff --git a/packages/engine/Source/Core/TrackingReferenceFrame.js b/packages/engine/Source/Core/TrackingReferenceFrame.js index 4ad418e96b7a..a7e735b8e1e5 100644 --- a/packages/engine/Source/Core/TrackingReferenceFrame.js +++ b/packages/engine/Source/Core/TrackingReferenceFrame.js @@ -36,5 +36,14 @@ const TrackingReferenceFrame = { * @constant */ VELOCITY: 2, + + /** + * The entity's local East-North-Up reference frame. + * When selected, the auto-detect algorithm is overridden. + * + * @type {number} + * @constant + */ + ENU: 3, }; export default Object.freeze(TrackingReferenceFrame); diff --git a/packages/engine/Source/DataSources/EntityView.js b/packages/engine/Source/DataSources/EntityView.js index bc759b53dbd6..9e7ae33234b5 100644 --- a/packages/engine/Source/DataSources/EntityView.js +++ b/packages/engine/Source/DataSources/EntityView.js @@ -269,7 +269,12 @@ function updateTransform( rotationScratch, ); Matrix4.fromRotationTranslation(rotation, cartesian, transform); - } else if (hasBasis) { + } else if ( + trackingReferenceFrame === TrackingReferenceFrame.ENU || + !hasBasis + ) { + Transforms.eastNorthUpToFixedFrame(cartesian, ellipsoid, transform); + } else { transform[0] = xBasis.x; transform[1] = xBasis.y; transform[2] = xBasis.z; @@ -286,9 +291,6 @@ function updateTransform( transform[13] = cartesian.y; transform[14] = cartesian.z; transform[15] = 0.0; - } else { - // Stationary or slow-moving, low-altitude objects use East-North-Up. - Transforms.eastNorthUpToFixedFrame(cartesian, ellipsoid, transform); } camera._setTransform(transform); diff --git a/packages/engine/Specs/DataSources/EntityViewSpec.js b/packages/engine/Specs/DataSources/EntityViewSpec.js index 2aa12913f9e5..61223cc1dd0b 100644 --- a/packages/engine/Specs/DataSources/EntityViewSpec.js +++ b/packages/engine/Specs/DataSources/EntityViewSpec.js @@ -83,6 +83,10 @@ describe( entity.trackingReferenceFrame = TrackingReferenceFrame.VELOCITY; view.update(JulianDate.now()); expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10); + + entity.trackingReferenceFrame = TrackingReferenceFrame.ENU; + view.update(JulianDate.now()); + expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10); }); it("uses entity bounding sphere", function () { @@ -115,6 +119,13 @@ describe( new BoundingSphere(new Cartesian3(3, 4, 5), 6), ); expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10); + + entity.trackingReferenceFrame = TrackingReferenceFrame.ENU; + view.update( + JulianDate.now(), + new BoundingSphere(new Cartesian3(3, 4, 5), 6), + ); + expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10); }); it("uses entity viewFrom if available and boundingsphere is supplied", function () { @@ -140,6 +151,10 @@ describe( entity.trackingReferenceFrame = TrackingReferenceFrame.VELOCITY; view.update(JulianDate.now()); expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10); + + entity.trackingReferenceFrame = TrackingReferenceFrame.ENU; + view.update(JulianDate.now()); + expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10); }); it("update throws without time parameter", function () { From 2715500bf1981e9aeae4595d9c98b342c70f5411 Mon Sep 17 00:00:00 2001 From: "jerome.fayot" Date: Thu, 21 Nov 2024 07:20:05 +0100 Subject: [PATCH 2/2] doc: updated CHANGES.md and TrackingReferenceFrame documentation --- CHANGES.md | 6 +++++- .../Source/Core/TrackingReferenceFrame.js | 20 ++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6553014c59d6..8b86cea1cf1d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,11 @@ ##### Additions :tada: - Added `getSample` to `SampledProperty` to get the time of samples. [#12253](https://github.com/CesiumGS/cesium/pull/12253) -- Added `Entity.trackingReferenceFrame` property to allow tracking entities in their own inertial reference frame. [#12194](https://github.com/CesiumGS/cesium/pull/12194) +- Added `Entity.trackingReferenceFrame` property to allow tracking entities in various reference frames. [#12194](https://github.com/CesiumGS/cesium/pull/12194), [#12314](https://github.com/CesiumGS/cesium/pull/12314) + - `TrackingReferenceFrame.AUTODETECT` (default): uses either VVLH or ENU dependeding on entity's dynamic. Use `TrackingReferenceFrame.ENU` if your camera orientation flips abruptly from time to time. + - `TrackingReferenceFrame.ENU`: uses the entity's local East-North-Up reference frame. + - `TrackingReferenceFrame.INERTIAL`: uses the entity's inertial reference frame. + - `TrackingReferenceFrame.VELOCITY`: uses entity's `VelocityOrientationProperty` as orientation. ##### Fixes :wrench: diff --git a/packages/engine/Source/Core/TrackingReferenceFrame.js b/packages/engine/Source/Core/TrackingReferenceFrame.js index a7e735b8e1e5..d16be08b853b 100644 --- a/packages/engine/Source/Core/TrackingReferenceFrame.js +++ b/packages/engine/Source/Core/TrackingReferenceFrame.js @@ -17,33 +17,29 @@ const TrackingReferenceFrame = { AUTODETECT: 0, /** - * The entity's inertial reference frame. If entity has no defined orientation - * property, a {@link VelocityOrientationProperty} is used instead, thus - * falling back to TrackingReferenceFrame.VELOCITY. - * When selected, the auto-detect algorithm is overridden. + * The entity's local East-North-Up reference frame. * * @type {number} * @constant */ - INERTIAL: 1, + ENU: 1, /** - * The entity's inertial reference frame with orientation fixed to its - * {@link VelocityOrientationProperty}, ignoring its own orientation. - * When selected, the auto-detect algorithm is overridden. + * The entity's inertial reference frame. If entity has no defined orientation + * property, it falls back to auto-detect algorithm. * * @type {number} * @constant */ - VELOCITY: 2, + INERTIAL: 2, /** - * The entity's local East-North-Up reference frame. - * When selected, the auto-detect algorithm is overridden. + * The entity's inertial reference frame with orientation fixed to its + * {@link VelocityOrientationProperty}, ignoring its own orientation. * * @type {number} * @constant */ - ENU: 3, + VELOCITY: 3, }; export default Object.freeze(TrackingReferenceFrame);