Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Szahu opened this issue Apr 6, 2021 · 0 comments
Open

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

Szahu opened this issue Apr 6, 2021 · 0 comments

Comments

@Szahu
Copy link

Szahu commented Apr 6, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant