diff options
author | Valerio Virgillito | 2012-04-04 15:58:49 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-04-04 15:58:49 -0700 |
commit | 347b4179be5581841fc94825dcb18901e625c670 (patch) | |
tree | 93556d56b049aa47c615a8b58add230cd96da166 /js/helper-classes/RDGE/src/core/script/animation.js | |
parent | 9f1806a7134ec4744a8009e6a7467f5cea04cabf (diff) | |
parent | e721a7c1009f298a1bd8fea583da14535e039880 (diff) | |
download | ninja-347b4179be5581841fc94825dcb18901e625c670.tar.gz |
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/animation.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/animation.js | 191 |
1 files changed, 95 insertions, 96 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/animation.js b/js/helper-classes/RDGE/src/core/script/animation.js index 63eca0a2..c82a0e76 100755 --- a/js/helper-classes/RDGE/src/core/script/animation.js +++ b/js/helper-classes/RDGE/src/core/script/animation.js | |||
@@ -4,8 +4,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var g_numChannels = new stat( "animation", "numChannels", 0, null, false ); | 7 | // RDGE namespaces |
8 | var g_numTracks = new stat( "animation", "numTracks", 0, null, false ); | 8 | var RDGE = RDGE || {}; |
9 | RDGE.animation = RDGE.animation || {}; | ||
9 | 10 | ||
10 | /** | 11 | /** |
11 | * channelController | 12 | * channelController |
@@ -18,68 +19,68 @@ var g_numTracks = new stat( "animation", "numTracks", 0, null, false ); | |||
18 | * @param _channel - the channel id | 19 | * @param _channel - the channel id |
19 | * | 20 | * |
20 | */ | 21 | */ |
21 | channelController = function(_animation, _channel) { | 22 | RDGE.animation.channelController = function (_animation, _channel) { |
22 | /** | 23 | /** |
23 | * this.interpolate - Enable/Disable interpolation between animation frames. | 24 | * this.interpolate - Enable/Disable interpolation between animation frames. |
24 | * Typically this should be enabled for smoother looking animation. However, | 25 | * Typically this should be enabled for smoother looking animation. However, |
25 | * there may be applications where interpolation is undesireable. | 26 | * there may be applications where interpolation is undesireable. |
26 | */ | 27 | */ |
27 | this.interpolate = false; | 28 | this.interpolate = false; |
28 | 29 | ||
29 | /** | 30 | /** |
30 | * this.animation - the animation resource. | 31 | * this.animation - the animation resource. |
31 | * This is where the keyframes for the channel are stored. | 32 | * This is where the keyframes for the channel are stored. |
32 | */ | 33 | */ |
33 | this.animation = _animation; | 34 | this.animation = _animation; |
34 | 35 | ||
35 | /** | 36 | /** |
36 | * this.channel - the channel id. This is used to look up the keyframe data for this channel. | 37 | * this.channel - the channel id. This is used to look up the keyframe data for this channel. |
37 | */ | 38 | */ |
38 | this.channel = _channel; | 39 | this.channel = _channel; |
39 | 40 | ||
40 | /** | 41 | /** |
41 | * this.localTime - the current time, relative to the start time. | 42 | * this.localTime - the current time, relative to the start time. |
42 | */ | 43 | */ |
43 | this.localTime = 0.0; | 44 | this.localTime = 0.0; |
44 | 45 | ||
45 | /** | 46 | /** |
46 | * this.startTime - the start time of the animation clip window. | 47 | * this.startTime - the start time of the animation clip window. |
47 | */ | 48 | */ |
48 | this.startTime = this.animation.clipStart / this.animation.framesPerSec; | 49 | this.startTime = this.animation.clipStart / this.animation.framesPerSec; |
49 | 50 | ||
50 | /** | 51 | /** |
51 | * this.endTime - the end time of the animation clip window. | 52 | * this.endTime - the end time of the animation clip window. |
52 | */ | 53 | */ |
53 | this.endTime = this.animation.clipEnd / this.animation.framesPerSec; | 54 | this.endTime = this.animation.clipEnd / this.animation.framesPerSec; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls. | 57 | * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls. |
57 | */ | 58 | */ |
58 | this.cachedFrame = -1; | 59 | this.cachedFrame = -1; |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations. | 62 | * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations. |
62 | */ | 63 | */ |
63 | oneFrameInSecs = 1.0 / _animation.framesPerSec; | 64 | oneFrameInSecs = 1.0 / _animation.framesPerSec; |
64 | 65 | ||
65 | /** | 66 | /** |
66 | * this.channel.timeline - stores the animation timeline. | 67 | * this.channel.timeline - stores the animation timeline. |
67 | * Currently this is calculated based on the framePerSec settings of the animation. | 68 | * Currently this is calculated based on the framePerSec settings of the animation. |
68 | * Eventually the timeline should be exported with the animation. Individual channels | 69 | * Eventually the timeline should be exported with the animation. Individual channels |
69 | * may have different timelines depending on which frames are keyed. | 70 | * may have different timelines depending on which frames are keyed. |
70 | */ | 71 | */ |
71 | this.channel.timeline = new Array(this.channel.numKeys + 1); | 72 | this.channel.timeline = new Array(this.channel.numKeys + 1); |
72 | for (i = 0; i <= this.channel.numKeys; ++i) { | 73 | for (i = 0; i <= this.channel.numKeys; ++i) { |
73 | this.channel.timeline[i] = i / this.animation.framesPerSec; | 74 | this.channel.timeline[i] = i / this.animation.framesPerSec; |
74 | } | 75 | } |
75 | 76 | ||
76 | /** this.computeFrame | 77 | /** this.computeFrame |
77 | * Calculates the current frame index of the animation at the current time. | 78 | * Calculates the current frame index of the animation at the current time. |
78 | * In the worst case, this function will perform a binary search for the frame | 79 | * In the worst case, this function will perform a binary search for the frame |
79 | * whose time is closest to and less than the current time. In the best case, | 80 | * whose time is closest to and less than the current time. In the best case, |
80 | * the current frame is near the most recently cached frame, or it remains unchanged. | 81 | * the current frame is near the most recently cached frame, or it remains unchanged. |
81 | */ | 82 | */ |
82 | this.computeFrame = function() { | 83 | this.computeFrame = function () { |
83 | var absTime = this.localTime + this.startTime; | 84 | var absTime = this.localTime + this.startTime; |
84 | var start = this.animation.clipStart; | 85 | var start = this.animation.clipStart; |
85 | var end = this.animation.clipEnd; | 86 | var end = this.animation.clipEnd; |
@@ -134,21 +135,21 @@ channelController = function(_animation, _channel) { | |||
134 | this.cachedFrame = start; | 135 | this.cachedFrame = start; |
135 | 136 | ||
136 | return start; | 137 | return start; |
137 | } | 138 | }; |
138 | 139 | ||
139 | /* this.sampleBool - Sample a boolean at the current frame, booleans are not interpolated. | 140 | /* this.sampleBool - Sample a boolean at the current frame, booleans are not interpolated. |
140 | * This function is used internally. | 141 | * This function is used internally. |
141 | */ | 142 | */ |
142 | this.sampleBool = function() { | 143 | this.sampleBool = function () { |
143 | // no interpolation on flags... | 144 | // no interpolation on flags... |
144 | var index = this.computeFrame(); | 145 | var index = this.computeFrame(); |
145 | return this.channel.keys[index]; | 146 | return this.channel.keys[index]; |
146 | } | 147 | }; |
147 | 148 | ||
148 | /* this.sampleQuat - Sample a quaternion at the current frame. | 149 | /* this.sampleQuat - Sample a quaternion at the current frame. |
149 | * if this.interpolate == true, quaternions are interpolated inbetween frames using spherical linear interpolation (SLERP). | 150 | * if this.interpolate == true, quaternions are interpolated inbetween frames using spherical linear interpolation (SLERP). |
150 | */ | 151 | */ |
151 | this.sampleQuat = function() { | 152 | this.sampleQuat = function () { |
152 | var frame0 = this.computeFrame(); | 153 | var frame0 = this.computeFrame(); |
153 | var frame1 = frame0 + 1; | 154 | var frame1 = frame0 + 1; |
154 | 155 | ||
@@ -162,16 +163,16 @@ channelController = function(_animation, _channel) { | |||
162 | var t = (absTime - k0) / (k1 - k0); | 163 | var t = (absTime - k0) / (k1 - k0); |
163 | var a = [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2], this.channel.keys[index0 + 3]]; | 164 | var a = [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2], this.channel.keys[index0 + 3]]; |
164 | var b = [this.channel.keys[index1 + 0], this.channel.keys[index1 + 1], this.channel.keys[index1 + 2], this.channel.keys[index1 + 3]]; | 165 | var b = [this.channel.keys[index1 + 0], this.channel.keys[index1 + 1], this.channel.keys[index1 + 2], this.channel.keys[index1 + 3]]; |
165 | return quat.slerp(a, b, t); | 166 | return RDGE.quat.slerp(a, b, t); |
166 | } | 167 | } |
167 | 168 | ||
168 | return [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2], this.channel.keys[index0 + 3]]; | 169 | return [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2], this.channel.keys[index0 + 3]]; |
169 | } | 170 | }; |
170 | 171 | ||
171 | /* this.sampleVec3 - Sample a vector3 at the current frame. | 172 | /* this.sampleVec3 - Sample a vector3 at the current frame. |
172 | * if this.interpolate == true, vectors are interpolated inbetween frames using linear interpolation (LERP). | 173 | * if this.interpolate == true, vectors are interpolated inbetween frames using linear interpolation (LERP). |
173 | */ | 174 | */ |
174 | this.sampleVec3 = function() { | 175 | this.sampleVec3 = function () { |
175 | var frame0 = this.computeFrame(); | 176 | var frame0 = this.computeFrame(); |
176 | var frame1 = frame0 + 1; | 177 | var frame1 = frame0 + 1; |
177 | 178 | ||
@@ -186,14 +187,14 @@ channelController = function(_animation, _channel) { | |||
186 | var a = [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2]]; | 187 | var a = [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2]]; |
187 | var b = [this.channel.keys[index1 + 0], this.channel.keys[index1 + 1], this.channel.keys[index1 + 2]]; | 188 | var b = [this.channel.keys[index1 + 0], this.channel.keys[index1 + 1], this.channel.keys[index1 + 2]]; |
188 | 189 | ||
189 | return vec3.lerp(a, b, t); | 190 | return RDGE.vec3.lerp(a, b, t); |
190 | } | 191 | } |
191 | return [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2]]; | 192 | return [this.channel.keys[index0 + 0], this.channel.keys[index0 + 1], this.channel.keys[index0 + 2]]; |
192 | } | 193 | }; |
193 | 194 | ||
194 | /* this.setTime - set the current time. | 195 | /* this.setTime - set the current time. |
195 | */ | 196 | */ |
196 | this.setTime = function(t) { | 197 | this.setTime = function (t) { |