6
$\begingroup$

I'm probably going to screw this up but.... In all the graphics libraries I've seen various matrices are often called something along the lines of

viewProjection
modelViewProjection
worldViewProjection
mvp
wvp

etc.

But, that seems unintuitive given that GLSL, HLSL, and most math libraries seem to multiply in the opposite direction.

In other words

viewProjection = projection * view;  // correct but unintuitive

vs

viewProjection = view * projection;  // incorrect but naming matches order

It gets worse if you add in transpose or inverse since now the order of operations vs the order of parts of the name of the matrix make zero sense whatsoever. a worldViewProjectionInverseTranspose would be

transpose(inverse(projection * view * world))

Well you can read it backward but as far as order of operations and position in the expression its

5 ( 4 ( 1 * 2 * 3 ) )

Is there any objective reason for the names to be backward from the operations that construct them or is it just some naming convention that stuck from some example lost in obscurity?

I'm asking this question because being that it's unintuitive I find it's always hard to remember the order. If worldViewProjection equaled world * view * projection it would be easy since the name matches the order. I'm hoping there's some other objective reason that might help remember vs just remembering always multiply backward from the order of the parts of the commonly used names.

$\endgroup$
  • $\begingroup$ See code above. We are not multiplying by world first. Even if you have a matrix stack it's always projection first if you were to put it in the stack. Maybe in your mind we are but in code we are not. If you were to write a = b + c + d no one would describe that as adding d first $\endgroup$ – gman Jul 20 '16 at 3:43
  • 3
    $\begingroup$ Personally I would prefer more explicit naming conventions. For example: worldToScreen = worldToView * viewToScreen , or screenPosition = worldToScreen * worldPosition ... $\endgroup$ – wip Jul 20 '16 at 5:44
  • 2
    $\begingroup$ Can we just blame this on the fact we multiply right-to-left while reading from left-to-right ? $\endgroup$ – PaulHK Jul 20 '16 at 7:58
7
$\begingroup$

I think the naming order is intuitive because it is in reading order (left to right), e.g., worldViewProjection means that your point/direction is first multiplied by the world matrix, then the view matrix, and then the projection matrix. In this manner, you know the correct multiplication order by just reading the variable name and you do not have to think about mathematics at all. In your case, I think the problem is that your intuition seems to be focused on how you write the equations on paper or code.

The idea that a point is a column vector and matrices are multiplied on the left is also just a mathematical convention that you are used. You can use a row vector and multiply on the right by the transpose matrix, and the math is exactly the same, but would imply a reverse writing order in compound transformations. Some people just prefer one notation over the other.

I have read some old computer graphics books that use row vectors as points/directions, but it seems that most modern books have converged on using column vectors. IMHO, maybe this change during the years is one of the sources of confusion for so many new CG students.

For instance, if you choose to represent points as row vectors you would write something like this in your code: new_point = point * world * view * projection. On the other hand, if you use column vectors you would write this: new_point = projection * view * world * point. The important thing is that these matrices must not be the same, that is, the world matrix in the first code is the transpose of the world matrix in the second code, and the same is true for the others. As you can see, if you choose one math convention over the other, this will probably have influence on your naming conventions while writing your code.

$\endgroup$
6
$\begingroup$

The order is arbitrary, but if you want to be compatible with physics textbooks then your notation is mostly set. The difference is that you seem to think that its more natural to observe the systen on the outside (and for graphics pipe devs its often so, not for modeler). For a mathematician it is more natural to think from local coordinates out. There are several reasons for this but mathematician seem to want to reduce this to functional form if you were to transform a value x through multiple functions you would get:

$$ h(g(f(x))) $$

or sometimes

$$ (h \circ g \circ f)(x) $$

This quite literary means transform x to f to g to h. So it is natural for a mathematician/physicist and some programmers to read the operations inside out simplybbecause this ties in better with the notation you were teached in early calculus. This way your operational order matches also other branches of mathematical notation. Since most math and physics textbooks take this approach you probably should too.

The other reason is that your modeling elements lie on the outside of your data. But obviously you are free to transpose your vectors and then your order is opposite. It is up to you to define meaning to your math. This because there is a rule that follows from how matrices are defined that states:

$$ (A \cdot B)^T = B^T \cdot A^T $$

It is easily shown that longer chains just reverse the entire chain by recursing this forumula.

It is good to remeber that the order inside the vectors are arbitrary as well as calculation order. There is no reason for the vector to be defined in X, Y, Z, W order we could define the matrices and vectors in any order even a slightly cryptic X, W, Z, Y order. So rember the modeling convention is not somehow set in stone. Students would often want it to be, because that would mean not needing to understand as much, but it does not have to be. Matrices just enable you to model arbitrary vectors with unified math notation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.