当前位置: 首页 > news >正文

WebGL矩阵变换库

目录

矩阵变换库:

Matrix4对象所支持的方法和属性如表所示:

方法属性规范: 


虽然平移、旋转、缩放等变换操作都可以用一个4×4的矩阵表示,但是在写WebGL程序的时候,手动计算每个矩阵很耗费时间。为了简化编程,大多数WebGL开发者都使用矩阵操作函数库来隐藏矩阵计算的细节,简化与矩阵有关的操作。目前已经有一些开源的矩阵库。以下是一个比较好的矩阵变换库可供大家学习使用。有了矩阵函数库,进行如“平移,然后旋转”等各种复合的变换就很简单了。

Matrix4是该矩阵库提供的新类型 ,顾名思义,Matrix4对象(实例)表示一个4×4的矩阵。该对象内部使用类型化数组Floated2Array来存储矩阵的元素。

矩阵变换库:

/*** Constructor of Matrix4* If opt_src is specified, new matrix is initialized by opt_src.* Otherwise, new matrix is initialized by identity matrix.* @param opt_src source matrix(option)*/
var Matrix4 = function(opt_src) {var i, s, d;if (opt_src && typeof opt_src === 'object' && opt_src.hasOwnProperty('elements')) {s = opt_src.elements;d = new Float32Array(16);for (i = 0; i < 16; ++i) {d[i] = s[i];}this.elements = d;} else {this.elements = new Float32Array([1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]);}
};/*** Set the identity matrix.* @return this*/
Matrix4.prototype.setIdentity = function() {var e = this.elements;e[0] = 1;   e[4] = 0;   e[8]  = 0;   e[12] = 0;e[1] = 0;   e[5] = 1;   e[9]  = 0;   e[13] = 0;e[2] = 0;   e[6] = 0;   e[10] = 1;   e[14] = 0;e[3] = 0;   e[7] = 0;   e[11] = 0;   e[15] = 1;return this;
};/*** Copy matrix.* @param src source matrix* @return this*/
Matrix4.prototype.set = function(src) {var i, s, d;s = src.elements;d = this.elements;if (s === d) {return;}for (i = 0; i < 16; ++i) {d[i] = s[i];}return this;
};/*** Multiply the matrix from the right.* @param other The multiply matrix* @return this*/
Matrix4.prototype.concat = function(other) {var i, e, a, b, ai0, ai1, ai2, ai3;// Calculate e = a * be = this.elements;a = this.elements;b = other.elements;// If e equals b, copy b to temporary matrix.if (e === b) {b = new Float32Array(16);for (i = 0; i < 16; ++i) {b[i] = e[i];}}for (i = 0; i < 4; i++) {ai0=a[i];  ai1=a[i+4];  ai2=a[i+8];  ai3=a[i+12];e[i]    = ai0 * b[0]  + ai1 * b[1]  + ai2 * b[2]  + ai3 * b[3];e[i+4]  = ai0 * b[4]  + ai1 * b[5]  + ai2 * b[6]  + ai3 * b[7];e[i+8]  = ai0 * b[8]  + ai1 * b[9]  + ai2 * b[10] + ai3 * b[11];e[i+12] = ai0 * b[12] + ai1 * b[13] + ai2 * b[14] + ai3 * b[15];}return this;
};
Matrix4.prototype.multiply = Matrix4.prototype.concat;/*** Multiply the three-dimensional vector.* @param pos  The multiply vector* @return The result of multiplication(Float32Array)*/
Matrix4.prototype.multiplyVector3 = function(pos) {var e = this.elements;var p = pos.elements;var v = new Vector3();var result = v.elements;result[0] = p[0] * e[0] + p[1] * e[4] + p[2] * e[ 8] + e[12];result[1] = p[0] * e[1] + p[1] * e[5] + p[2] * e[ 9] + e[13];result[2] = p[0] * e[2] + p[1] * e[6] + p[2] * e[10] + e[14];return v;
};/*** Multiply the four-dimensional vector.* @param pos  The multiply vector* @return The result of multiplication(Float32Array)*/
Matrix4.prototype.multiplyVector4 = function(pos) {var e = this.elements;var p = pos.elements;var v = new Vector4();var result = v.elements;result[0] = p[0] * e[0] + p[1] * e[4] + p[2] * e[ 8] + p[3] * e[12];result[1] = p[0] * e[1] + p[1] * e[5] + p[2] * e[ 9] + p[3] * e[13];result[2] = p[0] * e[2] + p[1] * e[6] + p[2] * e[10] + p[3] * e[14];result[3] = p[0] * e[3] + p[1] * e[7] + p[2] * e[11] + p[3] * e[15];return v;
};/*** Transpose the matrix.* @return this*/
Matrix4.prototype.transpose = function() {var e, t;e = this.elements;t = e[ 1];  e[ 1] = e[ 4];  e[ 4] = t;t = e[ 2];  e[ 2] = e[ 8];  e[ 8] = t;t = e[ 3];  e[ 3] = e[12];  e[12] = t;t = e[ 6];  e[ 6] = e[ 9];  e[ 9] = t;t = e[ 7];  e[ 7] = e[13];  e[13] = t;t = e[11];  e[11] = e[14];  e[14] = t;return this;
};/*** Calculate the inverse matrix of specified matrix, and set to this.* @param other The source matrix* @return this*/
Matrix4.prototype.setInverseOf = function(other) {var i, s, d, inv, det;s = other.elements;d = this.elements;inv = new Float32Array(16);inv[0]  =   s[5]*s[10]*s[15] - s[5] *s[11]*s[14] - s[9] *s[6]*s[15]+ s[9]*s[7] *s[14] + s[13]*s[6] *s[11] - s[13]*s[7]*s[10];inv[4]  = - s[4]*s[10]*s[15] + s[4] *s[11]*s[14] + s[8] *s[6]*s[15]- s[8]*s[7] *s[14] - s[12]*s[6] *s[11] + s[12]*s[7]*s[10];inv[8]  =   s[4]*s[9] *s[15] - s[4] *s[11]*s[13] - s[8] *s[5]*s[15]+ s[8]*s[7] *s[13] + s[12]*s[5] *s[11] - s[12]*s[7]*s[9];inv[12] = - s[4]*s[9] *s[14] + s[4] *s[10]*s[13] + s[8] *s[5]*s[14]- s[8]*s[6] *s[13] - s[12]*s[5] *s[10] + s[12]*s[6]*s[9];inv[1]  = - s[1]*s[10]*s[15] + s[1] *s[11]*s[14] + s[9] *s[2]*s[15]- s[9]*s[3] *s[14] - s[13]*s[2] *s[11] + s[13]*s[3]*s[10];inv[5]  =   s[0]*s[10]*s[15] - s[0] *s[11]*s[14] - s[8] *s[2]*s[15]+ s[8]*s[3] *s[14] + s[12]*s[2] *s[11] - s[12]*s[3]*s[10];inv[9]  = - s[0]*s[9] *s[15] + s[0] *s[11]*s[13] + s[8] *s[1]*s[15]- s[8]*s[3] *s[13] - s[12]*s[1] *s[11] + s[12]*s[3]*s[9];inv[13] =   s[0]*s[9] *s[14] - s[0] *s[10]*s[13] - s[8] *s[1]*s[14]+ s[8]*s[2] *s[13] + s[12]*s[1] *s[10] - s[12]*s[2]*s[9];inv[2]  =   s[1]*s[6]*s[15] - s[1] *s[7]*s[14] - s[5] *s[2]*s[15]+ s[5]*s[3]*s[14] + s[13]*s[2]*s[7]  - s[13]*s[3]*s[6];inv[6]  = - s[0]*s[6]*s[15] + s[0] *s[7]*s[14] + s[4] *s[2]*s[15]- s[4]*s[3]*s[14] - s[12]*s[2]*s[7]  + s[12]*s[3]*s[6];inv[10] =   s[0]*s[5]*s[15] - s[0] *s[7]*s[13] - s[4] *s[1]*s[15]+ s[4]*s[3]*s[13] + s[12]*s[1]*s[7]  - s[12]*s[3]*s[5];inv[14] = - s[0]*s[5]*s[14] + s[0] *s[6]*s[13] + s[4] *s[1]*s[14]- s[4]*s[2]*s[13] - s[12]*s[1]*s[6]  + s[12]*s[2]*s[5];inv[3]  = - s[1]*s[6]*s[11] + s[1]*s[7]*s[10] + s[5]*s[2]*s[11]- s[5]*s[3]*s[10] - s[9]*s[2]*s[7]  + s[9]*s[3]*s[6];inv[7]  =   s[0]*s[6]*s[11] - s[0]*s[7]*s[10] - s[4]*s[2]*s[11]+ s[4]*s[3]*s[10] + s[8]*s[2]*s[7]  - s[8]*s[3]*s[6];inv[11] = - s[0]*s[5]*s[11] + s[0]*s[7]*s[9]  + s[4]*s[1]*s[11]- s[4]*s[3]*s[9]  - s[8]*s[1]*s[7]  + s[8]*s[3]*s[5];inv[15] =   s[0]*s[5]*s[10] - s[0]*s[6]*s[9]  - s[4]*s[1]*s[10]+ s[4]*s[2]*s[9]  + s[8]*s[1]*s[6]  - s[8]*s[2]*s[5];det = s[0]*inv[0] + s[1]*inv[4] + s[2]*inv[8] + s[3]*inv[12];if (det === 0) {return this;}det = 1 / det;for (i = 0; i < 16; i++) {d[i] = inv[i] * det;}return this;
};/*** Calculate the inverse matrix of this, and set to this.* @return this*/
Matrix4.prototype.invert = function() {return this.setInverseOf(this);
};/*** Set the orthographic projection matrix.* @param left The coordinate of the left of clipping plane.* @param right The coordinate of the right of clipping plane.* @param bottom The coordinate of the bottom of clipping plane.* @param top The coordinate of the top top clipping plane.* @param near The distances to the nearer depth clipping plane. This value is minus if the plane is to be behind the viewer.* @param far The distances to the farther depth clipping plane. This value is minus if the plane is to be behind the viewer.* @return this*/
Matrix4.prototype.setOrtho = function(left, right, bottom, top, near, far) {var e, rw, rh, rd;if (left === right || bottom === top || near === far) {throw 'null frustum';}rw = 1 / (right - left);rh = 1 / (top - bottom);rd = 1 / (far - near);e = this.elements;e[0]  = 2 * rw;e[1]  = 0;e[2]  = 0;e[3]  = 0;e[4]  = 0;e[5]  = 2 * rh;e[6]  = 0;e[7]  = 0;e[8]  = 0;e[9]  = 0;e[10] = -2 * rd;e[11] = 0;e[12] = -(right + left) * rw;e[13] = -(top + bottom) * rh;e[14] = -(far + near) * rd;e[15] = 1;return this;
};/*** Multiply the orthographic projection matrix from the right.* @param left The coordinate of the left of clipping plane.* @param right The coordinate of the right of clipping plane.* @param bottom The coordinate of the bottom of clipping plane.* @param top The coordinate of the top top clipping plane.* @param near The distances to the nearer depth clipping plane. This value is minus if the plane is to be behind the viewer.* @param far The distances to the farther depth clipping plane. This value is minus if the plane is to be behind the viewer.* @return this*/
Matrix4.prototype.ortho = function(left, right, bottom, top, near, far) {return this.concat(new Matrix4().setOrtho(left, right, bottom, top, near, far));
};/*** Set the perspective projection matrix.* @param left The coordinate of the left of clipping plane.* @param right The coordinate of the right of clipping plane.* @param bottom The coordinate of the bottom of clipping plane.* @param top The coordinate of the top top clipping plane.* @param near The distances to the nearer depth clipping plane. This value must be plus value.* @param far The distances to the farther depth clipping plane. This value must be plus value.* @return this*/
Matrix4.prototype.setFrustum = function(left, right, bottom, top, near, far) {var e, rw, rh, rd;if (left === right || top === bottom || near === far) {throw 'null frustum';}if (near <= 0) {throw 'near <= 0';}if (far <= 0) {throw 'far <= 0';}rw = 1 / (right - left);rh = 1 / (top - bottom);rd = 1 / (far - near);e = this.elements;e[ 0] = 2 * near * rw;e[ 1] = 0;e[ 2] = 0;e[ 3] = 0;e[ 4] = 0;e[ 5] = 2 * near * rh;e[ 6] = 0;e[ 7] = 0;e[ 8] = (right + left) * rw;e[ 9] = (top + bottom) * rh;e[10] = -(far + near) * rd;e[11] = -1;e[12] = 0;e[13] = 0;e[14] = -2 * near * far * rd;e[15] = 0;return this;
};/*** Multiply the perspective projection matrix from the right.* @param left The coordinate of the left of clipping plane.* @param right The coordinate of the right of clipping plane.* @param bottom The coordinate of the bottom of clipping plane.* @param top The coordinate of the top top clipping plane.* @param near The distances to the nearer depth clipping plane. This value must be plus value.* @param far The distances to the farther depth clipping plane. This value must be plus value.* @return this*/
Matrix4.prototype.frustum = function(left, right, bottom, top, near, far) {return this.concat(new Matrix4().setFrustum(left, right, bottom, top, near, far));
};/*** Set the perspective projection matrix by fovy and aspect.* @param fovy The angle between the upper and lower sides of the frustum.* @param aspect The aspect ratio of the frustum. (width/height)* @param near The distances to the nearer depth clipping plane. This value must be plus value.* @param far The distances to the farther depth clipping plane. This value must be plus value.* @return this*/
Matrix4.prototype.setPerspective = function(fovy, aspect, near, far) {var e, rd, s, ct;if (near === far || aspect === 0) {throw 'null frustum';}if (near <= 0) {throw 'near <= 0';}if (far <= 0) {throw 'far <= 0';}fovy = Math.PI * fovy / 180 / 2;s = Math.sin(fovy);if (s === 0) {throw 'null frustum';}rd = 1 / (far - near);ct = Math.cos(fovy) / s;e = this.elements;e[0]  = ct / aspect;e[1]  = 0;e[2]  = 0;e[3]  = 0;e[4]  = 0;e[5]  = ct;e[6]  = 0;e[7]  = 0;e[8]  = 0;e[9]  = 0;e[10] = -(far + near) * rd;e[11] = -1;e[12] = 0;e[13] = 0;e[14] = -2 * near * far * rd;e[15] = 0;return this;
};/*** Multiply the perspective projection matrix from the right.* @param fovy The angle between the upper and lower sides of the frustum.* @param aspect The aspect ratio of the frustum. (width/height)* @param near The distances to the nearer depth clipping plane. This value must be plus value.* @param far The distances to the farther depth clipping plane. This value must be plus value.* @return this*/
Matrix4.prototype.perspective = function(fovy, aspect, near, far) {return this.concat(new Matrix4().setPerspective(fovy, aspect, near, far));
};/*** Set the matrix for scaling.* @param x The scale factor along the X axis* @param y The scale factor along the Y axis* @param z The scale factor along the Z axis* @return this*/
Matrix4.prototype.setScale = function(x, y, z) {var e = this.elements;e[0] = x;  e[4] = 0;  e[8]  = 0;  e[12] = 0;e[1] = 0;  e[5] = y;  e[9]  = 0;  e[13] = 0;e[2] = 0;  e[6] = 0;  e[10] = z;  e[14] = 0;e[3] = 0;  e[7] = 0;  e[11] = 0;  e[15] = 1;return this;
};/*** Multiply the matrix for scaling from the right.* @param x The scale factor along the X axis* @param y The scale factor along the Y axis* @param z The scale factor along the Z axis* @return this*/
Matrix4.prototype.scale = function(x, y, z) {var e = this.elements;e[0] *= x;  e[4] *= y;  e[8]  *= z;e[1] *= x;  e[5] *= y;  e[9]  *= z;e[2] *= x;  e[6] *= y;  e[10] *= z;e[3] *= x;  e[7] *= y;  e[11] *= z;return this;
};/*** Set the matrix for translation.* @param x The X value of a translation.* @param y The Y value of a translation.* @param z The Z value of a translation.* @return this*/
Matrix4.prototype.setTranslate = function(x, y, z) {var e = this.elements;e[0] = 1;  e[4] = 0;  e[8]  = 0;  e[12] = x;e[1] = 0;  e[5] = 1;  e[9]  = 0;  e[13] = y;e[2] = 0;  e[6] = 0;  e[10] = 1;  e[14] = z;e[3] = 0;  e[7] = 0;  e[11] = 0;  e[15] = 1;return this;
};/*** Multiply the matrix for translation from the right.* @param x The X value of a translation.* @param y The Y value of a translation.* @param z The Z value of a translation.* @return this*/
Matrix4.prototype.translate = function(x, y, z) {var e = this.elements;e[12] += e[0] * x + e[4] * y + e[8]  * z;e[13] += e[1] * x + e[5] * y + e[9]  * z;e[14] += e[2] * x + e[6] * y + e[10] * z;e[15] += e[3] * x + e[7] * y + e[11] * z;return this;
};/*** Set the matrix for rotation.* The vector of rotation axis may not be normalized.* @param angle The angle of rotation (degrees)* @param x The X coordinate of vector of rotation axis.* @param y The Y coordinate of vector of rotation axis.* @param z The Z coordinate of vector of rotation axis.* @return this*/
Matrix4.prototype.setRotate = function(angle, x, y, z) {var e, s, c, len, rlen, nc, xy, yz, zx, xs, ys, zs;angle = Math.PI * angle / 180;e = this.elements;s = Math.sin(angle);c = Math.cos(angle);if (0 !== x && 0 === y && 0 === z) {// Rotation around X axisif (x < 0) {s = -s;}e[0] = 1;  e[4] = 0;  e[ 8] = 0;  e[12] = 0;e[1] = 0;  e[5] = c;  e[ 9] =-s;  e[13] = 0;e[2] = 0;  e[6] = s;  e[10] = c;  e[14] = 0;e[3] = 0;  e[7] = 0;  e[11] = 0;  e[15] = 1;} else if (0 === x && 0 !== y && 0 === z) {// Rotation around Y axisif (y < 0) {s = -s;}e[0] = c;  e[4] = 0;  e[ 8] = s;  e[12] = 0;e[1] = 0;  e[5] = 1;  e[ 9] = 0;  e[13] = 0;e[2] =-s;  e[6] = 0;  e[10] = c;  e[14] = 0;e[3] = 0;  e[7] = 0;  e[11] = 0;  e[15] = 1;} else if (0 === x && 0 === y && 0 !== z) {// Rotation around Z axisif (z < 0) {s = -s;}e[0] = c;  e[4] =-s;  e[ 8] = 0;  e[12] = 0;e[1] = s;  e[5] = c;  e[ 9] = 0;  e[13] = 0;e[2] = 0;  e[6] = 0;  e[10] = 1;  e[14] = 0;e[3] = 0;  e[7] = 0;  e[11] = 0;  e[15] = 1;} else {// Rotation around another axislen = Math.sqrt(x*x + y*y + z*z);if (len !== 1) {rlen = 1 / len;x *= rlen;y *= rlen;z *= rlen;}nc = 1 - c;xy = x * y;yz = y * z;zx = z * x;xs = x * s;ys = y * s;zs = z * s;e[ 0] = x*x*nc +  c;e[ 1] = xy *nc + zs;e[ 2] = zx *nc - ys;e[ 3] = 0;e[ 4] = xy *nc - zs;e[ 5] = y*y*nc +  c;e[ 6] = yz *nc + xs;e[ 7] = 0;e[ 8] = zx *nc + ys;e[ 9] = yz *nc - xs;e[10] = z*z*nc +  c;e[11] = 0;e[12] = 0;e[13] = 0;e[14] = 0;e[15] = 1;}return this;
};/*** Multiply the matrix for rotation from the right.* The vector of rotation axis may not be normalized.* @param angle The angle of rotation (degrees)* @param x The X coordinate of vector of rotation axis.* @param y The Y coordinate of vector of rotation axis.* @param z The Z coordinate of vector of rotation axis.* @return this*/
Matrix4.prototype.rotate = function(angle, x, y, z) {return this.concat(new Matrix4().setRotate(angle, x, y, z));
};/*** Set the viewing matrix.* @param eyeX, eyeY, eyeZ The position of the eye point.* @param centerX, centerY, centerZ The position of the reference point.* @param upX, upY, upZ The direction of the up vector.* @return this*/
Matrix4.prototype.setLookAt = function(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ) {var e, fx, fy, fz, rlf, sx, sy, sz, rls, ux, uy, uz;fx = centerX - eyeX;fy = centerY - eyeY;fz = centerZ - eyeZ;// Normalize f.rlf = 1 / Math.sqrt(fx*fx + fy*fy + fz*fz);fx *= rlf;fy *= rlf;fz *= rlf;// Calculate cross product of f and up.sx = fy * upZ - fz * upY;sy = fz * upX - fx * upZ;sz = fx * upY - fy * upX;// Normalize s.rls = 1 / Math.sqrt(sx*sx + sy*sy + sz*sz);sx *= rls;sy *= rls;sz *= rls;// Calculate cross product of s and f.ux = sy * fz - sz * fy;uy = sz * fx - sx * fz;uz = sx * fy - sy * fx;// Set to this.e = this.elements;e[0] = sx;e[1] = ux;e[2] = -fx;e[3] = 0;e[4] = sy;e[5] = uy;e[6] = -fy;e[7] = 0;e[8] = sz;e[9] = uz;e[10] = -fz;e[11] = 0;e[12] = 0;e[13] = 0;e[14] = 0;e[15] = 1;// Translate.return this.translate(-eyeX, -eyeY, -eyeZ);
};/*** Multiply the viewing matrix from the right.* @param eyeX, eyeY, eyeZ The position of the eye point.* @param centerX, centerY, centerZ The position of the reference point.* @param upX, upY, upZ The direction of the up vector.* @return this*/
Matrix4.prototype.lookAt = function(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ) {return this.concat(new Matrix4().setLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ));
};/*** Multiply the matrix for project vertex to plane from the right.* @param plane The array[A, B, C, D] of the equation of plane "Ax + By + Cz + D = 0".* @param light The array which stored coordinates of the light. if light[3]=0, treated as parallel light.* @return this*/
Matrix4.prototype.dropShadow = function(plane, light) {var mat = new Matrix4();var e = mat.elements;var dot = plane[0] * light[0] + plane[1] * light[1] + plane[2] * light[2] + plane[3] * light[3];e[ 0] = dot - light[0] * plane[0];e[ 1] =     - light[1] * plane[0];e[ 2] =     - light[2] * plane[0];e[ 3] =     - light[3] * plane[0];e[ 4] =     - light[0] * plane[1];e[ 5] = dot - light[1] * plane[1];e[ 6] =     - light[2] * plane[1];e[ 7] =     - light[3] * plane[1];e[ 8] =     - light[0] * plane[2];e[ 9] =     - light[1] * plane[2];e[10] = dot - light[2] * plane[2];e[11] =     - light[3] * plane[2];e[12] =     - light[0] * plane[3];e[13] =     - light[1] * plane[3];e[14] =     - light[2] * plane[3];e[15] = dot - light[3] * plane[3];return this.concat(mat);
}/*** Multiply the matrix for project vertex to plane from the right.(Projected by parallel light.)* @param normX, normY, normZ The normal vector of the plane.(Not necessary to be normalized.)* @param planeX, planeY, planeZ The coordinate of arbitrary points on a plane.* @param lightX, lightY, lightZ The vector of the direction of light.(Not necessary to be normalized.)* @return this*/
Matrix4.prototype.dropShadowDirectionally = function(normX, normY, normZ, planeX, planeY, planeZ, lightX, lightY, lightZ) {var a = planeX * normX + planeY * normY + planeZ * normZ;return this.dropShadow([normX, normY, normZ, -a], [lightX, lightY, lightZ, 0]);
};/*** Constructor of Vector3* If opt_src is specified, new vector is initialized by opt_src.* @param opt_src source vector(option)*/
var Vector3 = function(opt_src) {var v = new Float32Array(3);if (opt_src && typeof opt_src === 'object') {v[0] = opt_src[0]; v[1] = opt_src[1]; v[2] = opt_src[2];} this.elements = v;
}/*** Normalize.* @return this*/
Vector3.prototype.normalize = function() {var v = this.elements;var c = v[0], d = v[1], e = v[2], g = Math.sqrt(c*c+d*d+e*e);if(g){if(g == 1)return this;} else {v[0] = 0; v[1] = 0; v[2] = 0;return this;}g = 1/g;v[0] = c*g; v[1] = d*g; v[2] = e*g;return this;
};/*** Constructor of Vector4* If opt_src is specified, new vector is initialized by opt_src.* @param opt_src source vector(option)*/
var Vector4 = function(opt_src) {var v = new Float32Array(4);if (opt_src && typeof opt_src === 'object') {v[0] = opt_src[0]; v[1] = opt_src[1]; v[2] = opt_src[2]; v[3] = opt_src[3];} this.elements = v;
}

