So far, my approach has been to calculate the 3D model's direction by calculating a Cartesian3 velocity vector based on the 3D model's last two positions. I then convert the vector to spherical coordinates and add it to the spherical coordinates that are produced based on the desired heading, pitch, and magnitude of the line. So at this point I should have the theta and phi components for the line in reference to the earth because I have taken the 3D model's orientation into account. I also know the magnitude because that was given with the line's desired length. I convert the result into Cartesian coordinates and then draw the line from the 3D model's position to the result of adding the 3D model and the line's Cartesian coordinates.
What I have so far works if the heading and pitch are both 0 (i.e. I want to draw a line from the front of the 3D Model) but that's about it.
I'm assuming that there is an easier way to do this within Cesium's framework by using quaternions but this is my first exposure to them so I'm a little lost as to how to use them.
Does anyone have any advice or an example?
After putting some more thought into it... I think I might be able to get the orientation of the entity (a quaternion), create another quaternion to represent the line's orientation with respect to the entity and then multiply them together to get the actual orientation of the line with respect to the earth.
function drawLine(entity, length, azimuth, elevation) {
var entityOrientation = Cesium.Quaternion.clone(entity.orientation);
var lineOrientation = Cesium.Quaternion.fromHeadingPitchRoll(Cesium.Math.toRadians(azimuth), Cesium.Math.toRadians(elevation), 0, new Cesium.Quaternion());
Cesium.Quaternion.multiply(entityOrientation, lineOrientation, lineOrientation);
var arbitraryPoint = //cartesian coordinate that is desired length away from entity's position
var beam = viewer.entities.add({
positions : [entity.position, arbitraryPoint],
polyline : Cesium.Color.BLUE,
orientation : lineOrientation
});
//then add an offset to the positions to take the line's new orientation into account so that it starts at the entity...
}
Maybe a better way to explain it would be that I want to point a line away from the entity in a certain direction with respect to the entity's current orientation. Does that make sense?
I did find this blog post from ages ago that may help some, but if you already figured it out, I'd love to know what you did!
https://cesiumjs.org/2013/04/22/Robust-Polyline-Rendering-with-WebGL/
Thanks
Andrew