I noticed that camera.look rotates the camera orientation vectors around origin, and camera.rotate does the same thing but it also rotates camera.position around origin. I needed to rotate the camera around an arbitrary point, so I added this function in camera.js (I copied some code from camera.rotate for this function)
Camera.prototype.rotate_around_point = function(point, axis, angle)
{
//shift to origin
var camera_temp=new Cartesian3;
Cartesian3.subtract(this.position,point,camera_temp);
//rotate around origin
var turnAngle = defaultValue(angle, this.defaultRotateAmount);
var quaternion = Quaternion.fromAxisAngle(axis, -turnAngle, rotateScratchQuaternion);
var rotation = Matrix3.fromQuaternion(quaternion, rotateScratchMatrix);
Matrix3.multiplyByVector(rotation, camera_temp, camera_temp);
Matrix3.multiplyByVector(rotation, this.direction, this.direction);
Matrix3.multiplyByVector(rotation, this.up, this.up);
Matrix3.multiplyByVector(rotation, this.right, this.right);
//shift back
this.position = Cartesian3.add(camera_temp,point,this.position);
}
``
Something I noticed about camera.rotate is the 2 crosses
Cartesian3.cross(this.direction, this.up, this.right);
Cartesian3.cross(this.right, this.direction, this.up);
``
It works if those lines were replaced by this line
Matrix3.multiplyByVector(rotation, this.right, this.right);
``
However, perhaps those 2 crosses help keep the orientation vectors orthogonal to one another? In Google Earth I used to store orientation as heading,tilt,roll to ensure orthogonality so I didn’t have to worry about keeping them orthogonal.
I needed this function because I plan to make a World of Warcraft style camera control for when I make Streetview splitscreen for Cesium. Cesium currently lacks 3D buildings, so I decided to have a character model represent the Streetview camera, while the 3Dview camera can rotate around it and get closer and farther from it. This seems to be the best solution, after trying out Streetview splitscreen with buildings turned off