Good morning all,
I am facing an issue related to position calculation in Cesium.
My project use ADS-B data to display Aircraft models position and they are updated with a rate of one second or more if data is not received periodically. To display the new position I use the preupdate event handler in this way:
viewer.scene.preUpdate.addEventListener(function (scene, time) {
var Diff = new Date().getTime() - TimestampRefresh;
if (RenderStarted) {
for (var plane of ListOfFlights.values()) {
if (typeof plane.Entity !== "undefined" && ListOfFlights !== null) {
if (plane.Longitude != 0) {
var speed = (plane.Speed * 1.852 ) / 3.6;
var altitude = plane.Altitude / CONSTFEET;
var hpRoll = new Cesium.HeadingPitchRoll();
hpRoll.heading = Cesium.Math.toRadians(plane.Heading);
hpRoll.pitch = Cesium.Math.toRadians(plane.Pitch / 100);
var position = Cesium.Cartesian3.fromDegrees(plane.Longitude, plane.Latitude, altitude);
var CoeFF = 1000 / Diff;
CoeFF = 1/CoeFF;
//if airplane is select by user I display more accurate position according speed
if (currentObject3d == plane.ID) {
var spdVector = new Cesium.Cartesian3();
spdVector = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.UNIT_X, (speed/10 ) +CoeFF , spdVector);
position = Cesium.Matrix4.multiplyByPoint(plane.Entity.modelMatrix, spdVector, position);
Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, plane.Entity.modelMatrix);
$('#Refreshspeed').text(Math.round(CoeFF).toString());
$('#geoSpeed').text(Math.round(plane.Speed).toString());
$('#geoAltitude').text(Math.round(plane.Altitude).toString());
$('#geoHeading').text(Math.round(plane.Heading).toString());
$('#geoLatitude').text(plane.Latitude.toPrecision(5));
$('#geoLongitude').text(plane.Longitude.toPrecision(5));
viewer.scene.selectedEntity = plane.Entity;
TimestampRefresh = new Date().getTime();
}
else {
Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, plane.Entity.modelMatrix);
}
if (plane.Label != null) {
plane.Label.position = position;
}
else {
}
}
}
else {
// alert(plane.Callsign);
}
}
}
}
//}
});
when an airplane is select by clicking on it (with pick event) , the code should correctly calculate the position and display the model moving as in reality. The result is not correct and in base at frame per second rate the model move too fast or to slow. I tried to insert a coeffecient correction due to a difference in rate refresh.without success. Do you have any suggestion?.
Thank you