Jump to content
  • Advertisement
Sign in to follow this  

directx rotation problem. please help

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

HI I need to rotate a gun which is in world coordinates in position (7.0f,5.0f,2.5f). I want to rotate it around center of the gun in world coordinates. when i use D3DXMatrixRotationAxis(...) it rotates my gun around a vector which starts from origin in world coordinates and ends to the vector i gave it.I looked at the D3DX functions and i couldn't find anything. THX in advance.

Share this post

Link to post
Share on other sites
You need to compose the transformations: That is, first you translate the gun to origin, after you rotate the gun and then you translate it to original position.

D3DXMATRIXA16 matR, matT1, matT2;

// Translate the gun to origin
D3DXMatrixTranslation( &matT1, -7.0f, -5.0f, -2.5f );

// Rotate the gun around Axis
D3DXMatrixRotationAxis( &matR, &Axis, angle );

// Translate the gun to original position
D3DXMatrixTranslation( &matT2, 7.0f, 5.0f, 2.5f );

matR = matT1 * matR * matT2;

pDev->SetTransform( D3DTS_WORLD, &matR );
// render the gun

Just complementing:
A vector is a set of oriented segments. Since a vector is defined by subtraction of 2 points, the oriented segments:
s1 = (10,10,10) - (0,0,0)
s2 = (18,18,18) - (8,8,8)
s3 = (102,102,102) - (92,92,92)
represent the same vector: v = s1 = s2 = s3 = ... = (10,10,10)
So, when a vector is expressed in relation to a coordinate system, it always starts from the origin. This is the reason why the rotations are computed around a axis that starts from the origin.

[Edited by - adriano_usp on February 12, 2005 10:06:15 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!