diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math/quat.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/quat.js | 501 |
1 files changed, 251 insertions, 250 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/math/quat.js b/js/helper-classes/RDGE/src/core/script/math/quat.js index a3812084..8c9d0228 100755 --- a/js/helper-classes/RDGE/src/core/script/math/quat.js +++ b/js/helper-classes/RDGE/src/core/script/math/quat.js | |||
@@ -1,250 +1,251 @@ | |||
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 | 31 | ||
32 | /** | 32 | |
33 | * RDGE.quat = {} | 33 | /** |
34 | * This library contains utility functions for operating on quaternions. | 34 | * RDGE.quat = {} |
35 | * -- | 35 | * This library contains utility functions for operating on quaternions. |
36 | * TODO: | 36 | * -- |
37 | * -need to add more helper functions for generating quaternions from | 37 | * TODO: |
38 | * other representations (i.e. - eulers, angle-axis). | 38 | * -need to add more helper functions for generating quaternions from |
39 | */ | 39 | * other representations (i.e. - eulers, angle-axis). |
40 | var RDGE = RDGE || {}; | 40 | */ |
41 | RDGE.quat = {}; | 41 | var RDGE = RDGE || {}; |
42 | 42 | RDGE.quat = {}; | |
43 | /** | 43 | |
44 | * RDGE.quat.string | 44 | /** |
45 | */ | 45 | * RDGE.quat.string |
46 | RDGE.quat.string = function (q) { | 46 | */ |
47 | return "{ " + q[0] + ", " + q[1] + ", " + q[2] + ", " + q[3] + " }"; | 47 | RDGE.quat.string = function (q) { |
48 | }; | 48 | return "{ " + q[0] + ", " + q[1] + ", " + q[2] + ", " + q[3] + " }"; |
49 | 49 | }; | |
50 | /** | 50 | |
51 | * RDGE.quat.verify | 51 | /** |
52 | */ | 52 | * RDGE.quat.verify |
53 | RDGE.quat.verify = function (q) { | 53 | */ |
54 | if (q == undefined || q.length == undefined || q.length < 4) { | 54 | RDGE.quat.verify = function (q) { |
55 | return false; | 55 | if (q == undefined || q.length == undefined || q.length < 4) { |
56 | } | 56 | return false; |
57 | 57 | } | |
58 | if (typeof (q[0]) != "number" || typeof (q[1]) != "number" || typeof (q[2]) != "number" || typeof (q[3]) != "number") { | 58 | |
59 | return false; | 59 | if (typeof (q[0]) != "number" || typeof (q[1]) != "number" || typeof (q[2]) != "number" || typeof (q[3]) != "number") { |
60 | } | 60 | return false; |
61 | 61 | } | |
62 | return true; | 62 | |
63 | }; | 63 | return true; |
64 | 64 | }; | |
65 | /** | 65 | |
66 | * RDGE.quat.identity | 66 | /** |
67 | */ | 67 | * RDGE.quat.identity |
68 | RDGE.quat.identity = function () { | 68 | */ |
69 | return [0.0, 0.0, 0.0, 1.0]; | 69 | RDGE.quat.identity = function () { |
70 | }; | 70 | return [0.0, 0.0, 0.0, 1.0]; |
71 | 71 | }; | |
72 | /** | 72 | |
73 | * RDGE.quat.add | 73 | /** |
74 | */ | 74 | * RDGE.quat.add |
75 | RDGE.quat.add = function (a, b) { | 75 | */ |
76 | return [a[0] + b[0], | 76 | RDGE.quat.add = function (a, b) { |
77 | a[1] + b[1], | 77 | return [a[0] + b[0], |
78 | a[2] + b[2], | 78 | a[1] + b[1], |
79 | a[3] + b[3]]; | 79 | a[2] + b[2], |
80 | }; | 80 | a[3] + b[3]]; |
81 | 81 | }; | |
82 | /** | 82 | |
83 | * RDGE.quat.sub | 83 | /** |
84 | */ | 84 | * RDGE.quat.sub |
85 | RDGE.quat.sub = function (a, b) { | 85 | */ |
86 | return [a[0] - b[0], | 86 | RDGE.quat.sub = function (a, b) { |
87 | a[1] - b[1], | 87 | return [a[0] - b[0], |
88 | a[2] - b[2], | 88 | a[1] - b[1], |
89 | a[3] - b[3]]; | 89 | a[2] - b[2], |
90 | }; | 90 | a[3] - b[3]]; |
91 | 91 | }; | |
92 | /** | 92 | |
93 | * RDGE.quat.mul | 93 | /** |
94 | */ | 94 | * RDGE.quat.mul |
95 | RDGE.quat.mul = function (a, b) { | 95 | */ |
96 | return [a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2], | 96 | RDGE.quat.mul = function (a, b) { |
97 | a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1], | 97 | return [a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2], |
98 | a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0], | 98 | a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1], |
99 | a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3]]; | 99 | a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0], |
100 | }; | 100 | a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3]]; |
101 | 101 | }; | |
102 | /** | 102 | |
103 | * RDGE.quat.addMul | 103 | /** |
104 | */ | 104 | * RDGE.quat.addMul |
105 | RDGE.quat.addMul = function (a, b, s) { | 105 | */ |
106 | if (s.length != undefined && s.length >= 4) { | 106 | RDGE.quat.addMul = function (a, b, s) { |
107 | return [a[0] + b[0] * s[0], a[1] + b[1] * s[1], a[2] + b[2] * s[2], a[3] + b[3] * s[3]]; | 107 | if (s.length != undefined && s.length >= 4) { |
108 | } else { | 108 | return [a[0] + b[0] * s[0], a[1] + b[1] * s[1], a[2] + b[2] * s[2], a[3] + b[3] * s[3]]; |
109 | return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s, a[3] + b[3] * s]; | 109 | } else { |
110 | } | 110 | return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s, a[3] + b[3] * s]; |
111 | }; | 111 | } |
112 | 112 | }; | |
113 | 113 | ||
114 | /** | 114 | |
115 | * RDGE.quat.scale | 115 | /** |
116 | */ | 116 | * RDGE.quat.scale |
117 | RDGE.quat.scale = function (q, s) { | 117 | */ |
118 | if (s.length != undefined && s.length >= 4) { | 118 | RDGE.quat.scale = function (q, s) { |
119 | return [q[0] * s[0], q[1] * q[1], q[2] * s[2], q[3] * s[3]]; | 119 | if (s.length != undefined && s.length >= 4) { |
120 | } else { | 120 | return [q[0] * s[0], q[1] * q[1], q[2] * s[2], q[3] * s[3]]; |
121 | return [q[0] * s, q[1] * s, q[2] * s, q[3] * s]; | 121 | } else { |
122 | } | 122 | return [q[0] * s, q[1] * s, q[2] * s, q[3] * s]; |
123 | }; | 123 | } |
124 | 124 | }; | |
125 | /** | 125 | |
126 | * RDGE.quat.lengthSq | 126 | /** |
127 | */ | 127 | * RDGE.quat.lengthSq |
128 | RDGE.quat.lengthSq = function (q) { | 128 | */ |
129 | return q[0] * q[0] + | 129 | RDGE.quat.lengthSq = function (q) { |
130 | q[1] * q[1] + | 130 | return q[0] * q[0] + |
131 | q[2] * q[2] + | 131 | q[1] * q[1] + |
132 | q[3] * q[3]; | 132 | q[2] * q[2] + |
133 | }; | 133 | q[3] * q[3]; |
134 | 134 | }; | |
135 | /** | 135 | |
136 | * RDGE.quat.length | 136 | /** |
137 | */ | 137 | * RDGE.quat.length |
138 | RDGE.quat.length = function (q) { | 138 | */ |
139 | return Math.sqrt(q[0] * q[0] + |