【问题标题】:Migrating to from glMatrix 1 to glMatrix 2从 glMatrix 1 迁移到 glMatrix 2
【发布时间】:2018-10-20 01:06:04
【问题描述】:

我无法将这些功能从使用 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 矩阵 (mat3)。

标签: javascript linear-algebra gl-matrix


【解决方案1】:

普通矩阵是 3*3 矩阵 (mat3)。

但无论如何,glMatrix 有据可查,根据mat4vec4 的文档,您的代码可以这样移植:

calculateNormal() {
    this.normalMatrix = mat4.clone(this.modelViewMatrix);
    mat4.invert(this.normalMatrix, this.normalMatrix);
    mat4.transpose(this.normalMatrix, this.normalMatrix);
}

可能没有必要create 以下向量,但我不知道向量是否存在于您的情况:

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 );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 2018-08-10
    • 2017-03-11
    相关资源
    最近更新 更多