pex-math
pex-math copied to clipboard
Add mat4.multQuat
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?
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).
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);
}