Rotate camera around an arbitrary point

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;

//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

I hava some questions , Can I get your contact information in order to ask you?
在 2015年1月9日星期五 UTC+8下午1:00:04,Hyper Sonic写道:

I've tried this method, but its throwing error on = Cesium.Matrix3.getRow(rotation, 0); as undefined X,
After Cesium.Quaternion.normalize(), X Y Z are undefined. Not sure why.

Do you have any sample by which you can control camera around a point?
I'm trying several other approaches like flyTo with Destination and Orientation parameters.


You can rotate around an arbitrary point using camera.lookAtTransform(). See this sandcastle example for reference (under setReferenceFrame()).

Hope that helps,

  • Rachel