Sign in to follow this  
wforl

rotation/translation

Recommended Posts

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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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