Javascript 从glMatrix 1迁移到glMatrix 2

Javascript 从glMatrix 1迁移到glMatrix 2,javascript,linear-algebra,gl-matrix,Javascript,Linear Algebra,Gl Matrix,我无法使用glMatrix 1.2将这些函数从旧应用程序更新为glMatrix 2.7: calculateNormal() { mat4.identity(this.normalMatrix); mat4.set(this.modelViewMatrix, this.normalMatrix); mat4.inverse(this.normalMatrix); mat4.transpose(this.normalMatrix); } 以下矩阵乘以4分量向量的函

我无法使用glMatrix 1.2将这些函数从旧应用程序更新为glMatrix 2.7:

calculateNormal() {
    mat4.identity(this.normalMatrix);
    mat4.set(this.modelViewMatrix, this.normalMatrix);
    mat4.inverse(this.normalMatrix);
    mat4.transpose(this.normalMatrix);
}
以下矩阵乘以4分量向量的函数不存在:

calculateOrientation() {
    mat4.multiplyVec4(this.matrix, [1, 0, 0, 0], this.right);
    mat4.multiplyVec4(this.matrix, [0, 1, 0, 0], this.up);
    mat4.multiplyVec4(this.matrix, [0, 0, 1, 0], this.normal);
}

通常,法线矩阵是3*3矩阵()

但无论如何,它都有很好的文档记录,并且根据和的文档记录,您的代码可以如下移植:

calculateNormal() {
    this.normalMatrix = mat4.clone(this.modelViewMatrix);
    mat4.invert(this.normalMatrix, this.normalMatrix);
    mat4.transpose(this.normalMatrix, this.normalMatrix);
}
可能没有必要创建以下向量,但我不知道在您的情况下是否存在向量:

calculateOrientation() {

    this.right = vec4.create();
    vec4.set( this.right, 1, 0, 0, 0 );
    vec4.transformMat4( this.right, this.right, this.matrix );

    this.up = vec4.create();
    vec4.set( this.up, 0, 1, 0, 0 );
    vec4.transformMat4( this.up, this.up, this.matrix );

    this.normal = vec4.create();
    vec4.set( this.normal, 0, 0, 1, 0 );
    vec4.transformMat4( this.normal, this.normal, this.matrix );
}

通常,法线矩阵是3*3矩阵(
mat3
)。