/** * @author alteredq / http://alteredqualia.com/ */ THREE.Clock = function ( autoStart ) { this.autoStart = ( autoStart !== undefined ) ? autoStart : true; this.startTime = 0; this.oldTime = 0; this.elapsedTime = 0; this.running = false; }; THREE.Clock.prototype = { constructor: THREE.Clock, start: function () { this.startTime = this._getNow(); this.oldTime = this.startTime; this.running = true; }, stop: function () { this.getElapsedTime(); this.running = false; }, getElapsedTime: function () { this.getDelta(); return this.elapsedTime; }, getDelta: function () { var diff = 0; if ( this.autoStart && ! this.running ) { this.start(); } if ( this.running ) { var newTime = this._getNow(); diff = 0.001 * ( newTime - this.oldTime ); this.oldTime = newTime; this.elapsedTime += diff; } return diff; }, _getNow: function () { var now = self.performance !== undefined && self.performance.now !== undefined ? self.performance.now() : Date.now(); return now; } };