Clock.js 911 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.Clock = function ( autoStart ) {
  5. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  6. this.startTime = 0;
  7. this.oldTime = 0;
  8. this.elapsedTime = 0;
  9. this.running = false;
  10. };
  11. THREE.Clock.prototype = {
  12. constructor: THREE.Clock,
  13. start: function () {
  14. this.startTime = self.performance.now();
  15. this.oldTime = this.startTime;
  16. this.running = true;
  17. },
  18. stop: function () {
  19. this.getElapsedTime();
  20. this.running = false;
  21. },
  22. getElapsedTime: function () {
  23. this.getDelta();
  24. return this.elapsedTime;
  25. },
  26. getDelta: function () {
  27. var diff = 0;
  28. if ( this.autoStart && ! this.running ) {
  29. this.start();
  30. }
  31. if ( this.running ) {
  32. var newTime = self.performance.now();
  33. diff = 0.001 * ( newTime - this.oldTime );
  34. this.oldTime = newTime;
  35. this.elapsedTime += diff;
  36. }
  37. return diff;
  38. }
  39. };
粤ICP备19079148号