Skip to content

Instantly share code, notes, and snippets.

@zz85
Created December 1, 2011 21:00
Show Gist options
  • Save zz85/1419820 to your computer and use it in GitHub Desktop.
Save zz85/1419820 to your computer and use it in GitHub Desktop.
At times, don't you just need a simple camera which rotates around an object in Theee.js?
/*
* @author @blurspline https://github.com/zz85
* Similar to a turntable or a hovering camera?
*/
THREE.OrbitControls = function( camera, target, distance, height, time ) {
var rotationUnits = time * 1000;
var startTime;
this.start = function() {
this.startTime = Date.now();
}
this.update = function() {
var lapsed = Date.now() - this.startTime;
var angle = (lapsed % rotationUnits) / rotationUnits * Math.PI * 2;
camera.position.x = Math.sin(angle) * distance + target.x;
camera.position.z = Math.cos(angle) * distance + target.z;
camera.position.y = height + target.z;
camera.lookAt(target);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment