aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/math/quat.js
diff options
context:
space:
mode:
authorKris Kowal2012-07-06 11:52:06 -0700
committerKris Kowal2012-07-06 15:01:48 -0700
commit648ee61ae84216d0236e0dbc211addc13b2cfa3a (patch)
tree8f0f55557bd0c47a84e49c1977c950645d284607 /js/helper-classes/RDGE/src/core/script/math/quat.js
parentaedd14b18695d031f695d27dfbd94df5614495bb (diff)
downloadninja-648ee61ae84216d0236e0dbc211addc13b2cfa3a.tar.gz
Expand tabs
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math/quat.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/math/quat.js64
1 files changed, 32 insertions, 32 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..d243a7ba 100755
--- a/js/helper-classes/RDGE/src/core/script/math/quat.js
+++ b/js/helper-classes/RDGE/src/core/script/math/quat.js
@@ -34,8 +34,8 @@ POSSIBILITY OF SUCH DAMAGE.
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*/
40var RDGE = RDGE || {}; 40var RDGE = RDGE || {};
41RDGE.quat = {}; 41RDGE.quat = {};
@@ -74,9 +74,9 @@ RDGE.quat.identity = function () {
74*/ 74*/
75RDGE.quat.add = function (a, b) { 75RDGE.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/**
@@ -84,9 +84,9 @@ RDGE.quat.add = function (a, b) {
84*/ 84*/
85RDGE.quat.sub = function (a, b) { 85RDGE.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/**
@@ -94,9 +94,9 @@ RDGE.quat.sub = function (a, b) {
94*/ 94*/
95RDGE.quat.mul = function (a, b) { 95RDGE.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/**
@@ -127,9 +127,9 @@ RDGE.quat.scale = function (q, s) {
127*/ 127*/
128RDGE.quat.lengthSq = function (q) { 128RDGE.quat.lengthSq = function (q) {
129 return q[0] * q[0] + 129 return q[0] * q[0] +
130 q[1] * q[1] + 130 q[1] * q[1] +
131 q[2] * q[2] + 131 q[2] * q[2] +
132 q[3] * q[3]; 132 q[3] * q[3];
133}; 133};
134 134
135/** 135/**
@@ -137,9 +137,9 @@ RDGE.quat.lengthSq = function (q) {
137*/ 137*/
138RDGE.quat.length = function (q) { 138RDGE.quat.length = function (q) {
139 return Math.sqrt(q[0] * q[0] + 139 return Math.sqrt(q[0] * q[0] +
140 q[1] * q[1] + 140 q[1] * q[1] +
141 q[2] * q[2] + 141 q[2] * q[2] +
142 q[3] * q[3]); 142 q[3] * q[3]);
143}; 143};
144 144
145/** 145/**
@@ -193,22 +193,22 @@ RDGE.quat.lerp = function (q0, q1, t) {
193* RDGE.quat.slerp 193* RDGE.quat.slerp
194*/ 194*/
195RDGE.quat.slerp = function (q0, q1, t) { 195RDGE.quat.slerp = function (q0, q1, t) {
196 var c = RDGE.quat.dot(q0, q1); // cosine of the angle 196 var c = RDGE.quat.dot(q0, q1); // cosine of the angle
197 197
198 // just lerp if the quats are "close" enough 198 // just lerp if the quats are "close" enough
199 if (c >= 0.9) { 199 if (c >= 0.9) {
200 return RDGE.quat.lerp(q0, q1, t); 200 return RDGE.quat.lerp(q0, q1, t);
201 } 201 }
202 202
203 var s = Math.sqrt(Math.abs(1.0 - c * c)); // sine of the angle 203 var s = Math.sqrt(Math.abs(1.0 - c * c)); // sine of the angle
204 if (s < 0.001) 204 if (s < 0.001)
205 return q0; // too close 205 return q0; // too close
206 206
207 var sign = c < 0.0 ? -1.0 : 1.0; 207 var sign = c < 0.0 ? -1.0 : 1.0;
208 var angle = Math.asin(s); 208 var angle = Math.asin(s);
209 209
210 var invs = 1.0 / s; // sine^-1 210 var invs = 1.0 / s; // sine^-1
211 var coef0 = Math.sin((1.0 - t) * angle) * invs; // interp. coefficients 211 var coef0 = Math.sin((1.0 - t) * angle) * invs; // interp. coefficients
212 var coef1 = Math.sin(t * angle) * invs * sign; 212 var coef1 = Math.sin(t * angle) * invs * sign;
213 213
214 RDGE.quat.scale(q0, coef0); 214 RDGE.quat.scale(q0, coef0);
@@ -235,16 +235,16 @@ RDGE.quat.toMatrix = function (q) {
235 var tzz = tz * q[2]; 235 var tzz = tz * q[2];
236 236
237 return [1.0 - (tyy + tzz), 237 return [1.0 - (tyy + tzz),
238 txy + twz, 238 txy + twz,
239 txz - twy, 239 txz - twy,
240 0, 240 0,
241 txy - twz, 241 txy - twz,
242 1.0 - (txx + tzz), 242 1.0 - (txx + tzz),
243 tyz + twx, 243 tyz + twx,
244 0, 244 0,
245 txz + twy, 245 txz + twy,
246 tyz - twx, 246 tyz - twx,
247 1.0 - (txx + tyy), 247 1.0 - (txx + tyy),
248 0, 0, 0, 0, 1]; 248 0, 0, 0, 0, 1];
249}; 249};
250 250