Thank you Rachel and Matthew,
I think I am nearly there - but not quite…
The code below loads position into a sampled position property and the heading information into hdg (I plan to move this to quaternions).
For testing I’ve given some nominal values to pitch, heading and roll and calculated an orientation from that. As soon as I try to apply it to the entity (via the line marked ‘THIS LINE’) the model disappears. If you could give me the crucial clue to get me over the finish line I would be very grateful.
Thank you
Hugh
var viewer = new Cesium.Viewer(‘cesiumContainer’, {
terrainProviderViewModels : [], //Disable terrain changing
infoBox : false, //Disable InfoBox widget
selectionIndicator : false //Disable selection indicator
});
//Enable lighting based on sun/moon positions
viewer.scene.globe.enableLighting = true;
viewer.trackedEntity = entity;
//Use STK World Terrain
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/world',
requestWaterMask : true,
requestVertexNormals : true
});
//Enable depth testing so things behind the terrain disappear.
viewer.scene.globe.depthTestAgainstTerrain = true;
//Set bounds of our simulation time
var start = Cesium.JulianDate.fromIso8601(‘2012-08-04T10:00:10Z’);
var stop = Cesium.JulianDate.fromIso8601(‘2012-08-04T10:03:10Z’);
//Make sure viewer is at the desired time.
viewer.clock.startTime = start.clone();
viewer.clock.stopTime = stop.clone();
viewer.clock.currentTime = start.clone();
viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; //Loop at the end
viewer.clock.multiplier = 4;
//Set timeline to simulation bounds
viewer.timeline.zoomTo(start, stop);
// Add heading
function storeHeading() {
var hdg = new Cesium.SampledProperty(Number);
//Populate it with data
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:34Z'), 88);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:35Z'), 87.6);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:36Z'), 87.6);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:37Z'), 88.3);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:38Z'), 89);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:39Z'), 89.7);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:40Z'), 89.7);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:41Z'), 90.1);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:42Z'), 90.8);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:43Z'), 90.8);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:44Z'), 90.8);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:45Z'), 91.2);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:46Z'), 91.5);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:47Z'), 90.8);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:48Z'), 90.4);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:49Z'), 90.4);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:50Z'), 90.8);
return hdg;
}
//Generate a random circular pattern with varying heights.
function computeFlight() {
var property = new Cesium.SampledPositionProperty();
// Populate it with data
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:35Z'), Cesium.Cartesian3.fromDegrees(-60.9649963, 13.7333345, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:36Z'), Cesium.Cartesian3.fromDegrees(-60.9649353, 13.7333384, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:37Z'), Cesium.Cartesian3.fromDegrees(-60.9648476, 13.7333422, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:38Z'), Cesium.Cartesian3.fromDegrees(-60.9647331, 13.733346, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:39Z'), Cesium.Cartesian3.fromDegrees(-60.9645958, 13.733346, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:40Z'), Cesium.Cartesian3.fromDegrees(-60.9644279, 13.733346, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:41Z'), Cesium.Cartesian3.fromDegrees(-60.9642372, 13.733346, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:42Z'), Cesium.Cartesian3.fromDegrees(-60.9640236, 13.7333441, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:43Z'), Cesium.Cartesian3.fromDegrees(-60.9637871, 13.7333403, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:44Z'), Cesium.Cartesian3.fromDegrees(-60.9635239, 13.7333364, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:45Z'), Cesium.Cartesian3.fromDegrees(-60.9632378, 13.7333317, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:46Z'), Cesium.Cartesian3.fromDegrees(-60.962925, 13.7333241, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:47Z'), Cesium.Cartesian3.fromDegrees(-60.9625931, 13.7333183, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:48Z'), Cesium.Cartesian3.fromDegrees(-60.9622383, 13.7333145, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:49Z'), Cesium.Cartesian3.fromDegrees(-60.9618607, 13.7333107, 21));
property.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T10:00:50Z'), Cesium.Cartesian3.fromDegrees(-60.9614601, 13.7333069, 21));
return property;
}
//Compute the entity position property.
var position = computeFlight();
var hdg = storeHeading(0);
//
var heading = Cesium.Math.toRadians(135);
var pitch = 0;
var roll = 0;
var orientation = new Cesium.HeadingPitchRoll( heading, pitch, roll);
//Actually create the entity
var entity = viewer.entities.add({
//Set the entity availability to the same interval as the simulation time.
availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start : start,
stop : stop
})]),
//Use our computed positions
position : position,
///////////////////////////////////////////////////////
//compute orientation
// orientation : orientation, /// THIS LINE
//Load the Cesium plane model to represent the entity
model : {
uri : '../../SampleData/models/CesiumAir/Cesium_Air.gltf',
minimumPixelSize : 64
},
//Show the path as a pink line sampled in 1 second increments.
path : {
resolution : 1,
material : new Cesium.PolylineGlowMaterialProperty({
glowPower : 0.1,
color : Cesium.Color.YELLOW
}),
width : 10
}
});
//Add button to view the path from the top down
Sandcastle.addDefaultToolbarButton(‘View Top Down’, function() {
viewer.trackedEntity = undefined;
viewer.zoomTo(viewer.entities, new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90)));
});
//Add button to view the path from the side
Sandcastle.addToolbarButton(‘View Side’, function() {
viewer.trackedEntity = undefined;
viewer.zoomTo(viewer.entities, new Cesium.HeadingPitchRange(Cesium.Math.toRadians(-90), Cesium.Math.toRadians(-15), 7500));
});
//Add button to track the entity as it moves
Sandcastle.addToolbarButton(‘View Aircraft’, function() {
viewer.trackedEntity = entity;
});
``