So, I’m running into some very odd behavior trying to assign a position and orientation to an entity. In Sandcastle, if I run the following code:
var viewer = new Cesium.Viewer("cesiumContainer");
var position = new Cesium.Cartesian3(-15684.821984300848, -6378688.159345446, 0);
var heading = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(-90), Cesium.Math.toRadians(0), Cesium.Math.toRadians(0));
var clock = viewer.clock;
var start = viewer.clock.currentTime;
var last = viewer.clock.currentTime;
console.log ('Start is ' + start.secondsOfDay + ', x is ' + position.x);
var dome = viewer.entities.add({
name: 'Test1',
position: position,
orientation: Cesium.Transforms.headingPitchRollQuaternion(position, heading),
ellipsoid: {
radii: new Cesium.Cartesian3(1000000, 1000000, 1000000),
innerRadii: new Cesium.Cartesian3(100, 100, 100),
minimumClock: Cesium.Math.toRadians(0),
maximumClock: -6.283185307179586,
minimumCone: Cesium.Math.toRadians(0),
maximumCone: 1.6580627893946132,
material: Cesium.Color.CORAL.withAlpha(0.30),
outline: new Cesium.ConstantProperty(true),
outlineColor: Cesium.Color.CORAL.withAlpha(0.40),
}
});
I get a dome on my globe that looks like this:
which is what I expect to see - a dome at the indicated coordinates, pointing straight up from the earth.
If I instead set the position and orientation like this:
position: new Cesium.ConstantPositionProperty(position),
orientation: new Cesium.ConstantPositionProperty(Cesium.Transforms.headingPitchRollQuaternion(position, heading)),
I get a dome that instead looks like this:
I’m guessing the difference is because the ConstantPositionProperty
strips the W-value off the quaternion; but according to the API, the position and orientation fields should take PositionProperties. So, what’s the proper way to do what I’m aiming for here?
As a bonus, if I start with the original code, and then put it in motion:
clock.onTick.addEventListener(function(){
var now = viewer.clock.currentTime;
var delta = now.secondsOfDay - start.secondsOfDay;
var step = now.secondsOfDay - last.secondsOfDay;
if (delta !== 0 && step > 5) {
var newPos = new Cesium.Cartesian3(-15684.821984300848 * (1 - delta / 60), -6378688.159345446, 0);
console.log('delta is ' + delta + ', x is ' + newPos.x);
dome.position = newPos;
dome.orientation = Cesium.Transforms.headingPitchRollQuaternion(newPos, heading);
last = now;
}
});
I get the expected results with that code above (the dome, pointed straight up, translates along the x-axis); but if I wrap the orientation here in a ConstantPositionProperty, it still appears to work correctly - until the position x-value changes from negative to positive, at which point the rotation turns 90 degrees:
So…
- What’s the expected way to use a quaternion to set orientation (or is that a sign that I’m doing something badly wrong?)
- Why, in the second case, does everything appear to work correctly until my Entity crosses the x = 0 plane?
Thanks!