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

WebGL matrix example is using atypical right-mul convention #34604

Closed
ghost opened this issue Jul 3, 2024 · 2 comments · Fixed by #35668
Closed

WebGL matrix example is using atypical right-mul convention #34604

ghost opened this issue Jul 3, 2024 · 2 comments · Fixed by #35668

Comments

@ghost
Copy link

ghost commented Jul 3, 2024

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Matrix_math_for_the_web#translation_matrix

What specific section or headline is this issue about?

Translation matrix

What information was incorrect, unhelpful, or incomplete?

MDN describes the translate matrix with the following code:

let x = 50;
let y = 100;
let z = 0;

let translationMatrix =
[
    1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    x, y, z, 1
];

The specification on W3 describes the translation matrix as:

[
    1, 0, 0, x,
    0, 1, 0, y,
    0, 0, 1, z,
    0, 0, 0, 1
];

What did you expect to see?

The two sources describe the same matrices for rotate and scale, but the provided translate matrices are different. Which is correct? Based on what I've looked up, I think MDN is incorrect.

It would also be helpful if the MDN page included the perspective matrix as on W3.

As an additional note, it would be helpful if both pages included the transform-origin matrix.

Do you have any supporting links, references, or citations?

https://www.brainvoyager.com/bv/doc/UsersGuide/CoordsAndTransforms/SpatialTransformationMatrices.html

https://gamedev.stackexchange.com/a/124669

https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Matrix_math_for_the_web#translation_matrix

https://www.w3.org/TR/css-transforms-2/#mathematical-description

Do you have anything more you want to share?

No response

@ghost ghost added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Jul 3, 2024
@github-actions github-actions bot added the Content:WebAPI Web API docs label Jul 3, 2024
@Josh-Cena
Copy link
Member

It is really confusing but it actually works. If you look closely at multiplyMatrixAndPoint, we are doing a right-multiplication and treating the point as a row vector, rather than the typical left-multiplication on a column vector. To be fair this probably makes more sense when written down as code, since you write an array horizontally, but maybe we should explain that? I'm not sure.

@Josh-Cena Josh-Cena removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Jul 3, 2024
@ghost
Copy link
Author

ghost commented Jul 3, 2024

@Josh-Cena Got it, that makes sense. Actually in the MDN page, the array is written horizontally, but I changed the formatting for the post. I think it would be helpful to explain it! Maybe a small note in the Translation matrix section that mentions this. For my part, I was using the page as a reference for what the matrices should look like, and hadn't actually looked too much into the multiplication methods MDN was using, so I missed that.

@Josh-Cena Josh-Cena changed the title "Matrix math for the web - Translation matrix" - Variance vs W3 Specification WebGL matrix example is using atypical right-mul convention Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant