Jump to content
  • Advertisement
Sign in to follow this  
Helderash

DirectX Rotation

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

Hey guys! I'm having a few problems with getting objects to rotate correctly in DirectX and I was wondering if anyone could fathom out where im going wrong. I'm currently working on a simple collision and response system for 2D circles (going to move up to 3D and spheres once its all working nicely). Everything was working correctly until implementing angular effects, and going through the maths there's no trouble there. My problem seems to be with the DirectX function call to rotate the object. At the moment Im using:
D3DXMatrixRotationZ(&matRotZ, (float)g_pBall.angle);
D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
Rather than objects rotating around their own origin, they seem to be rotating around the centre of the screen. Am I perhaps using the incorrect function call? Thankyou all for the help! James.

Share this post


Link to post
Share on other sites
Advertisement
I just thought it may be due to the way im combining world transformations, so the full code for that section is as below:


g_pD3DDevice->GetTransform(D3DTS_VIEW, &matView);
D3DXMatrixTranspose(&matTransposed, &matView);

D3DXMatrixTranslation(&matTrans, (float)g_pBall.XPos, (float)g_pBall.YPos, (float)g_pBall.ZPos);
D3DXMatrixMultiply(&matWorld, &matTrans, &matTransposed);
D3DXMatrixRotationZ(&matRotZ, (float)g_pBall.angle);
D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

Share this post


Link to post
Share on other sites
try replacing: "D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);" with

D3DXMatrixMultiply(&matWorld, &matRotZ, &matWorld);

Share this post


Link to post
Share on other sites
Quote:
MSDN
No matter what type of matrix you are creating, remember the left-to-right rule to ensure that you achieve the expected effects.


D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);


therefore should be:

D3DXMatrixMultiply(&matWorld, &matRotZ, &matWorld);


EDIT: beaten to it, yet again :-)

Share this post


Link to post
Share on other sites
Quote:
Original post by Todo
Quote:
MSDN
No matter what type of matrix you are creating, remember the left-to-right rule to ensure that you achieve the expected effects.


D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);


therefore should be:

D3DXMatrixMultiply(&matWorld, &matRotZ, &matWorld);


EDIT: beaten to it, yet again :-)


I believe you were beaten due to your use of custom quotes ;)

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!