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~~
about mWorldViewProj, help!~
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.
here id the code in HLSL base tutorial:
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~
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);
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 ) ) )
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 ) ) )
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:
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.
Code: Select all
// D3D
v' = v * World * View * Projection
// OpenGL
v' = Projection * View * World * v
TheQuestion = 2B || !2B