Hi Cesium Team,
I'll start by saying that I'm using Cesium b24 and STK Components 2013R7 with the Cesium jar file to write CZML. I've read through some of the past posts concerning switching reference frames but I'm still a bit lost and am looking for some suggestions on how to switch from the ECF frame (the Cesium default) to an ECI reference frame. I can do this in STK Pro by adding a button in the 3D Graphics Window called "Next View Reference Frame" and toggling it between the two views gives me what I want. I'd like to know the most efficient way to toggle between these two views in Cesium.
I see that the position attribute in CZML has a reference frame property that can be set to FIXED or INERTIAL. Is this all I'm really looking for and if so, how do I set that specific property in STK Components so that the CZML will get written out correctly?
I also see the Cesium Transform JS object. If this is what I really need and I need to write some javascript to make the reference frame change, can you supply a quick sample of code on how to use the Transform methods to do what I want?
If I'm not even close with my thoughts, please let me know what path to go down.
Thanks,
Peter
Hi Peter,
Specifying INERTIAL in CZML lets you describe the position of the object in ICRF, but it doesn’t impact the camera’s frame. To switch the camera to ICRF, you need to use Transforms, as you suggested. Assuming you’re using the Viewer widget, you can add code like this after you create it:
var viewer = new Cesium.Viewer(…); // your Viewer creation code here
var inertialToFixed = new Cesium.Matrix3();
function updateCameraInertial(viewer) {
if (viewer.scene.mode !== Cesium.SceneMode.SCENE3D) {
return;
}
if (!Cesium.defined(Cesium.Transforms.computeIcrfToFixedMatrix(viewer.clock.currentTime, inertialToFixed))) {
Cesium.Transforms.computeTemeToPseudoFixedMatrix(viewer.clock.currentTime, inertialToFixed);
}
Cesium.Matrix4.fromRotationTranslation(inertialToFixed, Cesium.Cartesian3.ZERO, viewer.scene.getCamera().transform);
}
viewer.clock.onTick.addEventListener(function() {
updateCameraInertial(viewer);
});
The only caveat with this (and the reason for my delay in getting back to you) is that you may see problems if you combine this code with camera flights, such as those initiated by the geocoder and home button widgets. Still, it should get you most of the way there and I’ll get back to you on the remaining issues once I have a complete answer.
Let me know how this works for you.
Kevin
Hi Kevin,
I put the code in above and am able to switch between ECI and ECEF now. Thanks for the help!!
Any update on the Home Button issue? I'm also seeing something similar when I try to zoom into a specific object that I've added to the map. The camera seems to get lost.
Peter
Hi Peter,
Yes, the Home Button issue is now fixed in master, and will be in the b26 release on March 3.
To fix the problem when zooming to a specific object, use this slightly modified code:
var inertialToFixed = new Cesium.Matrix3();
function updateCameraInertial(viewer) {
if (viewer.scene.mode !== Cesium.SceneMode.SCENE3D || Cesium.defined(viewer.trackedObject)) {
return;
}
if (!Cesium.defined(Cesium.Transforms.computeIcrfToFixedMatrix(viewer.clock.currentTime, inertialToFixed))) {
Cesium.Transforms.computeTemeToPseudoFixedMatrix(viewer.clock.currentTime, inertialToFixed);
}
Cesium.Matrix4.fromRotationTranslation(inertialToFixed, Cesium.Cartesian3.ZERO, viewer.scene.camera.transform);
}
viewer.clock.onTick.addEventListener(function() {
updateCameraInertial(viewer);
});
More details in the pull request that fixed the Home Button issue, if you’re interested:
https://github.com/AnalyticalGraphicsInc/cesium/pull/1489
Kevin
2 Likes
For those of you referencing this discussion in 2023 (and probably beyond), viewer.trackedObject
seems to have been renamed to viewer.trackedEntity
.
When hunting down relevant CesiumJS examples, make sure to cross-reference them with the documentation! It seems that many of the examples you can find in various forums are from before CesiumJS went in to a sort of minimal-maintenance mode.