about mWorldViewProj, help!~

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Nation
Posts: 4
Joined: Wed Feb 03, 2010 8:32 am
Location: China

about mWorldViewProj, help!~

Post 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~~
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post 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.
Nation
Posts: 4
Joined: Wed Feb 03, 2010 8:32 am
Location: China

Post 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~
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post 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 ) ) )
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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.
TheQuestion = 2B || !2B
Nation
Posts: 4
Joined: Wed Feb 03, 2010 8:32 am
Location: China

Post 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
Post Reply