Using SampledProperty to set orientation?

I have an entity that I am using SampledPositionProperty with to make the model associated with the entity move along a series of lat/lng positions over time.

I want to also alter the heading/bearing of the model in the same way. Is this possible?

I have attempted to use SampledProperty(‘orientation’) to do this, then set the entity’s orientation attribute to this object, which kinda seems to make sense as it is similar to what is done with the SampledPositionProperty object, but it doesn’t work.

Is what I am trying to do possible? What am I not understanding/doing wrong?

Thanks

Guy

I suspect what I need is part 2 of this tutorial… https://cesiumjs.org/2015/02/02/Visualizing-Spatial-Data/

Anyone?

SampledProperty(Quaternion) is what you’re looking for. You can then either create individual Quaternions directly, or if you have heading/pitch/roll, you can use Transforms.headingPitchRollQuaternion to create a quaternion from them. We’ll have some additional helper properties in the future, but for now those are your two options out of the box.

Also, Cesium is a high-traffic list with lots of members, as a courtesy to others, please don’t bump posts so soon after creating them. We try to answer every question, but due to the high volume (and the community nature of open source projects) this can take a few days. If 3-4 days go by and your question hasn’t been answered, an occasional bump is okay.

Thanks. Fair enough. I mainly work on this on weekends, and they seem pretty quiet here.

I am guessing that I can’t connect that to the orientation property on the Entity, unlike the SampledPositionProperty which can be assigned to Entity.position and automatically update the position during playback…?

You definitely assign it to the entity.orientation property, just like you do with position. The semantics are exactly the same. The only difference is that Position has it’s own set of properties (SampledPositionProperty instead of SampledProperty), mainly to handle reference frames.

Ok, well that’s good. I just have to figure out why what I’ve tried so far doesn’t work. :slight_smile:

Thanks for your help with this Matthew…do you have any ideas about where I am going wrong with the code below?

for (i=0; i<len; i++) {
var attributes = datapoints[i].attributes;
var lat = attributes.getNamedItem(“lat”).nodeValue;
var lon = attributes.getNamedItem(“lon”).nodeValue;
var alt = attributes.getNamedItem(“altitude”).nodeValue;
var pos = Cesium.Cartesian3.fromDegrees(Number(lon), Number(lat), Number(alt));
positions[i] = pos;
var date = new Date(Number(timestamps[i].textContent) * 1000);
if (i > 0) {
var attributes1 = datapoints[i-1].attributes;
var lat1 = Number(attributes1.getNamedItem(“lat”).nodeValue);
var lon1 = Number(attributes1.getNamedItem(“lon”).nodeValue);
var heading = this.calcBearing(this.toRadians(lat),this.toRadians(lon),this.toRadians(lat1),this.toRadians(lon1));
var headingR = Cesium.Math.toRadians(heading);
var pitch = Cesium.Math.toRadians(15.0);
var roll = Cesium.Math.toRadians(0.0);
headings[i] = Cesium.Transforms.headingPitchRollQuaternion(pos, headingR, pitch, roll);
}
times.push(Cesium.JulianDate.fromDate(date));
}
headings[0] = headings[1];

var modelAircraft = new Cesium.ModelGraphics( {
    uri : 'CesiumAir/Cesium_Air.gltf',
    minimumPixelSize : 128
});

var entity2 = new Cesium.Entity({
    id : trackname,
    seriesName : trackname,
    model: modelAircraft
});

var orientationProperty = new Cesium.SampledProperty();
orientationProperty.addSamples(times, headings);
entity2.orientation = orientationProperty;

Thanks again, I figured this out. I hadn’t passed the type to the SampledProperty constructor.