Skip to content

Commit

Permalink
Added math function: rotationTranslationMat4
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Aug 26, 2016
1 parent 5204f92 commit 5bf05a3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/core/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,56 @@
return SceneJS_math_scalingMat4c(s, s, s);
};

/**
* Creates a matrix from a quaternion rotation and vector translation
*
* @param {Float32Array} q Rotation quaternion
* @param {Float32Array} v Translation vector
* @param {Float32Array} dest Destination matrix
* @returns {Float32Array} dest
*/
window.SceneJS_math_rotationTranslationMat4 = function (q, v, dest) {

dest = dest || SceneJS_math_mat4();

var x = q[0];
var y = q[1];
var z = q[2];
var w = q[3];

var x2 = x + x;
var y2 = y + y;
var z2 = z + z;
var xx = x * x2;
var xy = x * y2;
var xz = x * z2;
var yy = y * y2;
var yz = y * z2;
var zz = z * z2;
var wx = w * x2;
var wy = w * y2;
var wz = w * z2;

dest[0] = 1 - (yy + zz);
dest[1] = xy + wz;
dest[2] = xz - wy;
dest[3] = 0;
dest[4] = xy - wz;
dest[5] = 1 - (xx + zz);
dest[6] = yz + wx;
dest[7] = 0;
dest[8] = xz + wy;
dest[9] = yz - wx;
dest[10] = 1 - (xx + yy);
dest[11] = 0;
dest[12] = v[0];
dest[13] = v[1];
dest[14] = v[2];
dest[15] = 1;

return dest;
};

/**
* Default lookat properties - eye at 0,0,1, looking at 0,0,0, up vector pointing up Y-axis
*/
Expand Down

0 comments on commit 5bf05a3

Please sign in to comment.