Skip to content

Commit

Permalink
feat: added TrackingReferenceFrame.ENU
Browse files Browse the repository at this point in the history
  • Loading branch information
jfayot committed Nov 19, 2024
1 parent 91821cc commit 7660e78
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Apps/Sandcastle/gallery/Entity tracking.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Interpolation.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
},
{
Expand Down
9 changes: 9 additions & 0 deletions packages/engine/Source/Core/TrackingReferenceFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 6 additions & 4 deletions packages/engine/Source/DataSources/EntityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions packages/engine/Specs/DataSources/EntityViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand Down

0 comments on commit 7660e78

Please sign in to comment.