Updating the orientation of an entity wrt to time

I have created an entity using a gltf file. The entity needs to be rotating and moving at the same time. I'm not facing any issues with changing the position of the entity (movement). However, there seem to be some issues with the rotation. When I remove the codes regarding the positioning of the entity, the rotation remains constant at the specified angle. Without removing the code for the movement, the entity rotates as it moves and its clearly not rotating at the value I specified.

var clock = viewer.clock;
var lastUpdated = clock.currentTime;
var count = 1;
var position = Cesium.Cartesian3.fromDegrees(103.7764, 1.2966, 50000.0);
var heading = Cesium.Math.toRadians(90);
var pitch = 0;
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

satelliteModel = viewer.entities.add({
    name : satelliteModel,
    position : position,
    orientation : orientation,

clock.onTick.addEventListener(function() {
  var dt = Cesium.JulianDate.secondsDifference(clock.currentTime, lastUpdated);
        if (dt >= 1.0) {
    var date = new Date(clock.currentTime);
    const latLonObj = tlejs.getLatLon(tleStr, date.toUTCString());
    count += 10;
    if (count >= 180) count = 10;
    heading = Cesium.Math.toRadians(count);
    pitch = 0;
    roll = 0;
    hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
    if(satelliteModel != null) {
      satelliteModel.position = Cesium.Cartesian3.fromDegrees(latLonObj.lng, latLonObj.lat, 50000.0);
      satelliteModel.orientaion = Cesium.Transforms.headingPitchRollQuaternion(satelliteModel.position, hpr);

  lastUpdated = clock.currentTime;

The position changes according to the coordinates of the satellite (no issues). The rotation is meant for sun tracking. I haven't work on the angle required for sun tracking yet. Just wanted to know how to rotate the entity continuously wrt to time. Thank you.

I made some modifications to your code to get it to work in a Sandcastle. The only thing I really had to change to get it to work was to call satteliteModel.position.getValue() before passing it to the headingPitchRollQuaternion function.

Here’s the Sandcastle.

The nice thing about Cesium is that there’s a lot of built in mechanisms for handling time dynamic stuff like this. Check out the SampledPositionProperty for example, here’s a Sandcastle showing its use. And another one showing the different interpolation values. Instead of manually setting the position and orientation of the model on each tick, you add samples to these dynamic properties, and you’ll be able to do things like scrub back and forth with the timeline, or pause and play the simulation in reverse etc. I’ve been working on documenting this better, and while it’s not released yet, here’s a PR that adds a Sandcastle example showing how to use these properties to control the orientation of a moving vehicle and spin its wheels based on its velocity:

Hope this helps!