pex-math icon indicating copy to clipboard operation
pex-math copied to clipboard

Add mat4.multQuat

Open vorg opened this issue 3 years ago • 2 comments

When creating modelMatrix from rotation in pex-renderer i'm missing the following function

  var tempMat4multQuatMat4 = mat4.create();
  function mat4multQuat(m, q) {
    mat4.fromQuat(tempMat4multQuatMat4, q);
    mat4.mult(m, tempMat4multQuatMat4);
    return m;
  }

Do you think it would be worth adding?

vorg avatar Oct 17 '22 12:10 vorg

Looks like pex-renderer use case is actually translation + rotation.

  • Is using fromTranslationRotationScale(a, translationVec3, rotationQuat, [1,1,1]) an option?
  • or adding fromTranslationRotation(a, translationVec3, rotationQuat,) another valid option?

I think they'd be both faster than running two consecutive mat4 operations (fromQuat/mult).

dmnsgn avatar Oct 17 '22 14:10 dmnsgn

For building camera.invViewMatrix indeed i could just default to above and scale [1,1,1] for the below i would need to assume that we use component.transform() and position,rotation,scale are set.

function updateModelMatrix(matrix, transform) {
  mat4.identity(matrix);
  if (transform.position) mat4.translate(matrix, transform.position);
  if (transform.rotation) mat4multQuat(matrix, transform.rotation);
  if (transform.scale) mat4.scale(matrix, transform.scale);
  if (transform.matrix) mat4.mult(matrix, transform.matrix);
}

vorg avatar Oct 17 '22 20:10 vorg