Matrix multiplication order

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Timo
Posts: 7
Joined: Fri Jan 29, 2010 9:37 am

Matrix multiplication order

Post by Timo »

Not probably a bug, but I just wanted to confirm whether it's intentional that the matrix multiplication is done in the wrong order. For example, if we have a simple multiplication like this:

Code: Select all

matrix4 M1, M2, M3;
...
M3 = M1*M2;
The result is not M1*M2, but M2*M1. This is assuming that the matrices are in row major format like said in the docs.

Anyway I think it should be mentioned in the documentation.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Hmm, you are correct. I guess that would explain why Irrlicht requires that you do:

Code: Select all

core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
instead of the classical way. That explains a lot.
TheQuestion = 2B || !2B
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, both orders are properly defined and just need to be used correctly.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

hybrid wrote:Well, both orders are properly defined and just need to be used correctly.
Well yes. Shouldn't the documentation be updated then?
TheQuestion = 2B || !2B
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

IIRC, I have added all the necessary explanations already for 1.7. If there are things still unclear, just point out the exact places and maybe give a suggestion on how to update the sections.
brferreira
Posts: 5
Joined: Wed Mar 03, 2010 5:45 pm

Post by brferreira »

hybrid wrote:IIRC, I have added all the necessary explanations already for 1.7. If there are things still unclear, just point out the exact places and maybe give a suggestion on how to update the sections.
The trunk doc says:

Code: Select all

//! Multiply by another matrix.
While it should be something like

Code: Select all

//! Multiply other matrix by this
/** This function returns a new matrix multiplying the second matrix by the first one */
Steel Style
Posts: 168
Joined: Sun Feb 04, 2007 3:30 pm
Location: France

Post by Steel Style »

I agree that's a really weird behaviour.
Anyone have a clue about what it is writed like this ?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You mean why? Well, multiplication of matrices is defined both ways. It's just a writing convention if a*b means one or the other. Niko defined most things as in D3D, so it might be a reason there.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

I don't mean to beat a dead horse. I'm fine with the current convention as it is defined; I'm just glad I know now for future reference. But http://msdn.microsoft.com/en-us/library ... S.85).aspx (D3DXMatrixMultiply) is defined as "the transformation M1 followed by the transformation M2 (Out = M1 * M2)."
Last edited by Halifax on Tue Mar 09, 2010 3:09 pm, edited 2 times in total.
TheQuestion = 2B || !2B
Steel Style
Posts: 168
Joined: Sun Feb 04, 2007 3:30 pm
Location: France

Post by Steel Style »

Yes that what it's supposed to be.
Because it's actually the multiplication is not M1*M2 but (M1*M2).Transpose.

So the only reason to do this may be because it's computed as column vector (OpenGL use them) so m[4] replace m[1], m[3] replace m[2]... but in this m[12] m[13] m[14] couldn't be the translation vector. :/
Post Reply