This topic is 5022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
thanks adriano_usp that was what i need.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633288
• Total Posts
3011222
• ### Who's Online (See full list)

There are no registered users currently online

×