diff options
author | Kruti Shah | 2012-07-17 12:40:00 -0700 |
---|---|---|
committer | Kruti Shah | 2012-07-17 12:40:00 -0700 |
commit | bf2d7bdb22c28089dc1067bc9094ebc590daac87 (patch) | |
tree | 2156d9920ea1b7db49ed6460545fea7cda121bae /js/helper-classes/RDGE/src/core/script/animation.js | |
parent | 7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff) | |
parent | b4b3e45d6684e77d361b4f8ca5be4889428320c5 (diff) | |
download | ninja-bf2d7bdb22c28089dc1067bc9094ebc590daac87.tar.gz |
Merge branch 'refs/heads/TimelineUberJD' into Timeline-local-kruti
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/animation.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/animation.js | 691 |
1 files changed, 346 insertions, 345 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/animation.js b/js/helper-classes/RDGE/src/core/script/animation.js index 2e13cce6..5564179d 100755 --- a/js/helper-classes/RDGE/src/core/script/animation.js +++ b/js/helper-classes/RDGE/src/core/script/animation.js | |||
@@ -1,345 +1,346 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | |
5 | 5 | Redistribution and use in source and binary forms, with or without | |
6 | Redistribution and use in source and binary forms, with or without | 6 | modification, are permitted provided that the following conditions are met: |
7 | modification, are permitted provided that the following conditions are met: | 7 | |
8 | 8 | * Redistributions of source code must retain the above copyright notice, | |
9 | - Redistributions of source code must retain the above copyright notice, | 9 | this list of conditions and the following disclaimer. |
10 | this list of conditions and the following disclaimer. | 10 | |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
12 | notice, this list of conditions and the following disclaimer in the | 12 | this list of conditions and the following disclaimer in the documentation |
13 | documentation and/or other materials provided with the distribution. | 13 | and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | |
15 | may be used to endorse or promote products derived from this software | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | without specific prior written permission. | 16 | contributors may be used to endorse or promote products derived from this |
17 | 17 | software without specific prior written permission. | |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | </copyright> */ | 29 | POSSIBILITY OF SUCH DAMAGE. |
30 | 30 | </copyright> */ | |
31 | // RDGE namespaces | 31 | |
32 | var RDGE = RDGE || {}; | 32 | // RDGE namespaces |
33 | RDGE.animation = RDGE.animation || {}; | 33 | var RDGE = RDGE || {}; |
34 | 34 | RDGE.animation = RDGE.animation || {}; | |
35 | /** | 35 | |
36 | * channelController | 36 | /** |
37 | * The channel controller is really the workhorse of the RDGE animation system. It handles timing, | 37 | * channelController |
38 | * interpolation, and sampling of attributes over the lifetime of an animation. Each channel controller | 38 | * The channel controller is really the workhorse of the RDGE animation system. It handles timing, |
39 | * is responsible for animating a single attribute. The current implementation supports animating vector, | 39 | * interpolation, and sampling of attributes over the lifetime of an animation. Each channel controller |
40 | * boolean, or quaternion attributes. This class is used internally by the animation system. | 40 | * is responsible for animating a single attribute. The current implementation supports animating vector, |
41 | * | 41 | * boolean, or quaternion attributes. This class is used internally by the animation system. |
42 | * @param _animation - the animation resource | 42 | * |
43 | * @param _channel - the channel id | 43 | * @param _animation - the animation resource |
44 | * | 44 | * @param _channel - the channel id |
45 | */ | 45 | * |
46 | RDGE.animation.channelController = function (_animation, _channel) { | 46 | */ |
47 | /** | 47 | RDGE.animation.channelController = function (_animation, _channel) { |
48 | * this.interpolate - Enable/Disable interpolation between animation frames. | 48 | /** |
49 | * Typically this should be enabled for smoother looking animation. However, | 49 | * this.interpolate - Enable/Disable interpolation between animation frames. |
50 | * there may be applications where interpolation is undesireable. | 50 | * Typically this should be enabled for smoother looking animation. However, |
51 | */ | 51 | * there may be applications where interpolation is undesireable. |
52 | this.interpolate = false; | 52 | */ |
53 | 53 | this.interpolate = false; | |
54 | /** | 54 | |
55 | * this.animation - the animation resource. | 55 | /** |
56 | * This is where the keyframes for the channel are stored. | 56 | * this.animation - the animation resource. |
57 | */ | 57 | * This is where the keyframes for the channel are stored. |
58 | this.animation = _animation; | 58 | */ |
59 | 59 | this.animation = _animation; | |
60 | /** | 60 | |
61 | * this.channel - the channel id. This is used to look up the keyframe data for this channel. | 61 | /** |
62 | */ | 62 | * this.channel - the channel id. This is used to look up the keyframe data for this channel. |
63 | this.channel = _channel; | 63 | */ |
64 | 64 | this.channel = _channel; | |
65 | /** | 65 | |
66 | * this.localTime - the current time, relative to the start time. | 66 | /** |
67 | */ | 67 | * this.localTime - the current time, relative to the start time. |
68 | this.localTime = 0.0; | 68 | */ |
69 | 69 | this.localTime = 0.0; | |
70 | /** | 70 | |
71 | * this.startTime - the start time of the animation clip window. | 71 | /** |
72 | */ | 72 | * this.startTime - the start time of the animation clip window. |
73 | this.startTime = this.animation.clipStart / this.animation.framesPerSec; | 73 | */ |
74 | 74 | this.startTime = this.animation.clipStart / this.animation.framesPerSec; | |
75 | /** | 75 | |
76 | * this.endTime - the end time of the animation clip window. | 76 | /** |
77 | */ | 77 | * this.endTime - the end time of the animation clip window. |
78 | this.endTime = this.animation.clipEnd / this.animation.framesPerSec; | 78 | */ |
79 | 79 | this.endTime = this.animation.clipEnd / this.animation.framesPerSec; | |
80 | /** | 80 | |
81 | * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls. | 81 | /** |
82 | */ | 82 | * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls. |
83 | this.cachedFrame = -1; | 83 | */ |
84 | 84 | this.cachedFrame = -1; | |
85 | /** | 85 | |
86 | * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations. | 86 | /** |
87 | */ | 87 | * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations. |
88 | oneFrameInSecs = 1.0 / _animation.framesPerSec; | 88 | */ |
89 | 89 | oneFrameInSecs = 1.0 / _animation.framesPerSec; | |
90 | /** | 90 | |
91 | * this.channel.timeline - stores the animation timeline. | 91 | /** |
92 | * Currently this is calculated based on the framePerSec settings of the animation. | 92 | * this.channel.timeline - stores the animation timeline. |
93 | * Eventually the timeline should be exported with the animation. Individual channels | 93 | * Currently this is calculated based on the framePerSec settings of the animation. |
94 | * may have different timelines depending on which frames are keyed. | 94 | * Eventually the timeline should be exported with the animation. Individual channels |
95 | */ | 95 | * may have different timelines depending on which frames are keyed. |
96 | this.channel.timeline = new Array(this.channel.numKeys + 1); | 96 | */ |
97 | for (i = 0; i <= this.channel.numKeys; ++i) { | 97 | this.channel.timeline = new Array(this.channel.numKeys + 1); |
98 | this.channel.timeline[i] = i / this.animation.framesPerSec; | 98 | for (i = 0; i <= this.channel.numKeys; ++i) { |
99 | } | 99 | this.channel.timeline[i] = i / this.animation.framesPerSec; |
100 | 100 | } | |
101 | /** this.computeFrame | 101 | |
102 | * Calculates the current frame index of the animation at the current time. | 102 | /** this.computeFrame |
103 | * In the worst case, this function will perform a binary search for the frame | 103 | * Calculates the current frame index of the animation at the current time. |
104 | * whose time is closest to and less than the current time. In the best case, | 104 | * In the worst case, this function will perform a binary search for the frame |
105 | * the current frame is near the most recently cached frame, or it remains unchanged. | 105 | * whose time is closest to and less than the current time. In the best case, |
106 | */ | 106 | * the current frame is near the most recently cached frame, or it remains unchanged. |
107 | this.computeFrame = function () { | 107 | */ |
108 | var absTime = this.localTime + this.startTime; | 108 | this.computeFrame = function () { |
109 | var start = this.animation.clipStart; | 109 | var absTime = this.localTime + this.startTime; |
110 | var end = this.animation.clipEnd; | 110 | var start = this.animation.clipStart; |
111 | 111 | var end = this.animation.clipEnd; | |
112 | if (this.cachedFrame != -1) { | 112 | |
113 | // if the current time is reasonably close to the last frame processed try searching | 113 | if (this.cachedFrame != -1) { |
114 | // forward or backward. best case it is the next frame. | 114 | // if the current time is reasonably close to the last frame processed try searching |
115 | if (Math.abs(absTime - this.channel.timeline[this.cachedFrame]) < 5 * oneFrameInSecs) { | 115 | // forward or backward. best case it is the next frame. |
116 | if (this.channel.timeline[this.cachedFrame] < absTime) { | 116 | if (Math.abs(absTime - this.channel.timeline[this.cachedFrame]) < 5 * oneFrameInSecs) { |
117 | while (this.channel.timeline[this.cachedFrame + 1] <= absTime) { | 117 | if (this.channel.timeline[this.cachedFrame] < absTime) { |
118 | this.cachedFrame++; | 118 | while (this.channel.timeline[this.cachedFrame + 1] <= absTime) { |
119 | if (this.animation.looping) { | 119 | this.cachedFrame++; |
120 | if (this.cachedFrame > this.numFrames - 1) { | 120 | if (this.animation.looping) { |
121 | this.cachedFrame -= this.numFrames - 1; | 121 | if (this.cachedFrame > this.numFrames - 1) { |
122 | } | 122 | this.cachedFrame -= this.numFrames - 1; |
123 | } else { | 123 | } |
124 | if (this.cachedFrame > this.numFrames - 1) { | 124 | } else { |
125 | this.cachedFrame = this.numFrames - 1; | 125 | if (this.cachedFrame > this.numFrames - 1) { |
126 | } | 126 | this.cachedFrame = this.numFrames - 1; |