@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
54 lines (44 loc) • 1.29 kB
JavaScript
/**
*
* @param {number[]|Float32Array|mat4} result
* @param { { x:number, y:number, z:number } } position
* @param { { x:number, y:number, z:number, w:number } } rotation
* @param { { x:number, y:number, z:number } } scale
*/
export function compose_matrix4_array(result, position, rotation, scale) {
const x = rotation.x;
const y = rotation.y;
const z = rotation.z;
const w = rotation.w;
const x2 = x + x;
const y2 = y + y;
const z2 = z + z;
const xx = x * x2;
const xy = x * y2;
const xz = x * z2;
const yy = y * y2;
const yz = y * z2;
const zz = z * z2;
const wx = w * x2;
const wy = w * y2;
const wz = w * z2;
const sx = scale.x;
const sy = scale.y;
const sz = scale.z;
result[0] = (1 - (yy + zz)) * sx;
result[1] = (xy + wz) * sx;
result[2] = (xz - wy) * sx;
result[3] = 0;
result[4] = (xy - wz) * sy;
result[5] = (1 - (xx + zz)) * sy;
result[6] = (yz + wx) * sy;
result[7] = 0;
result[8] = (xz + wy) * sz;
result[9] = (yz - wx) * sz;
result[10] = (1 - (xx + yy)) * sz;
result[11] = 0;
result[12] = position.x;
result[13] = position.y;
result[14] = position.z;
result[15] = 1;
}