This is giving me trouble, and I can't figure out any logical reason why it works one way and won't work the other.
This way works:
In WinMain(), I declared the following variables:
Code:
D3DXMATRIX matRotationX, matRotationY, matRotationZ, matTranslation;
Those are the matrices to take coordinates from object space and convert them to world space. So, of course, in my DirectX loop I have the following calls:
Code:
D3DXMatrixRotationX(&matRotationX,g_Transform.GetXRotation());
D3DXMatrixRotationY(&matRotationY,g_Transform.GetYRotation());
D3DXMatrixRotationZ(&matRotationZ,g_Transform.GetZRotation());
D3DXMatrixTranslation(&matTranslation,g_Transform.GetXTranslation(),
g_Transform.GetYTranslation(),g_Transform.GetZTranslation());
g_App.GetDevice()->SetTransform(D3DTS_WORLD,&(matRotationX*matRotationY*matRotationZ*matTranslation));
g_App is a global instance of my CApplication class, which basically just handles initializing a window and direct3D, and then initializing the scene (render states, and temporarily, lighting).
g_Transform is a global instance of my CTransformation class. In the version that works, it just contains the following variables and methods for setting/getting each of them (should be self-explanatory)
Code:
float fRotationX,fRotationY,fRotationZ,
fTranslationX,fTranslationY,fTranslationZ;
That works great. The only problem is that it's going to turn into a mess down the line if I handle those matrices in WinMain(), as soon as I get more than one primitive and they need to be transformed differently.
So, I wanted to put the matrices in the CTransformtion class, and have the class keep them updated when the rotation/translation variables are changed, and just have WinMain call a method of CTransform which would return the world matrix.
I coded that in, with a bunch of methods that look like this:
Code:
float CTransformation::ChangeXRotation(float fDeltaX)
{
fRotationX+=fDeltaX;
D3DXMatrixRotationX(&matRotationX, fRotationX);
return fRotationX;
}
and then
Code:
D3DXMATRIX* CTransformation::GetWorldTransform(void)
{
return &(matRotationX*matRotationY*
matRotationZ*matTranslation);
}
I changed WinMain() in the appropriate places to reflect the changes to the CTransformation class, and it compiled without error, but when I executed it, the primitive was no longer displayed. Switching WinMain() back to the original version makes it work again, so I think the problem must lie either in the new code in the CTransformation class, or there is something within DirectX that explains it. Any ideas? I'm going to try sticking all the calls which change a matrix between BeginScene() and EndScene() calls and see if that does anything... just thought of that. If it works, I'll post again with a "nevermind" Comments about any inefficiencies you see with what I just said would be appreciated though.
edits: formatting the code to require less scrolling on the board