Is there a way to display the earth’s inertial rotation, the way Insight3D does by default? I’m not sure if this is a function of central body, camera, scene, etc, but I’ve been looking for a way to set this and haven’t found one.
Hi Eric,
We don’t have this right now; however, below you will find an approximation for converting from TEME to pseudo-fixed. You can use it to set the camera’s transform, and make the globe spin. In the skeleton, replace the scene.setAnimation(…) call with this:
/**
-
Computes a rotation matrix to transform a point or vector from True Equator Mean Equinox (TEME) axes to the
-
pseudo-fixed axes at a given time. This method treats the UT1 time standard as equivalent to UTC.
Patrick,
Thanks for that code. I was able to get that working in the CesiumViewer, and I see what you mean about the camera controls.
Will I need to provide all of my positional data in ECEF? My propagation algorithms currently deal only in ECI and my ECEF conversion code is buried in FORTRAN in a place I can’t get to it, so I will need to do some work to convert. I know this is easy to do in STK Components, and I was just curious what the plan for this is.
Eric
Eric,
Currently, there are not plans for ECI to ECEF in Cesium. However, you could use the function I provided to set the primitive’s model transform as an approximation, e.g.
polyline.model = computeTemeToPseudoFixedMatrix(time);
polyline.setPositions(/* positions in ECI, well, really TEME */);
Regards,
Patrick
I have not been able to get this code to work in Sandcastle.
Here are the error messages:
- TypeError: viewer.scene.setAnimation is not a function (on line 45)
- TypeError: Cesium.SunPosition is undefined (on line 46)
- TypeError: time.addSeconds is not a function (on line 49)
Have there been API changes that affects this code?
Is this code still the way to get the Earth to rotate?
The time interval for this space mission visualization is 2014-07-22 T11:00:00Z to 2014-08-12 T22:07:27Z.
Buttons on the left side of the page enable selection of viewpoints one of the viewpoints is the Earth.
http://daoneil.github.io/spacemission/Apps/EarthToMoon_withNav.html
An ideal implementation would be to tie the rotation of the Earth to the time widget shuttle ring.
What code would enable time widget driven Earth rotation?
Hello,
This code sample is very old, and the API has changed since then.
Take a look at the camera Sandcastle demo: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Camera.html&label=Showcases
From the menu, select ‘View in ICRF’ and look at that section of the code.
Best,
Hannah
I implemented the code from the camera Sandcastle demo. Now, the problem is the trajectories rotate along with the Earth.
This
link leads to the version with the camera.transform. Please wait 30 seconds until the buttons are no longer grey then click on the Earth button.
http://daoneil.github.io/spacemission/Apps/EarthToMoon_spinGlobe.html
I’m wondering whether it’s possible to periodically update the orientation of the viewer.scene.globe.ellipsoid.
I’ve tried setting the orientation to a Matrix4 and Quaternion and I get type errors.
What is the data type of an entity’s orientation?
Here is some code that I have attempted in Sandcastle:
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var currentAngle = 0 ;
// var m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(currentAngle));
var zAxis = new Cesium.Cartesian3(0, 0, 1) ;
var rotquat = new Cesium.Quaternion.fromAxisAngle(zAxis,Cesium.Math.toRadians(currentAngle)) ;
viewer.clock.onTick.addEventListener(function(clock) {
// viewer.scene.globe.ellipsoid.orientation = Cesium.Matrix4.fromRotationTranslation(m, Cesium.Cartesian3.ZERO);
console.log("ready to set orientation") ;
viewer.scene.globe.ellipsoid.orientation = rotquat ;
currentAngle = currentAngle + 1 ;
if (currentAngle > 360) { currentAngle = 0 ; }
rotquat = Cesium.Quaternion.fromAxisAngle(zAxis,Cesium.Math.toRadians(currentAngle)) ;
// m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(currentAngle)) ;
});
Cool demo!
I see, your coordinates are already in ICRF. That’s why they’re moving.
In your CZML file, you can define the reference frame for your positions.
Try
“position”: {
“referenceFrame”: “INERTIAL”,
…
``
Hope this helps!
-Hannah
Hannah -
Thanks! adding the inertial reference frame to the CZML files fixed the problem with the trajectories rotating with the Earth.
Now, the view point buttons no longer work, probably because the camera and the tracked entity are in two different reference frames.
This code snippet is the function called by the view point Moon button:
function showTheMoon() {
var ourMoon = czmlDataSource2.entities.getById(‘theMoon’) ;
viewer.trackedEntity = ourMoon ;
}
In the function called by the Spacecraft button, I attempted to produce a transform based on the lunar probe’s position and use the transform in the camera.looAtTtransform function.
function showSpaceCraft() {
var spaceCraft = czmlDataSource1.entities.getById(‘lunarProbe’) ;
var center = spaceCraft.position.getValue(Cesium.JulianDate.now()) ;
center.x = center.x + 10 ;
center.y = center.y + 10 ; // move center away from the spacecraft
console.log ("center ", center) ; // nothing appears in the console
// Get the transform from local east-north-up at the adjusted center.
var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);
viewer.camera.lookAtTransform(transform, spaceCraft.position.getValue(Cesium.JulianDate.now()));
}
The current model – http://daoneil.github.io/spacemission/Apps/EarthToMoon_spinGlobe.html
Thanks for your guidance.
It looks like there’s a typo in your example that’s throwing an error to the console. I’m not sure if that’s the root of your problem though.
spaceCraft is an entity, correct? To track it, you could set viewer.trackedEntity = spaceCraft; (and viewer.trackedEntity = undefined; to untrack it)
Best,
Hannah
Hannah -
Thanks for mentioning the typo; interestingly, the web console in FireFox did not catch it but the web console in Chrome did.
Please look at these two versions of the same demo.
- http://daoneil.github.io/spacemission/Apps/EarthToMoon_withCam.html
-
http://daoneil.github.io/spacemission/Apps/EarthToMoon_ICRF.html
Within the function called by the spacecraft button is viewer.trackedEntity = spaceCraft ; and
within the function called by the moon button is viewer.trackedEntity = ourMoon ;
These functions work as desired in the EarthToMoon_withCam but they don’t work in EarthToMoon_ICRF.
In the _ICRF version, pressing the spacecraft or moon buttons only show an empty star-field.
Both demo versions include the following code:
function icrf(scene, time) {
if (scene.mode !== Cesium.SceneMode.SCENE3D) {
return;
}
var icrfToFixed = Cesium.Transforms.computeIcrfToFixedMatrix(time);
if (Cesium.defined(icrfToFixed)) {
var camera = viewer.camera;
var offset = Cesium.Cartesian3.clone(camera.position);
var transform = Cesium.Matrix4.fromRotationTranslation(icrfToFixed);
camera.lookAtTransform(transform, offset);
}
}
clock.multiplier = 3 * 60 * 60;
scene.preRender.addEventListener(icrf);
The only difference the is last line, which adds the event listener – it is commented out in the _withCam version.
Adding the event listener does cause the Earth to spin while keeping the trajectories still.
Per your previous suggestion, the CZML files include:
`“position”: {
“referenceFrame”: “INERTIAL”,
With the camera in ICRF and the trajectories in an Inertial reference frame, wouldn’t we need to
transform coordinates so the camera and the models are in the same reference frame?
`
Thanks.
Hello,
Just to make sure I understand, for the EarthToMoon_ICRF demo, you are using referenceFrame: INERTIAL in the CZML and the scene.preRender event?
-Hannah
In the EarthToMoon_ICRF demo, I have the INERTIAL reference frame specified in the CZML code that specifies the lunar probe and the Moon’s orbit.
The scene.preRender event is in the JavaScript; here is the script:
In the EarthToMoon_withCam version, you can see the spacecraft or the Moon when you click the buttons; however the trajectories spin with the Earth.
In the EarthToMoon_ICRF version, the Earth spins, the trajectories stay put but you no longer see the spacecraft or the Moon when you click the buttons.
Should the CZML files have something in them about the scene.preRender event or the ICRF?
Thanks,
- Dan
Some success!
This version works, albeit sporadically, http://daoneil.github.io/spacemission/Apps/EarthToMoon_Transforms.html
Now,
the Earth spins, the trajectories, stay still, and the buttons work the
first time. On subsequent clicks of the Spacecraft button there is only
night-sky; however, if you press the Moon button before pressing the Spacecraft button then the Spacecraft appears.
The code for the main script as presented in my previous post.
Here are the functions that are called by the buttons:
function bigPicture() {
viewer.trackedEntity = undefined
scene.preRender.
addEventListener(icrf);
viewer.camera.setView({
destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.0, 1500000000.0)
});
viewer.trackedEntity = earthCore ;
console.log (“big picture”) ;
}
function showSpaceCraft() {
viewer.trackedEntity = undefined
scene.preRender.removeEventListener(icrf);
var spaceCraft = czmlDataSource1.entities.getById('lunarProbe') ;
viewer.trackedEntity = spaceCraft ;
}
function showTheMoon() {
viewer.trackedEntity = undefined
scene.preRender.removeEventListener(icrf);
var ourMoon = czmlDataSource2.entities.getById('theMoon') ;
viewer.trackedEntity = ourMoon ;
}
function showTheEarth() {
viewer.trackedEntity = undefined
scene.preRender.addEventListener(icrf);
// Set position with a top-down view
viewer.camera.setView({
destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.0, 150000000.0)
});
viewer.trackedEntity = earthCore ;
}
What
has changed? The functions called by the Spacecraft and Moon buttons removes the event listener that was added in the main script.
The buttons for the big picture and the Earth add the event listener for ICRF. If someone could let me know how to make the program a little more
robust regarding the spacecraft as a tracked entity, I would appreciate
it.
Sorry I never got back to you. Glad you were able to figure out a solution!
What is the problem you were seeing now? I wasn’t able to reproduce it. I clicked the spacecraft button multiple times and switched back and forth between the spacecraft and moon views and everything seemed to work fine.
By the way, we do add a moon ellipsoid to the scene (which I’m sure you’ve noticed). You can turn off our moon by doing viewer.scene.moon.show = false;
And you can add our texture to your moon with
"ellipsoid" : {
"radii" : {
"cartesian" : [...]
},
"material" : {
"image" : {
"image" : { "uri" : "path/to/Cesium/Source/Assets/Textures/moonSmall.jpg" }
}
}
}
``
I’m not sure which version of Cesium you’re using, but the hole in the top of the moon should have be fixed if you use the latest version, 1.19
Best,
Hannah
Hannah -
Thanks for the suggested alternative approaches, I chose to turn off the default Moon and texture map an ellipsoid.
I added a Boolean flag to check before adding or removing the ICRF event listener.
The CZML now sets the clock multiplier to 2100x.
- Here is the demo -> http://daoneil.github.io/spacemission/Apps/EarthToMoon_Demo.html
- Here is the source code for the EarthToMoon_demo.html and associated CZML files -> https://github.com/daoneil/spacemission
- Dan
Thanks for sharing, Dan! That demo looks really great!
-Hannah