Jump to content
  • Advertisement
Sign in to follow this  
guywithknife

OpenGL Quick and simple question

This topic is 4876 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

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.

Share this post


Link to post
Share on other sites
Advertisement
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].

Share this post


Link to post
Share on other sites
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 matrix
D3DXMatrixIdentity(&matrix);

// Do rotation for object 2
D3DXMatrixRotationY(&matrix, timeGetTime() / 1000.0f);
pID3DDevice->SetTransform(D3DTS_WORLD, &matrix);

// Draw object 2


Thanks for the reply!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!