1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /**
- * @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.start = function () {
- this.startTime = performance.now !== undefined ? performance.now() : Date.now();
- this.oldTime = this.startTime;
- this.running = true;
- };
- THREE.Clock.prototype.stop = function () {
- this.getElapsedTime();
- this.running = false;
- };
- THREE.Clock.prototype.getElapsedTime = function () {
- this.getDelta();
- return this.elapsedTime;
- };
- THREE.Clock.prototype.getDelta = function () {
- var diff = 0;
- if ( this.autoStart && ! this.running ) {
- this.start();
- }
- if ( this.running ) {
- var newTime = performance.now !== undefined ? performance.now() : Date.now();
- diff = 0.001 * ( newTime - this.oldTime );
- this.oldTime = newTime;
- this.elapsedTime += diff;
- }
- return diff;
- };
|