Skip to main content
gamedev.net
🔒 Locked

Quick and simple question

Started by guywithknife Feb 16, 2005 at 1:23 PM 3 replies 1k views
Original Post
guywithknife
guywithknife
Just a quick DirectX Graphics question: Someone has asked me how to rotate say two objects independantly. I have no experience with DirectX, so have no idea. I suggested the OpenGL approach, but dont really know how to convert it to DirectX code. So, if someone could paste a small code snippet of how to do this, it would be greatly appreciated. Thanks in advance! PS: I have already done a google search, but all the rotation tutorials I found only showed how to rotate a single object.
rjackets
rjackets
You need to change the world matrix for each new transform. So, set up matrix for object 1, draw object 1, set up matrix for object 2, draw object 2

Information on DirectX matrices are fairly easy to find. The ones I mostly use for object transforms are Scaling(), RotationYawPitchRoll(), and Translation() -- Usually in that order too [wink].
guywithknife
guywithknife
Yes, thats pretty much what I was thinking. So, would something like this do it:

D3DXMATRIX matrix;D3DXMatrixRotationY(&matrix, timeGetTime() / 1000.0f);pID3DDevice->SetTransform(D3DTS_WORLD, &matrix);// Draw object 1 // Reset the matrixD3DXMatrixIdentity(&matrix); // Do rotation for object 2D3DXMatrixRotationY(&matrix, timeGetTime() / 1000.0f);pID3DDevice->SetTransform(D3DTS_WORLD, &matrix);// Draw object 2


Thanks for the reply!
rjackets
rjackets
That will work just fine. You dont actually need to reset the matrix after you do the first draw. When you set it to the second one it will just overwrite it anyway, so the reset is unnecessary. Probably wont give you too much trouble if you keep it, but the fastest code is the code that is never executed [wink]

Good luck.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.