# Problom With D3DXMatrixRotationY

## Recommended Posts

hello i got a problom with D3DXMatrixRotationY before i added the line of it everything worked fine and i saw what i wanted to see. now i dont see anything i think i killed the matrix O_o but thats only becuase i had no idea where to give the Rotation information to. here is the code:
void render( void )
{
g_pd3dDevice-&gt;Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

g_pd3dDevice-&gt;BeginScene();

D3DXMATRIX mWorld;
D3DXMatrixTranslation( &mWorld, 0.0f, 1.0f, v );
D3DXMatrixRotationY( &mWorld , 2);
g_pd3dDevice-&gt;SetTransform( D3DTS_WORLD, &mWorld );

g_pd3dDevice-&gt;SetStreamSource( 0, g_pTriangleList_VB, 0, sizeof(Vertex) );
g_pd3dDevice-&gt;SetFVF( D3DFVF_MY_VERTEX );
g_pd3dDevice-&gt;DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 4 );

g_pd3dDevice-&gt;EndScene();
g_pd3dDevice-&gt;Present( NULL, NULL, NULL, NULL );
}

can anyone tell me whats wrong here? thanks in advance Btw how do i make the Code to be in a BOX? i writed <source> but it doesnt seem to work O_o

##### Share on other sites
The rotation angle is in radians. 2 is almost 180 degrees.
D3DX has a couple of useful functions to convert from radians to degrees and back - D3DXToDegree() and D3DXToRadian() I think, I don't have the SDK with me here.

For source code, use [ source ] and [ /source ].

EDIT: Assuming you want to rotate and translate, you need to create 3 matrices. One to translate, one to rotate, and then one to do both:
D3DXMATRIX mTrans, mRot, mWorld;D3DXMatrixTranslation( &mTrans, 0.0f, 1.0f, v );D3DXMatrixRotationY( &mRot , D3DXToRadian(15.0f));D3DXMatrixMultiply( &mWorld, &mRot , &mTrams);g_pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld );

Bear in mind that the order of multiplication does matter though, since matrix multiplication isn't communative.

Edit2: What Jack said - D3DXToRadian (singular).

##### Share on other sites
Quote:
 Original post by mc30900Btw how do i make the Code to be in a BOX?i writed but it doesnt seem to work O_o
You need square brackets instead of angled brackets: [ source ] ... [ /source ]

As for your question, you're requesting a rotation of 2 radians - which is approximately 115 degrees. You might want to use D3DXToRadian() or D3DXToDegree() helper functions.

Also, your call to D3DXMatrixRotationY() is wiping out the results from D3DXMatrixTranslation(); if you want both transforms you want to use a temporary matrix and multiply the intermediary results together.

Also, depending on your vertex format you might be viewing the back-face after the rotation. Try setting D3DRS_CULLMODE to D3DCULL_NONE if you can't see anything.

hth
Jack

##### Share on other sites
yep, i know what are radians...
and 3.14 Radians are 180 degrees :P.
but you sure i did it right?
i think that the Veriable that needs to contain the Translate information now have only the Rotation information.
Can u give another look at it please?

##### Share on other sites
Quote:
 Original post by mc30900yep, i know what are radians...and 3.14 Radians are 180 degrees :P.but you sure i did it right?i think that the Veriable that needs to contain the Translate information now have only the Rotation information.
Take a look at my post (I edited it, probably while you were posting), and the source snippet there.

##### Share on other sites
Quote:
 Original post by Evil SteveThe rotation angle is in radians. 2 is almost 180 degrees.D3DX has a couple of useful functions to convert from radians to degrees and back - D3DXToDegree() and D3DXToRadian() I think, I don't have the SDK with me here.For source code, use [ source ] and [ /source ].EDIT: Assuming you want to rotate and translate, you need to create 3 matrices. One to translate, one to rotate, and then one to do both:*** Source Snippet Removed ***Bear in mind that the order of multiplication does matter though, since matrix multiplication isn't communative.Edit2: What Jack said - D3DXToRadian (singular).

umm i'm not sure i understand what u wrote.
1 for Translation
1 for Rotation
and the 3rd one is to combine both of them?

p.s Sorry for my bad english

##### Share on other sites
Yup. If you want to translate and rotate, then you need to build a translation matrix, build a rotation matrix, and then build a combined matrix from the translation and rotation combined.
In this case it does the rotation first, then the translation (rot*trans). You could also have the object "swing arond" the origin by going the translation then the rotation.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627741
• Total Posts
2978887

• 10
• 10
• 21
• 14
• 14