nfrechette / rtm

Realtime Math
MIT License
732 stars 44 forks source link

Why does matrix_mul always consider the left hand side as a 4x3 matrix #194

Closed peter1745 closed 10 months ago

peter1745 commented 10 months ago

Hello, I'm curious why the matrix_mul always considers the left hand side as a 4x3 matrix for 4x4 matrix multiplication?

From what I can tell this is on purpose, but it means that it's not a true 4x4 multiplication, despite claiming that it is?

The fact that this isn't documented means that it's really easy to get incorrect results from multiplying 4x4 matrices, since you'd be expecting a true 4x4 matrix multiplication.

Just wondering what the reason for this is, if it's intentional, and if so I'd like to suggest that this is documented somewhere

nfrechette commented 10 months ago

Hello @peter1745, Thank you for reporting this!

Looking at the code, you are correct. This appears to be a bug and isn't intentional. I personally haven't used RTM 4x4 matrices in my own work as I don't use it for rendering which is where they tend to be more commonly used. That's why it slipped through the cracks this long :(

Looking at the unit test for it, it seems that it was copy/pasted from the 4x3 multiplication and would thus hide the issue as well.

I'll fix both of those in patch release 2.2.1 shortly and I'll give 4x4 matrices a look over as a lot of it was copy/pasted. I'll reference this issue with the commit that fixes this and I'll make the 2.2.1 release in the next few days if nothing else pops up.

peter1745 commented 10 months ago

Well I'm glad to hear that this was a mistake and that it will be fixed :)

nfrechette commented 10 months ago

Sonarcloud had a hickup earlier this week, slowing things down. I should be able to make the 2.2.1 release with this fix on Friday night this week. The fix is contained in the referencing commit.