diff options
author | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
commit | 84b3327bd92faafab7954b5eb64c7abe24a3fe13 (patch) | |
tree | 3f56cbed2f08c5a81ea79eaf0bcb9bd031d8a627 /js/helper-classes/RDGE/src/core/script/animation.js | |
parent | c0a42c56f768a873ba637f5b86d5f6a84d4a3312 (diff) | |
parent | 40c6eb2c06b34f65a74d59ef9687251952858bab (diff) | |
download | ninja-84b3327bd92faafab7954b5eb64c7abe24a3fe13.tar.gz |
Merge branch 'normalize' of https://github.com/kriskowal/ninja-internal
Conflicts:
js/components/gradientpicker.reel/gradientpicker.js
js/components/tools-properties/text-properties.reel/text-properties.js
js/document/views/base.js
js/document/views/design.js
js/helper-classes/3D/StageLine.js
js/helper-classes/3D/draw-utils.js
js/lib/drawing/world.js
js/lib/geom/circle.js
js/lib/geom/line.js
js/lib/geom/rectangle.js
js/lib/geom/shape-primitive.js
js/lib/rdge/materials/bump-metal-material.js
js/lib/rdge/materials/flag-material.js
js/lib/rdge/materials/fly-material.js
js/lib/rdge/materials/julia-material.js
js/lib/rdge/materials/keleidoscope-material.js
js/lib/rdge/materials/mandel-material.js
js/lib/rdge/materials/material.js
js/lib/rdge/materials/plasma-material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/radial-gradient-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/water-material.js
js/panels/Materials/materials-library-panel.reel/materials-library-panel.html
js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
js/panels/Materials/materials-popup.reel/materials-popup.html
js/panels/Materials/materials-popup.reel/materials-popup.js
js/tools/LineTool.js
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/animation.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/animation.js | 690 |
1 files changed, 345 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..0a4826c5 100755 --- a/js/helper-classes/RDGE/src/core/script/animation.js +++ b/js/helper-classes/RDGE/src/core/script/animation.js | |||
@@ -1,345 +1,345 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, are permitted provided that the following conditions are met: |
8 | 8 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 9 | - Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 10 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | - Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the | 12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. | 13 | documentation and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | - Neither the name of Motorola Mobility nor the names of its contributors |
15 | may be used to endorse or promote products derived from this software | 15 | may be used to endorse or promote products derived from this software |
16 | without specific prior written permission. | 16 | without specific prior written permission. |
17 | 17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | // RDGE namespaces | 31 | // RDGE namespaces |
32 | var RDGE = RDGE || {}; | 32 | var RDGE = RDGE || {}; |
33 | RDGE.animation = RDGE.animation || {}; | 33 | RDGE.animation = RDGE.animation || {}; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * channelController | 36 | * channelController |
37 | * The channel controller is really the workhorse of the RDGE animation system. It handles timing, | 37 | * 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 | 38 | * 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, | 39 | * 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. | 40 | * boolean, or quaternion attributes. This class is used internally by the animation system. |
41 | * | 41 | * |
42 | * @param _animation - the animation resource | 42 | * @param _animation - the animation resource |
43 | * @param _channel - the channel id | 43 | * @param _channel - the channel id |
44 | * | 44 | * |
45 | */ | 45 | */ |
46 | RDGE.animation.channelController = function (_animation, _channel) { | 46 | RDGE.animation.channelController = function (_animation, _channel) { |
47 | /** | 47 | /** |
48 | * this.interpolate - Enable/Disable interpolation between animation frames. | 48 | * this.interpolate - Enable/Disable interpolation between animation frames. |
49 | * Typically this should be enabled for smoother looking animation. However, | 49 | * Typically this should be enabled for smoother looking animation. However, |
50 | * there may be applications where interpolation is undesireable. | 50 | * there may be applications where interpolation is undesireable. |
51 | */ | 51 | */ |
52 | this.interpolate = false; | 52 | this.interpolate = false; |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * this.animation - the animation resource. | 55 | * this.animation - the animation resource. |
56 | * This is where the keyframes for the channel are stored. | 56 | * This is where the keyframes for the channel are stored. |
57 | */ | 57 | */ |
58 | this.animation = _animation; | 58 | this.animation = _animation; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * this.channel - the channel id. This is used to look up the keyframe data for this channel. | 61 | * this.channel - the channel id. This is used to look up the keyframe data for this channel. |
62 | */ | 62 | */ |
63 | this.channel = _channel; | 63 | this.channel = _channel; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * this.localTime - the current time, relative to the start time. | 66 | * this.localTime - the current time, relative to the start time. |
67 | */ | 67 | */ |
68 | this.localTime = 0.0; | 68 | this.localTime = 0.0; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * this.startTime - the start time of the animation clip window. | 71 | * this.startTime - the start time of the animation clip window. |
72 | */ | 72 | */ |
73 | this.startTime = this.animation.clipStart / this.animation.framesPerSec; | 73 | this.startTime = this.animation.clipStart / this.animation.framesPerSec; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * this.endTime - the end time of the animation clip window. | 76 | * this.endTime - the end time of the animation clip window. |
77 | */ | 77 | */ |
78 | this.endTime = this.animation.clipEnd / this.animation.framesPerSec; | 78 | this.endTime = this.animation.clipEnd / this.animation.framesPerSec; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls. | 81 | * this.cachedFrame - cached frame index, this optimizes best case scenario computeFrame calls. |
82 | */ | 82 | */ |
83 | this.cachedFrame = -1; | 83 | this.cachedFrame = -1; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations. | 86 | * oneFrameInSecs - stores the interval of a single frame in seconds. This is used for internal calculations. |
87 | */ | 87 | */ |
88 | oneFrameInSecs = 1.0 / _animation.framesPerSec; | 88 | oneFrameInSecs = 1.0 / _animation.framesPerSec; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * this.channel.timeline - stores the animation timeline. | 91 | * this.channel.timeline - stores the animation timeline. |
92 | * Currently this is calculated based on the framePerSec settings of the animation. | 92 | * Currently this is calculated based on the framePerSec settings of the animation. |
93 | * Eventually the timeline should be exported with the animation. Individual channels | 93 | * Eventually the timeline should be exported with the animation. Individual channels |
94 | * may have different timelines depending on which frames are keyed. | 94 | * may have different timelines depending on which frames are keyed. |
95 | */ | 95 | */ |
96 | this.channel.timeline = new Array(this.channel.numKeys + 1); | 96 | this.channel.timeline = new Array(this.channel.numKeys + 1); |
97 | for (i = 0; i <= this.channel.numKeys; ++i) { | 97 | for (i = 0; i <= this.channel.numKeys; ++i) { |
98 | this.channel.timeline[i] = i / this.animation.framesPerSec; | 98 | this.channel.timeline[i] = i / this.animation.framesPerSec; |
99 | } | 99 | } |
100 | 100 | ||
101 | /** this.computeFrame | 101 | /** this.computeFrame |
102 | * Calculates the current frame index of the animation at the current time. | 102 | * 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 | 103 | * 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, | 104 | * 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. | 105 | * the current frame is near the most recently cached frame, or it remains unchanged. |
106 | */ | 106 | */ |
107 | this.computeFrame = function () { | 107 | this.computeFrame = function () { |
108 | var absTime = this.localTime + this.startTime; | 108 | var absTime = this.localTime + this.startTime; |
109 | var start = this.animation.clipStart; | 109 | var start = this.animation.clipStart; |
110 | var end = this.animation.clipEnd; | 110 | var end = this.animation.clipEnd; |
111 | 111 | ||
112 | if (this.cachedFrame != -1) { | 112 | if (this.cachedFrame != -1) { |
113 | // if the current time is reasonably close to the last frame processed try searching | 113 | // if the current time is reasonably close to the last frame processed try searching |
114 | // forward or backward. best case it is the next frame. | 114 | // forward or backward. best case it is the next frame. |
115 | if (Math.abs(absTime - this.channel.timeline[this.cachedFrame]) < 5 * oneFrameInSecs) { | 115 | if (Math.abs(absTime - this.channel.timeline[this.cachedFrame]) < 5 * oneFrameInSecs) { |
116 | if (this.channel.timeline[this.cachedFrame] < absTime) { | 116 | if (this.channel.timeline[this.cachedFrame] < absTime) { |
117 | while (this.channel.timeline[this.cachedFrame + 1] <= absTime) { | 117 | while (this.channel.timeline[this.cachedFrame + 1] <= |