directx rotation problem. please help

Started by
1 comment, last by ehsan_the_tiamat 19 years, 2 months ago
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.
Advertisement
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]
thanks adriano_usp that was what i need.

This topic is closed to new replies.

Advertisement