Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matrix multiplication order PVM vs MVP in graphics programming

Tags:

math

matrix

3d

hi there I was wondering why most tutorials and programming code use MVP to describe the Model-View-Projection matrix. Instead of PVM which is the actual order of implementation in the code:

mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
gl_Position = MVP * VertexInModelSpace;

seems much more understandable to me to write PVM instead of MVP.

like image 659
ColacX Avatar asked Oct 06 '22 12:10

ColacX


1 Answers

Matrices don't actually have a fixed meaning, just relations between rows and columns. The meaning is freely definable by the developers. The MVP order follows from standard mathematical conventions. But since nothing says you can not define the vectors as columns instead of rows nothing precludes this ordering.

Clarification: Since changing notation transposes the meaning. Then following applies:

MmvpT = Mpvm

Due to the definition of matrix multiplication following rule kicks in:

(AB)T = BTAT

Since B can be recursively another matrix multiplication a infinite chain of these are possible. Which means essentially that you have swapped the multiplication order, by changing notation.

Its a bit like looking at the problem from the outside or the problem from the inside. In this case your thinking as a outside observer. Whereas the other way around one would observe the thing from the standpoint of the first operator in the chain. Personally I think the notation you use may be more intuitive for this specific task, the other is just way more common. Mainly due to the fact that all mathematics books I have ever seen use this convention, so blame the mathematicians.

So better stick with the more common way, makes things more generally understandable. For example: Nothing stops me from typing the answer in Finnish but the convention of stackoverflow is to answer in English, making answers more understandable to most users. Use the more common form since others may not grasp the difference, and this leads to errors.

like image 103
joojaa Avatar answered Oct 10 '22 02:10

joojaa