Skip to content

Instantly share code, notes, and snippets.

Created October 18, 2017 13:31
Show Gist options
  • Select an option

  • Save anonymous/7e2882490c0ef09dc856b518dd2f7b8a to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/7e2882490c0ef09dc856b518dd2f7b8a to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/puradikike
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var rOld=[0.997095,-0.0395677,0.0650849,0.0455955,0.994537,-0.0939016,-0.0610139,0.0965963,0.993452];
var rNew=[0.997103,-0.0393574,0.0650828,0.0453777,0.994559,-0.0937723,-0.0610381,0.096454,0.993464];
//var sinceHand = sinceFrame.hand(this.id);
var transposed = transpose(create(), rNew);
var m = multiply(create(), rOld, transposed);
console.log(m);
function create() {
var out = new Float32Array(9);
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 1;
out[5] = 0;
out[6] = 0;
out[7] = 0;
out[8] = 1;
return out;
}
function transpose(out, a) {
// If we are transposing ourselves we can skip a few steps but have to cache some values
if (out === a) {
var a01 = a[1], a02 = a[2], a12 = a[5]
out[1] = a[3]
out[2] = a[6]
out[3] = a01
out[5] = a[7]
out[6] = a02
out[7] = a12
} else {
out[0] = a[0]
out[1] = a[3]
out[2] = a[6]
out[3] = a[1]
out[4] = a[4]
out[5] = a[7]
out[6] = a[2]
out[7] = a[5]
out[8] = a[8]
}
return out
}
function multiply(out, a, b) {
var a00 = a[0], a01 = a[1], a02 = a[2]
var a10 = a[3], a11 = a[4], a12 = a[5]
var a20 = a[6], a21 = a[7], a22 = a[8]
var b00 = b[0], b01 = b[1], b02 = b[2]
var b10 = b[3], b11 = b[4], b12 = b[5]
var b20 = b[6], b21 = b[7], b22 = b[8]
out[0] = b00 * a00 + b01 * a10 + b02 * a20
out[1] = b00 * a01 + b01 * a11 + b02 * a21
out[2] = b00 * a02 + b01 * a12 + b02 * a22
out[3] = b10 * a00 + b11 * a10 + b12 * a20
out[4] = b10 * a01 + b11 * a11 + b12 * a21
out[5] = b10 * a02 + b11 * a12 + b12 * a22
out[6] = b20 * a00 + b21 * a10 + b22 * a20
out[7] = b20 * a01 + b21 * a11 + b22 * a21
out[8] = b20 * a02 + b21 * a12 + b22 * a22
return out
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">var rOld=[0.997095,-0.0395677,0.0650849,0.0455955,0.994537,-0.0939016,-0.0610139,0.0965963,0.993452];
var rNew=[0.997103,-0.0393574,0.0650828,0.0453777,0.994559,-0.0937723,-0.0610381,0.096454,0.993464];
//var sinceHand = sinceFrame.hand(this.id);
var transposed = transpose(create(), rNew);
var m = multiply(create(), rOld, transposed);
console.log(m);
function create() {
var out = new Float32Array(9);
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 1;
out[5] = 0;
out[6] = 0;
out[7] = 0;
out[8] = 1;
return out;
}
function transpose(out, a) {
// If we are transposing ourselves we can skip a few steps but have to cache some values
if (out === a) {
var a01 = a[1], a02 = a[2], a12 = a[5]
out[1] = a[3]
out[2] = a[6]
out[3] = a01
out[5] = a[7]
out[6] = a02
out[7] = a12
} else {
out[0] = a[0]
out[1] = a[3]
out[2] = a[6]
out[3] = a[1]
out[4] = a[4]
out[5] = a[7]
out[6] = a[2]
out[7] = a[5]
out[8] = a[8]
}
return out
}
function multiply(out, a, b) {
var a00 = a[0], a01 = a[1], a02 = a[2]
var a10 = a[3], a11 = a[4], a12 = a[5]
var a20 = a[6], a21 = a[7], a22 = a[8]
var b00 = b[0], b01 = b[1], b02 = b[2]
var b10 = b[3], b11 = b[4], b12 = b[5]
var b20 = b[6], b21 = b[7], b22 = b[8]
out[0] = b00 * a00 + b01 * a10 + b02 * a20
out[1] = b00 * a01 + b01 * a11 + b02 * a21
out[2] = b00 * a02 + b01 * a12 + b02 * a22
out[3] = b10 * a00 + b11 * a10 + b12 * a20
out[4] = b10 * a01 + b11 * a11 + b12 * a21
out[5] = b10 * a02 + b11 * a12 + b12 * a22
out[6] = b20 * a00 + b21 * a10 + b22 * a20
out[7] = b20 * a01 + b21 * a11 + b22 * a21
out[8] = b20 * a02 + b21 * a12 + b22 * a22
return out
}</script></body>
</html>
var rOld=[0.997095,-0.0395677,0.0650849,0.0455955,0.994537,-0.0939016,-0.0610139,0.0965963,0.993452];
var rNew=[0.997103,-0.0393574,0.0650828,0.0453777,0.994559,-0.0937723,-0.0610381,0.096454,0.993464];
//var sinceHand = sinceFrame.hand(this.id);
var transposed = transpose(create(), rNew);
var m = multiply(create(), rOld, transposed);
console.log(m);
function create() {
var out = new Float32Array(9);
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 1;
out[5] = 0;
out[6] = 0;
out[7] = 0;
out[8] = 1;
return out;
}
function transpose(out, a) {
// If we are transposing ourselves we can skip a few steps but have to cache some values
if (out === a) {
var a01 = a[1], a02 = a[2], a12 = a[5]
out[1] = a[3]
out[2] = a[6]
out[3] = a01
out[5] = a[7]
out[6] = a02
out[7] = a12
} else {
out[0] = a[0]
out[1] = a[3]
out[2] = a[6]
out[3] = a[1]
out[4] = a[4]
out[5] = a[7]
out[6] = a[2]
out[7] = a[5]
out[8] = a[8]
}
return out
}
function multiply(out, a, b) {
var a00 = a[0], a01 = a[1], a02 = a[2]
var a10 = a[3], a11 = a[4], a12 = a[5]
var a20 = a[6], a21 = a[7], a22 = a[8]
var b00 = b[0], b01 = b[1], b02 = b[2]
var b10 = b[3], b11 = b[4], b12 = b[5]
var b20 = b[6], b21 = b[7], b22 = b[8]
out[0] = b00 * a00 + b01 * a10 + b02 * a20
out[1] = b00 * a01 + b01 * a11 + b02 * a21
out[2] = b00 * a02 + b01 * a12 + b02 * a22
out[3] = b10 * a00 + b11 * a10 + b12 * a20
out[4] = b10 * a01 + b11 * a11 + b12 * a21
out[5] = b10 * a02 + b11 * a12 + b12 * a22
out[6] = b20 * a00 + b21 * a10 + b22 * a20
out[7] = b20 * a01 + b21 * a11 + b22 * a21
out[8] = b20 * a02 + b21 * a12 + b22 * a22
return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment