Sign in to follow this  

Coding Makes the Matworld Go 'Round

This topic is 4139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I've been following the coding in this book and basically it's going through a huge chapter all about graphics and I'm taking it slowly to take it piece by piece. Well while I was reading I was following along with my own code and comparing it to the code on the cd, while the CD has some extra stuff for the more advanced portions of the chapter what I have should work (I think). Basically all it is is a Verts[4] in a square list. I have my projection and view transformations in and put in a world transformation of 'matWorld'. I didn't do anything with the matWorld except declare it and run a SetTransform on it. This is the code the cd had:
D3DXMatrixRotationZ(&matWorld, (float)timeGetTime() / 1000.0f);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
I didn't want the MatrixRotation so I only had the SetTransform and my box didn't appear. I commented that single line out and bam the square appeared. Can anyone help clear up why nothing would show when I took out that code? Maybe explain a bit more about why it's required to code the three transformations instead of DX making a single function that does all of it for the programmer?

Share this post


Link to post
Share on other sites
Hello programmermattc,
D3DXMatrixRotationZ creates a matrix, so if you comment out that line you may have a empty matrix being passed into SetTransform (I could confirm this if you show me the code where matWorld is created).
This could be the reason your box isn't showing up.

Keep D3DXMatrixRotationZ commented, but try adding a new line above SetTransform:
D3DXMatrixIdentity(&matWorld);

Share this post


Link to post
Share on other sites
Thats what I was thinking too but I thought if it transformed a blank matrixthe program would error out. I had this a few lines above:
D3DXMATRIX matWorld;

Adding that Identity worked! Thanks! Any idea now why I wouldn't have to apply my other two transformations to the World so DX would understand how to render it in context? Is an Identity Matrix normally used for a world matrix if something like a rotation isn't used?

Share this post


Link to post
Share on other sites
"Maybe explain a bit more about why it's required to code the three transformations instead of DX making a single function that does all of it for the programmer?"

- Are you asking why there is a function for each rotation axis?
Probably because the programmer may want to rotate in different orders, also rotation through all axis is more expensive, but there are functions to do this; D3DXMatrixRotationYawPitchRoll and D3DXMatrixRotationAxis.

Share this post


Link to post
Share on other sites
An identity matrix is kind of like '1' for multiplication. Anything times 1 ='s the same number you had. Well anything times an identity matrix is the same matrix. So basically, you start with the identity matrix and then perform your transformations in the ordr you want. With a plain matrix you'd end up with multiplications against 0, and losing data. For comparison an 'empty' matrix would be:

0000
0000
0000
0000


whereas an identity matrix is

1000
0100
0010
0001

Share this post


Link to post
Share on other sites

This topic is 4139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this