aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/animation.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/animation.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/animation.js77
1 files changed, 39 insertions, 38 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..9eee36ba 100755
--- a/js/helper-classes/RDGE/src/core/script/animation.js
+++ b/js/helper-classes/RDGE/src/core/script/animation.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -32,11 +33,11 @@ POSSIBILITY OF SUCH DAMAGE.
32var RDGE = RDGE || {}; 33var RDGE = RDGE || {};
33RDGE.animation = RDGE.animation || {}; 34RDGE.animation = RDGE.animation || {};
34 35
35/** 36/**
36 * channelController 37 * channelController
37 * The channel controller is really the workhorse of the RDGE animation system. It handles timing, 38 * The channel controller is really the workhorse of the RDGE animation system. It handles timing,
38 * interpolation, and sampling of attributes over the lifetime of an animation. Each channel controller 39 * interpolation, and sampling of attributes over the lifetime of an animation. Each channel controller
39 * is responsible for animating a single attribute. The current implementation supports animating vector, 40 * is responsible for animating a single attribute. The current implementation supports animating vector,
40 * boolean, or quaternion attributes. This class is used internally by the animation system. 41 * boolean, or quaternion attributes. This class is used internally by the animation system.
41 * 42 *
42 * @param _animation - the animation resource 43 * @param _animation - the animation resource
@@ -44,16 +45,16 @@ RDGE.animation = RDGE.animation || {};
44 * 45 *
45 */ 46 */
46RDGE.animation.channelController = function (_animation, _channel) { 47RDGE.animation.channelController = function (_animation, _channel) {
47 /** 48 /**
48 * this.interpolate - Enable/Disable interpolation between animation frames. 49 * this.interpolate - Enable/Disable interpolation between animation frames.
49 * Typically this should be enabled for smoother looking animation. However, 50 * Typically this should be enabled for smoother looking animation. However,
50 * there may be applications where interpolation is undesireable. 51 * there may be applications where interpolation is undesireable.
51 */ 52 */
52 this.interpolate = false; 53 this.interpolate = false;
53 54
54 /** 55 /**
55 * this.animation - the animation resource. 56 * this.animation - the animation resource.
56 * This is where the keyframes for the channel are stored. 57 * This is where the keyframes for the channel are stored.
57 */ 58 */
58 this.animation = _animation; 59 this.animation = _animation;
59 60
@@ -77,20 +78,20 @@ RDGE.animation.channelController = function (_animation, _channel) {
77 */ 78 */
78 this.endTime = this.animation.clipEnd / this.animation.framesPerSec; 79 this.endTime = this.animation.clipEnd / this.animation.framesPerSec;
79 80
80 /** 81 /**
81 * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls. 82 * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls.
82 */ 83 */
83 this.cachedFrame = -1; 84 this.cachedFrame = -1;
84 85
85 /** 86 /**
86 * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations. 87 * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations.
87 */ 88 */
88 oneFrameInSecs = 1.0 / _animation.framesPerSec; 89 oneFrameInSecs = 1.0 / _animation.framesPerSec;
89 90
90 /** 91 /**
91 * this.channel.timeline - stores the animation timeline. 92 * this.channel.timeline - stores the animation timeline.
92 * Currently this is calculated based on the framePerSec settings of the animation. 93 * Currently this is calculated based on the framePerSec settings of the animation.
93 * Eventually the timeline should be exported with the animation. Individual channels 94 * Eventually the timeline should be exported with the animation. Individual channels
94 * may have different timelines depending on which frames are keyed. 95 * may have different timelines depending on which frames are keyed.
95 */ 96 */
96 this.channel.timeline = new Array(this.channel.numKeys + 1); 97 this.channel.timeline = new Array(this.channel.numKeys + 1);
@@ -98,11 +99,11 @@ RDGE.animation.channelController = function (_animation, _channel) {
98 this.channel.timeline[i] = i / this.animation.framesPerSec; 99 this.channel.timeline[i] = i / this.animation.framesPerSec;
99 } 100 }
100 101
101 /** this.computeFrame 102 /** this.computeFrame
102 * Calculates the current frame index of the animation at the current time. 103 * Calculates the current frame index of the animation at the current time.
103 * In the worst case, this function will perform a binary search for the frame 104 * In the worst case, this function will perform a binary search for the frame
104 * whose time is closest to and less than the current time. In the best case, 105 * whose time is closest to and less than the current time. In the best case,
105 * the current frame is near the most recently cached frame, or it remains unchanged. 106 * the current frame is near the most recently cached frame, or it remains unchanged.
106 */ 107 */
107 this.computeFrame = function () { 108 this.computeFrame = function () {
108 var absTime = this.localTime + this.startTime; 109 var absTime = this.localTime + this.startTime;
@@ -146,7 +147,7 @@ RDGE.animation.channelController = function (_animation, _channel) {
146 } 147 }
147 } 148 }
148 149
149 // binary search... 150 // binary search...
150 while (start + 1 < end) { 151 while (start + 1 < end) {
151 var mid = Math.floor((start + end) / 2); 152 var mid = Math.floor((start + end) / 2);
152 if (absTime > this.channel.timeline[mid]) { 153 if (absTime > this.channel.timeline[mid]) {
@@ -262,9 +263,9 @@ RDGE.animation.channelController = function (_animation, _channel) {
262 }; 263 };
263}; 264};
264 265
265/** 266/**
266 * track 267 * track
267 * Each track advances and samples from a list of channel controllers, and is assigned to a scene graph node. 268 * Each track advances and samples from a list of channel controllers, and is assigned to a scene graph node.
268 * 269 *
269 * @param _animation - the animation resource 270 * @param _animation - the animation resource
270 * @param _track - the track id 271 * @param _track - the track id