MCPcopy Create free account
hub / github.com/microsoft/SandDance / fromMat3

Function fromMat3

docs/app/js/sanddance-app.js:75225–75253  ·  view source on GitHub ↗
(out, m)

Source from the content-addressed store, hash-verified

75223 return out;
75224}
75225function fromMat3(out, m) {
75226 // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
75227 // article "Quaternion Calculus and Fast Animation".
75228 var fTrace = m[0] + m[4] + m[8];
75229 var fRoot;
75230 if (fTrace > 0.0) {
75231 // |w| > 1/2, may as well choose w > 1/2
75232 fRoot = Math.sqrt(fTrace + 1.0); // 2w
75233 out[3] = 0.5 * fRoot;
75234 fRoot = 0.5 / fRoot; // 1/(4w)
75235 out[0] = (m[5] - m[7]) * fRoot;
75236 out[1] = (m[6] - m[2]) * fRoot;
75237 out[2] = (m[1] - m[3]) * fRoot;
75238 } else {
75239 // |w| <= 1/2
75240 var i = 0;
75241 if (m[4] > m[0]) i = 1;
75242 if (m[8] > m[i * 3 + i]) i = 2;
75243 var j = (i + 1) % 3;
75244 var k = (i + 2) % 3;
75245 fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
75246 out[i] = 0.5 * fRoot;
75247 fRoot = 0.5 / fRoot;
75248 out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
75249 out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
75250 out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
75251 }
75252 return out;
75253}
75254function fromEuler(out, x, y, z) {
75255 var halfToRad = 0.5 * Math.PI / 180.0;
75256 x *= halfToRad;

Callers 1

sanddance-app.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected