On my attempt to port my project (youbeq) from Google Earth to Cesiumjs I've encountered some difficulties that are preventing me from moving forward.
You can check out a part of what is already running on Cesium: http://dev.youbeq.com/Apps/Sandcastle/gallery/FollowModelCameras.html
If you check that example you can see that I have a vehicle you can control and you can change cameras as well as look left/right/back.
In Google Earth you can control the camera position and orientation by setting the LatLngAlt (for position) and Heading, Tilt and Roll (for orientation), in Cesiumjs it is a completely different setup and I can't seem to find the correct way to accomplish the same behaviour. What I was doing was pretty simple, given the current vehicle position I would find the camera position according to an offset for the xyz axis, and set the HTR of that particular camera.
From the LatLngAlt I already have I can position the camera, what I can't seem to get right is setting the orientation of the camera given the HTR I have. How can I rotate the camera correctly?
I tried adapting the code from here https://github.com/AnalyticalGraphicsInc/cesium/issues/1133 but that didn't work that well.
This is what I have right now, it just positions the camera and attempts to set the heading:
// code snippet ---------->
var position = Cesium.Cartesian3.fromDegrees(lng, lat, cameraAlt, ellipsoid, new Cesium.Cartesian3());
var transform = Cesium.Transforms.eastNorthUpToFixedFrame(position);
camera.transform = transform;
var yDir = Cesium.Matrix4.multiplyByPointAsVector(bodyModel.modelMatrix, Cesium.Cartesian3.UNIT_Y, new Cesium.Cartesian3());
Cesium.Matrix4.multiplyByPointAsVector(this.camera.inverseTransform, yDir, yDir);
var rZ = Cesium.Matrix3.fromRotationZ(getVehicleHeading() - cameraHeading, new Cesium.Matrix3());
var rotatedZ = new Cesium.Cartesian3();
Cesium.Matrix3.multiplyByVector(rZ, yDir, rotatedZ);
Cesium.Cartesian3.add(yDir, rotatedZ, yDir);
// <---------- code snippet
If anyone can give me some help in finding the correct way to accomplish this type of movement it would be greatly appreciated.