diff options
author | Ananya Sen | 2012-04-17 18:11:55 -0700 |
---|---|---|
committer | Ananya Sen | 2012-04-17 18:11:55 -0700 |
commit | 35abad196cc9feb76ef50c1b63032a38233a6d51 (patch) | |
tree | 914689c66d4ab6c6e088b571eade0a0e35082916 /js/helper-classes/RDGE/src/core/script/math/quat.js | |
parent | 1f891c58bad0b7746659aa4138001b5ee76d9a0e (diff) | |
parent | 616a8532099fec2a15855eac97cd85cb60c4451c (diff) | |
download | ninja-35abad196cc9feb76ef50c1b63032a38233a6d51.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into Codeview-improvements
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 | 237 |
1 files changed, 119 insertions, 118 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 5c2c8bb6..f3c44d11 100755 --- a/js/helper-classes/RDGE/src/core/script/math/quat.js +++ b/js/helper-classes/RDGE/src/core/script/math/quat.js | |||
@@ -6,210 +6,211 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | 7 | ||
8 | /** | 8 | /** |
9 | * quat = {} | 9 | * RDGE.quat = {} |
10 | * This library contains utility functions for operating on quaternions. | 10 | * This library contains utility functions for operating on quaternions. |
11 | * -- | 11 | * -- |
12 | * TODO: | 12 | * TODO: |
13 | * -need to add more helper functions for generating quaternions from | 13 | * -need to add more helper functions for generating quaternions from |
14 | * other representations (i.e. - eulers, angle-axis). | 14 | * other representations (i.e. - eulers, angle-axis). |
15 | */ | 15 | */ |
16 | quat = {} | 16 | var RDGE = RDGE || {}; |
17 | RDGE.quat = {}; | ||
17 | 18 | ||
18 | /** | 19 | /** |
19 | * vec4.string | 20 | * RDGE.quat.string |
20 | */ | 21 | */ |
21 | quat.string = function(q) { | 22 | RDGE.quat.string = function (q) { |
22 | return "{ " + q[0] + ", " + q[1] + ", " + q[2] + ", " + q[3] + " }"; | 23 | return "{ " + q[0] + ", " + q[1] + ", " + q[2] + ", " + q[3] + " }"; |
23 | } | 24 | }; |
24 | 25 | ||
25 | /** | 26 | /** |
26 | * quat.verify | 27 | * RDGE.quat.verify |
27 | */ | 28 | */ |
28 | quat.verify = function(q) { | 29 | RDGE.quat.verify = function (q) { |
29 | if (q == undefined || q.length == undefined || q.length < 4) { | 30 | if (q == undefined || q.length == undefined || q.length < 4) { |
30 | return false; | 31 | return false; |
31 | } | 32 | } |
32 | 33 | ||
33 | if (typeof (q[0]) != "number" || typeof (q[1]) != "number" || typeof (q[2]) != "number" || typeof (q[3]) != "number") { | 34 | if (typeof (q[0]) != "number" || typeof (q[1]) != "number" || typeof (q[2]) != "number" || typeof (q[3]) != "number") { |
34 | return false; | 35 | return false; |
35 | } | 36 | } |
36 | 37 | ||
37 | return true; | 38 | return true; |
38 | } | 39 | }; |
39 | 40 | ||
40 | /** | 41 | /** |
41 | * quat.identity | 42 | * RDGE.quat.identity |
42 | */ | 43 | */ |
43 | quat.identity = function() { | 44 | RDGE.quat.identity = function () { |
44 | return [0.0, 0.0, 0.0, 1.0]; | 45 | return [0.0, 0.0, 0.0, 1.0]; |
45 | } | 46 | }; |
46 | 47 | ||
47 | /** | 48 | /** |
48 | * quat.add | 49 | * RDGE.quat.add |
49 | */ | 50 | */ |
50 | quat.add = function(a, b) { | 51 | RDGE.quat.add = function (a, b) { |
51 | return [ a[0] + b[0], | 52 | return [a[0] + b[0], |
52 | a[1] + b[1], | 53 | a[1] + b[1], |
53 | a[2] + b[2], | 54 | a[2] + b[2], |
54 | a[3] + b[3]]; | 55 | a[3] + b[3]]; |
55 | } | 56 | }; |
56 | 57 | ||
57 | /** | 58 | /** |
58 | * quat.sub | 59 | * RDGE.quat.sub |
59 | */ | 60 | */ |
60 | quat.sub = function(a, b) { | 61 | RDGE.quat.sub = function (a, b) { |
61 | return [ a[0] - b[0], | 62 | return [a[0] - b[0], |
62 | a[1] - b[1], | 63 | a[1] - b[1], |
63 | a[2] - b[2], | 64 | a[2] - b[2], |
64 | a[3] - b[3]]; | 65 | a[3] - b[3]]; |
65 | } | 66 | }; |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * quat.mul | 69 | * RDGE.quat.mul |
69 | */ | 70 | */ |
70 | quat.mul = function( a, b ) { | 71 | RDGE.quat.mul = function (a, b) { |
71 | return [ a[3]*b[3] - a[0]*b[0] - a[1]*b[1] - a[2]*b[2], | 72 | return [a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2], |
72 | a[3]*b[0] + a[0]*b[3] + a[1]*b[2] - a[2]*b[1], | 73 | a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1], |
73 | a[3]*b[1] - a[0]*b[2] + a[1]*b[3] + a[2]*b[0], | 74 | a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0], |
74 | a[3]*b[2] + a[0]*b[1] - a[1]*b[0] + a[2]*b[3] ]; | 75 | a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3]]; |
75 | } | 76 | }; |
76 | 77 | ||
77 | /** | 78 | /** |
78 | * quat.addMul | 79 | * RDGE.quat.addMul |
79 | */ | 80 | */ |
80 | quat.addMul = function(a, b, s) { | 81 | RDGE.quat.addMul = function (a, b, s) { |
81 | if (s.length != undefined && s.length >= 4) { | 82 | if (s.length != undefined && s.length >= 4) { |
82 | 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]]; | 83 | 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]]; |
83 | } else { | 84 | } else { |
84 | return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s, a[3] + b[3] * s]; | 85 | return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s, a[3] + b[3] * s]; |
85 | } | 86 | } |
86 | } | 87 | }; |
87 | 88 | ||
88 | 89 | ||
89 | /** | 90 | /** |
90 | * quat.scale | 91 | * RDGE.quat.scale |
91 | */ | 92 | */ |
92 | quat.scale = function(q, s) { | 93 | RDGE.quat.scale = function (q, s) { |
93 | if (s.length != undefined && s.length >= 4) { | 94 | if (s.length != undefined && s.length >= 4) { |
94 | return [q[0] * s[0], q[1] * q[1], q[2] * s[2], q[3] * s[3]]; | 95 | return [q[0] * s[0], q[1] * q[1], q[2] * s[2], q[3] * s[3]]; |
95 | } else { | 96 | } else { |
96 | return [q[0] * s, q[1] * s, q[2] * s, q[3] * s]; | 97 | return [q[0] * s, q[1] * s, q[2] * s, q[3] * s]; |
97 | } | 98 | } |
98 | } | 99 | }; |
99 | 100 | ||
100 | /** | 101 | /** |
101 | * quat.lengthSq | 102 | * RDGE.quat.lengthSq |
102 | */ | 103 | */ |
103 | quat.lengthSq = function(q) { | 104 | RDGE.quat.lengthSq = function (q) { |
104 | return q[0] * q[0] + | 105 | return q[0] * q[0] + |
105 | q[1] * q[1] + | 106 | q[1] * q[1] + |
106 | q[2] * q[2] + | 107 | q[2] * q[2] + |
107 | q[3] * q[3]; | 108 | q[3] * q[3]; |
108 | } | 109 | }; |
109 | 110 | ||
110 | /** | 111 | /** |
111 | * quat.length | 112 | * RDGE.quat.length |
112 | */ | 113 | */ |
113 | quat.length = function(q) { | 114 | RDGE.quat.length = function (q) { |
114 | return Math.sqrt( q[0] * q[0] + | 115 | return Math.sqrt(q[0] * q[0] + |
115 | q[1] * q[1] + | 116 | q[1] * q[1] + |
116 | q[2] * q[2] + | 117 | q[2] * q[2] + |
117 | q[3] * q[3]); | 118 | q[3] * q[3]); |
118 | } | 119 | }; |
119 | 120 | ||
120 | /** | 121 | /** |
121 | * quat.normalize | 122 | * RDGE.quat.normalize |
122 | */ | 123 | */ |
123 | quat.normalize = function(q) { | 124 | RDGE.quat.normalize = function (q) { |
124 | var l = Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); | 125 | var l = Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); |
125 | if (Math.abs(1.0 - l) > 0.0001) { | 126 | if (Math.abs(1.0 - l) > 0.0001) { |
126 | var ool = 1.0 / l; | 127 | var ool = 1.0 / l; |
127 | return [q[0] * ool, q[1] * ool, q[2] * ool, q[3] * ool]; | 128 | return [q[0] * ool, q[1] * ool, q[2] * ool, q[3] * ool]; |
128 | } | 129 | } |
129 | return q; | 130 | return q; |
130 | } | 131 | }; |
131 | 132 | ||
132 | /** | 133 | /** |
133 | * quat.inverse | 134 | * RDGE.quat.inverse |
134 | */ | 135 | */ |
135 | quat.inverse = function(q) { |