gl-matrix icon indicating copy to clipboard operation
gl-matrix copied to clipboard

Is glMatrix.mat4.FromRotatinTranslationScale() in wrong order?

Open Szahu opened this issue 3 years ago • 0 comments

Please be gentle as I am still learning and this is my first gitHub issue.

This code, hopefully used properly, gives me distorted result:

let transformMatrix = new Float32Aray(16);

let rotationQuat= new Float32Array(16);
glMatrix.quat.identity(rotationQuat);
glMatrix.quat.setAxisAngle(rotationQuat, [0, 0, 1], someAngle);

let translation = [0, 0, 0];
let scale = [x, y, 1] // I use same vertices positions for all sprites and then scale them accordingly

glMatrix.mat4.fromRotationTranslationScale(transformMatrix , rotationQuat, translation, scale);

Image rendered this way is distorted scale-wise. However image is not distorted when calculations are done manually and I apply translation first, then scale and lastly rotation, like so:

let translateMat = new Float32Array(16);
let rotMat = new Float32Array(16);
let scaleMat = new Float32Array(16);

glMatrix.mat4.fromTranslation(translateMat, traslation);
glMatrix.mat4.fromScaling(scaleMat, traslation);
glMatrix.mat4.fromZRotation(rotMat, someAngle);

let finalMat = new Float32Array(16);
let rotScale = new Float32Array(16);

glMatrix.mat4.mul(rotScale, translateMat, scaleMat);
glMatrix.mat4.mul(finalMat, rotScale, rotMat);

let transformMatrix = finalMat;

This way things seem to be working fine and outputted matrix gives me correct result. Am I doing something wrong or is it glMatrix mistaken?

Szahu avatar Apr 06 '21 12:04 Szahu