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

Inconsistent order or arguments #468

Open
PauliusLiekis opened this issue May 10, 2024 · 2 comments
Open

Inconsistent order or arguments #468

PauliusLiekis opened this issue May 10, 2024 · 2 comments

Comments

@PauliusLiekis
Copy link

I'm confused about the order of arguments, as it doesn't follow mathematical logic. This code specifically:

mat4.multiply(M_, M1, M2);
vec3.transformMat4(p_, p, M_);

if I inline this code I end up with this order: p_ = p * M1 * M2, which would imply that p is first multiplied by M1 and then M2, but that's not what happens. The result M1 * M2 * p, i.e. it's multiplied by M2 and then by M1.

Wouldn't this order vec3.transformMat4(p_, M_, p); be less confusing? Is it just an oversight or am I missing something?


For example, writing this in CoreGraphics would look like this:

p_ = p.applying(M1.concatenating(M2))

and mathematically equivalent to p_ = p * M1 * M2, i.e. the consistent order, although a bit unconventional use of row-vectors for someone coming from a math background, but at least they are super consistent about that when it comes to the order of arguments in API or any explanations in the documentation.

@PauliusLiekis
Copy link
Author

PauliusLiekis commented May 10, 2024

BTW.: having a bit of math in the documentation might clear up this:

(static) transformMat4(out, a, m) → {vec4}
Transforms the vec4 with a mat4, i.e. "m * a".

@wang1212
Copy link

There are concepts of left multiplication and right multiplication in matrix multiplication, and they represent different meanings.

glmatrix is ​​used in the drawing engine. I guess the API means more to apply another transformation matrix to a vector or matrix, which satisfies the meaning of matrix left multiplication.

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

2 participants