# rotation/translation

## Recommended Posts

wforl    169
im current trying to implement a bullet being fired from the position of the player, at the moment im simply using Transform = translation * rotation; such that when the bullet is fired, it increments in z, by a velocityZ, and then rotates by the players rotation, (360degs being a full spin). but this obviously only works while the player is at 0,0,0 pos, as the y rotation is gonna be always applied on the 0,0,0 axis.
if (this->alive == true)	//if the current bullet is alive, then update
{
D3DXMATRIX translation;
D3DXMATRIX scale;
D3DXMATRIX rotation;
D3DXMatrixIdentity(&rotation);
D3DXMatrixTranslation(&translation, pos.x, pos.y, pos.z += velocityZ);      //pos equals the position that bullet was fired, and stays at this value, until fired again, where a new position is added
D3DXMatrixRotationY(&rotation, rot.y);

//Transform =  rotation * translation;
Transform =  translation * rotation;
}

so, how would i rotate the bullet, in Y, but on the bullets initial position?

##### Share on other sites
haegarr    7372
D3D uses row vectors, so
translation * rotation
means to translate the bullet and to rotate the translated bullet. However, looking at the matrix math, this means not only to change the orientation of the bullet but also its position. So, what you want to do is
rotation * translation
instead. This changes the orientation and translates the rotated bullet to its target position.

You should decouple the bullet from the shooter when the bullet gets instantiated. I.e. set its initial position (i.e. translation in world co-ordinates) to that of the shooter, and set its velocity also in world co-ordinates.

##### Share on other sites
wforl    169
ok cheers, i was thinking about it kinda wrong, i was hoping to just translate in z, but while the bullet is rotated, thus it moving in x an z.

so, with the way you suggested, im gonna have to apply the veclocity to both x and z position, i guess incorporating the bullets initial yrotation when fired.

hmm, i'll have to work that out