Page 1 of 1

about mWorldViewProj, help!~

Posted: Sun Feb 07, 2010 9:24 am
by Nation
usually, we make the mWorldViewProj by matWorld * matView * matPro,
but I find the project 10.Shaders, here mWorldViewProj is made by matPro * matView * matWorld, why???when i modify the mWorldViewProj by matWorld * matView * matPro, i can't see anything in my screen, thanks~~

Posted: Sun Feb 07, 2010 4:18 pm
by DavidJE13
I believe that matPro * matView * matWorld is the correct order. Matrix multiplication says that AB is A applied to B, so in this case that is the world transform followed by the view transform followed by the projection. Reversing them puts projection first, so you have a flat world before doing rotation & translation, which will obviously fail.

Posted: Mon Feb 08, 2010 2:12 am
by Nation
here id the code in HLSL base tutorial:

Code: Select all

    D3DXMATRIX matWorld, matView, matProj;
    g_pd3dDevice->GetTransform(D3DTS_WORLD, &matWorld);
    g_pd3dDevice->GetTransform(D3DTS_VIEW, &matView);
    g_pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProj);
    D3DXMATRIX matWVP = matWorld * matView * matProj;
   BasicConstTable->SetMatrix(g_pd3dDevice, WVPMatrixHandle, &matWVP);
this is not your order, when i start study D3D, i see if you want a object first rotate in it's local coordinate, then translate int to world, you must calculate matRotate and matTrans, the final world transform is matRotate * matTrans, it's also means matrix multiply, the final effect is from left to right, i'm blurred now, can't determine which is right, thank you, wait for more reply~

Posted: Mon Feb 08, 2010 3:08 am
by DavidJE13
My matrix math is a little rusty, so I may be wrong here, but;

That should only work if the final calculation is position = vector * matrix whereas the normal way (that I know) is position = matrix * vector. Maybe the method you posted is more widely used, and if that's the case then you can simply swap the multiplication order in the shader to get it in the order you like (swap both the final matrix construction and the vector multiplication).
In any case, I prefer the position = matrix * vector form because it can be thought of as functions; projection( view( world( position ) ) )

Posted: Mon Feb 08, 2010 4:38 am
by Halifax
Yes, it's a fundamental difference between OpenGL and Direct3D. Direct3D does post-multiplication of row-major matrices while OpenGL does pre-multiplication of column-major matrices:

Code: Select all

// D3D
v' = v * World * View * Projection
// OpenGL
v' = Projection * View * World * v
Irrlicht follows the OpenGL route. It may be confusing, but if you work it out on paper then it will become more clear. Both methods produce the exact same results.

Posted: Tue Feb 09, 2010 11:27 am
by Nation
thanks you~~here is the note of irr::core::CMatrix4 in Irrlicht

//! 4x4 matrix. Mostly used as transformation matrix for 3d calculations.
/** The matrix is a D3D style matrix, row major with translations in the 4th row. */

maybe it's a clerical error~ :D