Created
December 1, 2011 21:00
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @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