# 谁能解释一下glMatrix中的几个函数。

``````mat4.multiply = function(mat, mat2, dest) {
if(!dest) { dest = mat }

// Cache the matrix values (makes for huge speed increases!)
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];

var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];

dest[0] = b00*a00 + b01*a10 + b02*a20 + b03*a30;
dest[1] = b00*a01 + b01*a11 + b02*a21 + b03*a31;
dest[2] = b00*a02 + b01*a12 + b02*a22 + b03*a32;
dest[3] = b00*a03 + b01*a13 + b02*a23 + b03*a33;
dest[4] = b10*a00 + b11*a10 + b12*a20 + b13*a30;
dest[5] = b10*a01 + b11*a11 + b12*a21 + b13*a31;
dest[6] = b10*a02 + b11*a12 + b12*a22 + b13*a32;
dest[7] = b10*a03 + b11*a13 + b12*a23 + b13*a33;
dest[8] = b20*a00 + b21*a10 + b22*a20 + b23*a30;
dest[9] = b20*a01 + b21*a11 + b22*a21 + b23*a31;
dest[10] = b20*a02 + b21*a12 + b22*a22 + b23*a32;
dest[11] = b20*a03 + b21*a13 + b22*a23 + b23*a33;
dest[12] = b30*a00 + b31*a10 + b32*a20 + b33*a30;
dest[13] = b30*a01 + b31*a11 + b32*a21 + b33*a31;
dest[14] = b30*a02 + b31*a12 + b32*a22 + b33*a32;
dest[15] = b30*a03 + b31*a13 + b32*a23 + b33*a33;

return dest;
};
``````

``````mat4.translate = function(mat, vec, dest) {
var x = vec[0], y = vec[1], z = vec[2];

if(!dest || mat == dest) {
mat[12] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12];
mat[13] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13];
mat[14] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14];
mat[15] = mat[3]*x + mat[7]*y + mat[11]*z + mat[15];
return mat;
}

var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];

dest[0] = a00;
dest[1] = a01;
dest[2] = a02;
dest[3] = a03;
dest[4] = a10;
dest[5] = a11;
dest[6] = a12;
dest[7] = a13;
dest[8] = a20;
dest[9] = a21;
dest[10] = a22;
dest[11] = a23;

dest[12] = a00*x + a10*y + a20*z + mat[12];
dest[13] = a01*x + a11*y + a21*z + mat[13];
dest[14] = a02*x + a12*y + a22*z + mat[14];
dest[15] = a03*x + a13*y + a23*z + mat[15];
return dest;
};``````

###### 你尚未登录，登录后可以
• 和开发者交流问题的细节
• 关注并接收问题和回答的更新提醒
• 参与内容的编辑和改进，让解决方法与时俱进