Closed kirevdokimov closed 3 years ago
Matrix representation of translation defined as this: https://en.wikipedia.org/wiki/Translation_(geometry) First three components of 4th column is case of 4x4 matrix.
Result of one case of multiplication is this: https://www.wolframalpha.com/input/?i=%7B%7B1+%2F+10%2C+0%2C+0%2C+5%7D%2C+%7B0%2C+1%2C+0%2C+0%7D%2C+%7B0%2C+0%2C+1%2C+0%7D%2C%7B0%2C+0%2C+0%2C+1%7D%7D+.+%7B10%2C0%2C0%2C1%7D
Same multiplication case
console.log(twgl.m4.transformPoint([ 1 / 10, 0, 0, 5, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], [ 10, 0, 0, 1 ]))
Expected result is (6,0,0) see source of truth Actual result is
But if I replace translation component from last column to last row
console.log(twgl.m4.transformPoint([ 1 / 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5, 0, 0, 1 ], [ 10, 0, 0, 1 ]))
It returns expected results for previous case
As I can see translation is stored in last row instead of last column https://github.com/greggman/twgl.js/blob/0a44471ab91d068dae3ccc85f3054eeeb4c19a3a/src/m4.js#L419-L422
What is the reason to do that way instead of classic approach?
Thank you for your work!
Because that's the way pretty much all speed oriented math libraries work. OpenGL, glm, etc ....
See this article
Definition
Matrix representation of translation defined as this: https://en.wikipedia.org/wiki/Translation_(geometry) First three components of 4th column is case of 4x4 matrix.
Source of truth
Result of one case of multiplication is this: https://www.wolframalpha.com/input/?i=%7B%7B1+%2F+10%2C+0%2C+0%2C+5%7D%2C+%7B0%2C+1%2C+0%2C+0%7D%2C+%7B0%2C+0%2C+1%2C+0%7D%2C%7B0%2C+0%2C+0%2C+1%7D%7D+.+%7B10%2C0%2C0%2C1%7D
TWGL Behaviour
Same multiplication case
Expected result is (6,0,0) see source of truth Actual result is
But if I replace translation component from last column to last row
It returns expected results for previous case
As I can see translation is stored in last row instead of last column https://github.com/greggman/twgl.js/blob/0a44471ab91d068dae3ccc85f3054eeeb4c19a3a/src/m4.js#L419-L422
What is the reason to do that way instead of classic approach?
Thank you for your work!