Last change
on this file since 28897 was 28897, checked in by davidb, 10 years ago |
GUI front-end to server base plus web page content
|
File size:
1.1 KB
|
Line | |
---|
1 | /**
|
---|
2 | * @author alteredq / http://alteredqualia.com/
|
---|
3 | */
|
---|
4 |
|
---|
5 | THREE.Clock = function ( 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 | THREE.Clock.prototype = {
|
---|
18 |
|
---|
19 | constructor: THREE.Clock,
|
---|
20 |
|
---|
21 | start: function () {
|
---|
22 |
|
---|
23 | this.startTime = self.performance !== undefined && self.performance.now !== undefined
|
---|
24 | ? self.performance.now()
|
---|
25 | : Date.now();
|
---|
26 |
|
---|
27 | this.oldTime = this.startTime;
|
---|
28 | this.running = true;
|
---|
29 | },
|
---|
30 |
|
---|
31 | stop: function () {
|
---|
32 |
|
---|
33 | this.getElapsedTime();
|
---|
34 | this.running = false;
|
---|
35 |
|
---|
36 | },
|
---|
37 |
|
---|
38 | getElapsedTime: function () {
|
---|
39 |
|
---|
40 | this.getDelta();
|
---|
41 | return this.elapsedTime;
|
---|
42 |
|
---|
43 | },
|
---|
44 |
|
---|
45 | getDelta: function () {
|
---|
46 |
|
---|
47 | var diff = 0;
|
---|
48 |
|
---|
49 | if ( this.autoStart && ! this.running ) {
|
---|
50 |
|
---|
51 | this.start();
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | if ( this.running ) {
|
---|
56 |
|
---|
57 | var newTime = self.performance !== undefined && self.performance.now !== undefined
|
---|
58 | ? self.performance.now()
|
---|
59 | : Date.now();
|
---|
60 |
|
---|
61 | diff = 0.001 * ( newTime - this.oldTime );
|
---|
62 | this.oldTime = newTime;
|
---|
63 |
|
---|
64 | this.elapsedTime += diff;
|
---|
65 |
|
---|
66 | }
|
---|
67 |
|
---|
68 | return diff;
|
---|
69 |
|
---|
70 | }
|
---|
71 |
|
---|
72 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.