OSDN Git Service

three.jsをThirdPartyに追加
[webglgame/webgl_framework.git] / webglFramework / Thirdparty / three.js-master / src / core / Clock.js
1 /**
2  * @author alteredq / http://alteredqualia.com/
3  */
4
5 function Clock( autoStart ) {
6
7         this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
8
9         this.startTime = 0;
10         this.oldTime = 0;
11         this.elapsedTime = 0;
12
13         this.running = false;
14
15 }
16
17 Object.assign( Clock.prototype, {
18
19         start: function () {
20
21                 this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
22
23                 this.oldTime = this.startTime;
24                 this.elapsedTime = 0;
25                 this.running = true;
26
27         },
28
29         stop: function () {
30
31                 this.getElapsedTime();
32                 this.running = false;
33                 this.autoStart = false;
34
35         },
36
37         getElapsedTime: function () {
38
39                 this.getDelta();
40                 return this.elapsedTime;
41
42         },
43
44         getDelta: function () {
45
46                 var diff = 0;
47
48                 if ( this.autoStart && ! this.running ) {
49
50                         this.start();
51                         return 0;
52
53                 }
54
55                 if ( this.running ) {
56
57                         var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
58
59                         diff = ( newTime - this.oldTime ) / 1000;
60                         this.oldTime = newTime;
61
62                         this.elapsedTime += diff;
63
64                 }
65
66                 return diff;
67
68         }
69
70 } );
71
72
73 export { Clock };