Orientation problem using VelocityOrientationProperty

Hello
I’m moving models dynamically by reading from a text file that refreshes every second. As you can see, the models take the position from this file and by means of SampledPositionProperty it is interpolating so that the movement is fluid. The orientation is good while the model has speed
But problem is that when it stops, the orientation is wrong. Can you tell me how to solve it?
Thank you and greetings.

Code

//Main function
var offset = 5
function read_aircraft_file() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var flight_list=this.responseText.split("\n");
for (i = 2; i < flight_list.length; i++){
flight = flight_list[i];
var flight_data = flight.split(" ");
if (flight_data[8].indexOf(‘ok’)>-1){
var callsign = flight_data[0];
var url = ‘SampleData/models/’+flight_data[1];
var lon = parseFloat(flight_data[2]);
var lat = parseFloat(flight_data[3]);
var height = parseFloat(flight_data[4]);
var heading = Cesium.Math.toRadians(-90.0+parseFloat(flight_data[5]));
var pitch = - Cesium.Math.toRadians(parseFloat(flight_data[6]));
var roll = Cesium.Math.toRadians(parseFloat(flight_data[7]));
var position = Cesium.Cartesian3.fromDegrees(lon, lat, height);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, heading, pitch, roll);
var entity = viewer.entities.getById(callsign); if (entity === undefined){ var property = new Cesium.SampledPositionProperty();
/*property.setInterpolationOptions({
interpolationDegree : 2,
interpolationAlgorithm : Cesium.HermitePolynomialApproximation
}); */ var entity = viewer.entities.add({
position: property,
id : callsign,
model : {
uri : url,
}
})
}
var curtime = Cesium.JulianDate.now(); time = Cesium.JulianDate.addSeconds(curtime,offset, new Cesium.JulianDate());
entity.position.addSample(time, position);
entity.orientation = new Cesium.VelocityOrientationProperty(entity.position);
}
};
}
};
xhttp.open(“GET”, “…/GAMMA_interface/Cesium_file.txt”, true);
xhttp.send();
};
myInterval = setInterval(function(){read_aircraft_file()},1000);

Hello,
your entity doesn’t use your heading pitch roll definition from the file. Instead you use VelocityOrientationProperty. This attribute need some an evolution of position in order to generate an orientation. So I’d like to say it’s normal.

Hi there,

Farouk is correct – VelocityOrientationProperty looks at the change in position in order to compute an orientation (you’re not using your heading pitch roll). When you’re out of position data, you don’t have points from which to compute the orientation. Try setting http://cesiumjs.org/Cesium/Build/Documentation/SampledPositionProperty.html?classFilter=sample#forwardExtrapolationType which will tell Cesium how to extrapolate when you’re out of points.

If that doesn’t work, I’ll look into another solution.

Hope that helps,

  • Rachel