Переход с glMatrix 1 на glMatrix 2

1

Я не смог обновить эти функции из старого приложения, используя 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);
}
  • 0
    Обычно нормальная матрица - это матрица 3 * 3 ( mat3 ).
Теги:
linear-algebra
gl-matrix

1 ответ

1
Лучший ответ

В общем случае нормальной матрицей является матрица 3 * 3 ( mat3).

Но в любом случае glMatrix хорошо документирован и, согласно документации mat4 и vec4, ваш код можно портировать следующим образом:

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

Ещё вопросы

Сообщество Overcoder
Наверх
Меню