Sign in to follow this  

directx rotation problem. please help

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

This topic is 4687 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this