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