Matrix4对象所支持的方法和属性如表所示:

* 单位阵在矩阵乘法中的行为,就像数字1在乘法中的行为一样。将一个矩阵乘以单位阵,得到的结果和原矩阵完全相同。在单位阵中,对角线上的元素为1.0,其余的元素为0.0。

方法属性规范: 

从上表中可见,Matrix4对象有两种方法:一种方法的名称中含有前缀set,另一种则不含。包含set前缀的方法会根据参数计算出变换矩阵,然后将变换矩阵写入到自身中;而不含set前缀的方法,会先根据参数计算出变换矩阵,然后将自身与刚刚计算得到的变换矩阵相乘,然后把最终得到的结果再写入到Matrix4对象中。

如上表所示,Matrix4对象的方法十分强大且灵活。更重要的是,有了这些函数,进行变换就会变得轻而易举。

相关文章:

WebGL矩阵变换库

目录 矩阵变换库&#xff1a; Matrix4对象所支持的方法和属性如表所示&#xff1a; 方法属性规范&#xff1a; 虽然平移、旋转、缩放等变换操作都可以用一个44的矩阵表示&#xff0c;但是在写WebGL程序的时候&#xff0c;手动计算每个矩阵很耗费时间。为了简化编程&#xf…...

block层:8. deadline调度器

deadline 源码基于5.10 0. 私有数据 struct deadline_data {/** run time data*//** requests (deadline_rq s) are present on both sort_list and fifo_list*/struct rb_root sort_list[2];struct list_head fifo_list[2];/** next in sort order. read, write or both ar…...

DTO,VO,PO的意义与他们之间的转换

DTO&#xff08;Data Transfer Object&#xff09;&#xff1a;数据传输对象&#xff0c;这个概念来源于J2EE的设计模式&#xff0c;原来的目的是为了EJB的分布式应用提供粗粒度的数据实体&#xff0c;以减少分布式调用的次数&#xff0c;从而提高分布式调用的性能和降低网络负…...

Java 集合框架2

一、关于set接口的常用类 1.HashSet类 用来处理无序的单列数据&#xff0c;没有重复的元素,重复的元素算一个 i.构造方法 //HashSet类是set接口的子类&#xff0c;是无序的单列数据&#xff0c;没有重复的元素&#xff0c;重复的元素算一个 //HashSet的构造方法 //HashSet() …...

2024王道408数据结构P144 T16

2024王道408数据结构P144 T16 思考过程 首先看题目&#xff0c;要求我们把二叉树的叶子结点求出来并且用链表的方式存储&#xff0c;链接时用叶结点的右指针来存放单链表指针。我们很清楚可以看出来能用中序遍历递归的方式实现&#xff0c;因为第一个叶子结点在整棵树的最左下…...

【ARM Coresight 系列文章 22 -- linux frace 与 trace-cmd】

文章目录 ftrace 介绍trace-cmd 介绍trace-cmd 常用跟踪事件ftrace 与 trace-cmd 关系ftrace 编译依赖 ftrace 介绍 ftrace 是 Linux 内核中的一个跟踪工具&#xff0c;主要用于帮助开发者分析和调试内核的行为。ftrace 的名字来源于 “function tracer”&#xff0c;它最初是…...

MyBatis的一级缓存和二级缓存是怎么样的?

目录 1. 一级缓存 2. 一级缓存失效的几种情况 3. 二级缓存 4.二级缓存失效的情况 5. 二级缓存的相关配置 6. 缓存的查询顺序 MyBatis 的缓存共分为一级缓存和二级缓存。 1. 一级缓存 一级缓存是 SqlSession 级别的&#xff0c;通过同一个 SqlSession 查询到的数据会被缓…...

下载的文件被Windows 11 安全中心自动删除

今天从CSDN上下载了自己曾经上传的文件&#xff0c;但是浏览器下载完之后文件被Windows安全中心自动删除&#xff0c;说是带病毒。实际是没有病毒的&#xff0c;再说了即便有病毒也不应该直接删除啊&#xff0c;至少给用户一个保留或删除的选项。 研究了一番&#xff0c;可以暂…...

【Java List与数组】List<T>数组和数组List<T>的区别(124)

List数组&#xff1a;存储List的数组&#xff0c;即&#xff1a;数组中的元素是&#xff1a;List&#xff1b; 数组List&#xff1a;存储数组的List&#xff0c;即&#xff1a;List中的数据是类型的数组&#xff1b; 测试案例&#xff1a; import java.util.ArrayList; impor…...

Nuxt 菜鸟入门学习笔记四:静态资源

文章目录 public 目录assets 目录全局样式导入 Nuxt 官网地址&#xff1a; https://nuxt.com/ Nuxt 使用以下两个目录来处理 CSS、fonts 和图片等静态资源&#xff1a; public 目录 public 目录用作静态资产的公共服务器&#xff0c;可通过应用程序定义的 URL 公开获取。 换…...

C语言 - 结构体、结构体数组、结构体指针和结构体嵌套

结构体的意义 问题&#xff1a;学籍管理需要每个学生的下列数据&#xff1a;学号、姓名、性别、年龄、分数&#xff0c;请用 C 语言程序存储并处理一组学生的学籍。 单个学生学籍的数据结构&#xff1a; 学号&#xff08;num&#xff09;&#xff1a; int 型姓名&#xff08;…...

python安装playwright问题记录

python安装playwright这个时候,有得时候会https timeout 有的时候会 not found。 我最后使用的方法三&#xff0c;挺好用的。 PyPI The Python Package Index 可以尝试使用的方法 1. 更换pip源&#xff1a;使用国内的pip源可以提高下载速度并减少超时问题。例如&#xff0c…...

关于gRPC微服务利弊之谈

gRPC微服务架构包括以下几个主要组件&#xff1a; 服务定义&#xff1a;定义服务的接口和消息格式&#xff0c;使用Protocol Buffers或其他的消息格式进行描述。服务实现&#xff1a;实现定义的服务接口和消息处理逻辑。服务器端实现&#xff1a;在服务器端&#xff0c;需要实…...

【Terraform学习】使用 Terraform创建Lambda函数启动EC2(Terraform-AWS最佳实战学习)

本站以分享各种运维经验和运维所需要的技能为主 《python》&#xff1a;python零基础入门学习 《shell》&#xff1a;shell学习 《terraform》持续更新中&#xff1a;terraform_Aws学习零基础入门到最佳实战 《k8》暂未更新 《docker学习》暂未更新 《ceph学习》ceph日常问题解…...

Mac软件删除方法?如何删除不会有残留

Mac电脑如果有太多无用的应用程序&#xff0c;很有可能会拖垮Mac系统的运行速度。因此&#xff0c;卸载电脑中无用的软件是优化Mac系统运行速度的最佳方式之一。Mac卸载应用程序的方式是和Windows有很大的区别&#xff0c;特别对于Mac新用户来说&#xff0c;如何无残留的卸载删…...

编程之道:【性能优化】提高软件效率的实际建议和避免常见陷阱

在今天的数字化世界中&#xff0c;软件性能是应用程序成功的关键之一。无论是网页加载速度、移动应用的响应时间还是后端服务器的处理速度&#xff0c;性能都直接影响着用户满意度。在追求高性能时&#xff0c;开发人员需要采取一系列实际建议&#xff0c;同时避免常见的陷阱。…...

VGG的结构:视觉几何组(Visual Geometry Group)

目录 1. VGG 的结构 2. VGG 的网络细节 3. VGG 的代码实现 1. VGG 的结构 牛津大学的视觉几何组&#xff08;Visual Geometry Group&#xff09;设计了 VGGNet(也称为 VGG)&#xff0c;一种经典的卷积神经网络 (CNN) 架构。在 2014 年 ILSVRC 分类任务中&#xff0c;VGG 取…...

VBA:按照Excel工作表中的名称列自动汇总多个工作薄中对应sheet中所需要的数据

需求如下&#xff1a; B列为产品名为合并单元格&#xff0c;C列为供应商名&#xff0c;G、H列为金额数据&#xff1b;数据源放在同一个文件夹内&#xff0c;B列产品名来源于工作薄名称中间的字符串&#xff0c;C列供应商名来源于工作薄中的sheet名&#xff1b;G、H列金额数据来…...

Mybatis1.9 批量删除

1.9 批量删除 1.9.1 编写接口方法1.9.2 编写SQL语句1.9.3 编写测试方法 如上图所示&#xff0c;用户可以选择多条数据&#xff0c;然后点击上面的 删除 按钮&#xff0c;就会删除数据库中对应的多行数据。 1.9.1 编写接口方法 在 BrandMapper 接口中定义删除多行数据的方法。…...

CUDA小白 - NPP(2) -图像处理-算数和逻辑操作(2)

cuda小白 原始API链接 NPP GPU架构近些年也有不少的变化&#xff0c;具体的可以参考别的博主的介绍&#xff0c;都比较详细。还有一些cuda中的专有名词的含义&#xff0c;可以参考《详解CUDA的Context、Stream、Warp、SM、SP、Kernel、Block、Grid》 常见的NppStatus&#xf…...

python+redis实现布隆过滤器(含redis5.0版本以上和5.0以下版本的两份代码)

布隆过滤器是一种空间效率极高的概率数据结构&#xff0c;用于测试一个元素是否是集合的成员。如果布隆过滤器返回 False&#xff0c;则元素绝对不在集合中。如果返回 True&#xff0c;则元素可能在集合中&#xff0c;但也可能是一个误报。布隆过滤器利用了多个不同的哈希函数对…...

SpringBoot Thymeleaf iText7 生成 PDF(2023/08/29)

SpringBoot Thymeleaf iText7 生成 PDF&#xff08;2023/08/29&#xff09; 文章目录 SpringBoot Thymeleaf iText7 生成 PDF&#xff08;2023/08/29&#xff09;1. 前言2. 技术思路3. 实现过程4. 测试 1. 前言 近期在项目种遇到了实时生成复杂 PDF 的需求&#xff0c;经过一番…...

【核磁共振成像】并行采集MRI

目录 一、并行成像二、SENSE重建三、SMASH重建四、灵敏度校准五、AUTO-SMASH和VD-AUTO-SMASH六、GRAPPA重建七、SPACE RIP重建算法八、PILS重建算法九、PRUNO重建算法十、UNFOLD算法 一、并行成像 并行MR成像(pMRI):相位阵列接受线圈不但各有自己专用的接受通道&#xff0c;而且…...

深度图相关评测网站

文章目录 1 单目/Stereo相关测评网站介绍12 单目/Stereo相关测评网站介绍23 单目/Stereo相关测评网站介绍3 1 单目/Stereo相关测评网站介绍1 https://vision.middlebury.edu/stereo/eval3/ 2 单目/Stereo相关测评网站介绍2 http://www.cvlibs.net/datasets/kitti/eval_stereo…...

本地部署 CodeLlama 并在 VSCode 中使用 CodeLlama

本地部署 CodeLlama 并在 VSCode 中使用 CodeLlama 1. CodeLlama 是什么2. CodeLlama Github 地址3. 下载 CodeLlama 模型4. 部署 CodeLlama5. 在 VSCode 中使用 CodeLlama6. 使用WSGI启动服务7. 创建 start.sh 启动脚本 1. CodeLlama 是什么 Code Llama 是一个基于 Llama 2 的…...

Agilent33220A任意波形发生器

20MHz正弦波和方波脉冲、斜披、三角波&#xff0c;噪声和直流波形14-bit,50MSa/s&#xff0c;64K点任意波形AM、FM、PM、FSK和PWM凋制线性和对数扫描及脉冲串模式10mVpp至10Vpp幅苗范围图形化界面可以对信号设置进行可视化验证通过USB、GPIB和LAN连接 性能优异的各种函数的波形…...

springboot第37集:kafka,mqtt,Netty,nginx,CentOS,Webpack

image.png binzookeeper-server-start.shconfigzookeeper.properties.png image.png image.png 消费 image.png image.png image.png image.png image.png image.png image.png image.png image.png Netty的优点有很多&#xff1a; API使用简单&#xff0c;学习成本低。功能强大…...

NVIDIA DLI 深度学习基础 答案 领取证书

最后一节作业是水果分类的任务&#xff0c;一共6类&#xff0c;使用之前学习的知识在代码段上进行填空。 加载ImageNet预训练的基础模型 from tensorflow import kerasbase_model keras.applications.VGG16(weights"imagenet",input_shape(224, 224, 3),include_t…...

axios模拟表单提交

axios默认是application/json方式提交&#xff0c;controller接收的时候必须以RequestBody的方式接收&#xff0c;有时候不太方便。如果axios以application/x-www-form-urlencoded方式提交数据&#xff0c;controller接收的时候只要保证名字应对类型正确即可。 前端代码&#…...

智安网络|探索物联网架构:构建连接物体与数字世界的桥梁

物联网是指通过互联网将各种物理设备与传感器连接在一起&#xff0c;实现相互通信和数据交换的网络系统。物联网架构是实现这一连接的基础和框架&#xff0c;它允许物体与数字世界之间的互动和协作。 一、物联网架构的概述 物联网架构是一种分层结构&#xff0c;它将物联网系…...

胡歌深夜发文:我对不起好多人

胡歌的微博又上了热搜。 8月29日01:18分&#xff0c;胡歌微博发文称&#xff1a;“我尽量保持冷静&#xff0c;我对不起好多人&#xff0c;我希望对得起这短暂的一生”&#xff0c;并配了一张自己胡子拉碴的图&#xff0c;右眼的伤疤清晰可见。 不少网友留言称“哥你又喝多了吗…...

C++二级题

数字放大 #include<iostream> #include<string.h> #include<stdio.h> #include<iomanip> #include<cmath> #include<bits/stdc.h> int a[2000][2000]; int b[2000]; char c[2000]; long long n; using namespace std; int main() {cin>…...

NetApp AFF A900:适用于数据中心的超级产品

NetApp AFF A900&#xff1a;适用于数据中心的超级产品 AFF A 系列中的 AFF A900 高端 NVMe 闪存存储功能强大、安全可靠、具有故障恢复能力&#xff0c;提供您为任务关键型企业级应用程序提供动力并保持数据始终可用且安全所需的一切。 产品功能与特性 AFF A900&#xff1a…...

入海排污口水质自动监测系统,助力把好入河入海“闸门”

随着经济社会的不断发展&#xff0c;污水的排放强度不断加大&#xff0c;大量的污水排入河流、湖泊和海洋中&#xff0c;造成了水体污染&#xff0c;严重影响着我国的用水安全、公众健康、经济发展与社会稳定。入河入海排污口是污染物进入河流和海洋的最后关口&#xff0c;也是…...

AUTOSAR知识点 之 ECUM (一):基础知识梳理(概念部分)

目录 1、概述 2、ECUM的工作状态 2.1、Startup状态 2.2、UP状态 2.3、RUN状态 2.4、SLEEP状态...

leetcode分类刷题:哈希表(Hash Table)(二、数组交集问题)

1、当需要快速判断某元素是否出现在序列中时&#xff0c;就要用到哈希表了。 2、本文针对的总结题型为给定两个及多个数组&#xff0c;求解它们的交集。接下来&#xff0c;按照由浅入深层层递进的顺序总结以下几道题目。 3、以下题目需要共同注意的是&#xff1a;对于两个数组&…...

[Mac软件]Adobe After Effects 2023 v23.5 中文苹果电脑版(支持M1)

After Effects是动画图形和视觉效果的行业标准。由运动设计师、平面设计师和视频编辑用于创建复杂的动画图形和视觉上吸引人的视频。 创建动画图形 使用预设样式为文本和图形添加动画效果&#xff0c;或逐帧调整它们。编辑、添加深度、制作动画或转换为可编辑的路径&#xff…...

范德波尔方程详细介绍与Python实现(附说明)

引言: 在研究真空管放大器的过程中,写下了一个振动微分方程。当时人们并没有混沌或是对初始条件敏感的概念。不过,当混沌理论有一定发展后,人们重新回顾这个方程时发现它其实是个混沌方程。当时,范德波尔在 Nature 杂志报告了基于这个微分方程的霓虹灯实验,发现当驱动信号…...

常用的GPT插件

0.简介 随着chatgpt爆火&#xff0c;这玩意并不对国内用户开放&#xff0c;如果想要使用的话还要需要进行翻墙以及国外手机号才能进行注册。 对于国内来说有很多国内免费的方法&#xff0c;这里就整理一下&#xff0c;方便大家开发 1. 网站类型 下面的网站无需注册即可免费…...

智慧校园用电安全解决方案

随着科技的不断发展&#xff0c;智慧校园建设逐渐成为了教育行业的一大趋势。在这个过程中&#xff0c;电力系统作为校园基础设施的重要组成部分&#xff0c;其安全、稳定、高效的运行显得尤为重要。下面小编来为大家介绍下智慧校园用电安全解决方案吧! 一、智慧校园电力系统现…...

【教程】DGL中的子图分区函数partition_graph讲解

转载请注明出处&#xff1a;小锋学长生活大爆炸[xfxuezhang.cn] 目录 函数形式 函数作用 函数内容 函数入参 函数返参 使用示例 实际上官方的函数解释中就已经非常详细了。 函数形式 def partition_graph(g, graph_name, num_parts, out_path, num_hops1, part…...

关于layui table回显以及选择下一页时记住上一页数据的问题

代码如下 <div class"layui-form-item"><label class"layui-form-label">选择商品</label><div class"layui-input-inline"><input type"text" name"keyword" id"keyword" placehold…...

kafka消息系统实战

kafka是什么&#xff1f; 是一种高吞吐量的、分布式、发布、订阅、消息系统 1.导入maven坐标 <dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-clients</artifactId><version>2.4.1</version></dependency&…...

Kafka3.0.0版本——Leader故障处理细节原理

目录 一、服务器信息二、服务器基本信息及相关概念2.1、服务器基本信息2.2、LEO的概念2.3、HW的概念 三、Leader故障处理细节 一、服务器信息 三台服务器 原始服务器名称原始服务器ip节点centos7虚拟机1192.168.136.27broker0centos7虚拟机2192.168.136.28broker1centos7虚拟机…...

BI系统框架模型

一 技术架构 二 数据源 主数据 &#xff1a;组织|岗位|人员|大区|三大主数据&#xff08;客户、物料、供应商&#xff09;财务主数据&#xff08;科目|成本中心|利润中心|资产&#xff09;|工作中心|工艺路线 业务数据 &#xff1a;线索|业务机会|合同|订单|采购|生产|发…...

双向交错CCM图腾柱无桥单相PFC学习仿真与实现(3)硬件功能实现

前言 前面介绍了双向交错CCM图腾柱的系统设计仿真实现&#xff0c;仿真很理想 双向交错CCM图腾柱无桥单相PFC学习仿真与实现&#xff08;1&#xff09;系统问题分解_卡洛斯伊的博客-CSDN博客 然后又介绍了SOG锁相环仿真实现的原理 双向交错CCM图腾柱无桥单相PFC学习仿真与实…...

微软用 18 万行 Rust 重写了 Windows 内核

微软正在使用 Rust 编程语言重写其核心 Windows 库。 5 月 11 日——Azure 首席技术官 Mark Russinovich 表示&#xff0c;最新的 Windows 11 Insider Preview 版本是第一个包含内存安全编程语言 Rust 的版本。 “如果你参加了 Win11 Insider 环&#xff0c;你将在 Windows 内…...

word 调整列表缩进

word 调整列表缩进的一种方法&#xff0c;在试了其他方法无效后&#xff0c;按下图所示顺序处理&#xff0c;编号和文字之间的空白就没那么大了。 即右键word上方样式->点击修改格式->定义新编号格式->字体->取消勾选 “……对齐到网格”->确定...

nginx学习

一、nginx常用版本 Nginx开源版&#xff1a; http://nginx.org/ nginx plus商业版本&#xff08;好像功能支持更多&#xff09; https://www.nginx.com/ openresty &#xff08;免费&#xff0c;用的也是这个&#xff09; https://openresty.org/cn/ Tengine https://tengine.…...

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(一)

pythonTensorFlow实现人脸识别智能小程序的项目&#xff08;包含TensorFlow版本与Pytorch版本&#xff09;&#xff08;一&#xff09; 一&#xff1a;TensorFlow基础知识内容部分&#xff08;简明扼要&#xff0c;快速适应&#xff09;1、下载Cifar10数据集&#xff0c;并进行…...