Sign in to follow this  

rotating tank sprites using direct x and c++

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

//start rendering if (d3ddev->BeginScene()) { //erase the entire background d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE); //start sprite handler sprite_handler->Begin(D3DXSPRITE_ALPHABLEND); D3DXMATRIX mat; // D3DXMatrixTransformation2D(&mat,NULL,NULL,NULL,NULL,D3DXToRadian(-45.0),NULL); //create vector to update sprite position D3DXVECTOR3 position((float)tank.x, (float)tank.y, 0.0); D3DXVECTOR3 center((float)0, (float)0, 0.0); // d3ddev->SetTransform(D3DTS_WORLD,&mat); // sprite_handler->SetTransform(&mat); //draw the sprite for (int j=0;j<=1000;j++) { // D3DXMatrixRotationZ(&mat,0.0); sprite_handler->Draw( tank_image[0], NULL, ¢er, &position, D3DCOLOR_XRGB(255,255,255)); sprite_handler->Draw( tank_image[6], NULL, ¢er, &position, D3DCOLOR_XRGB(255,255,255)); } I am trying to rotate a tank sprite

Share this post


Link to post
Share on other sites
and he wants help.

I haven't done much with directX but my general concept to it is use trig (sin+cos) in conjunction with the rotation angle of the tank to find the 4 corners of the image. When rotation = 0, the 4 corners would be (-(w/2),-(h/2)) ((w/2),-(h/2)) ((w/2),(h/2)) and (-(w/2),(h/2)) where 0,0 is the center of the tank.

Then based on rotation figure out how to calculate where the corners should be. If the tank is a 32x32 sprite, the topleft corner should, with a 45 degree rotation, move to (-sqrt(512),0)

Just think it through and youll come up with the method to calculating the position of the corners. Then using those positions you can render the sprite wherever however you want.

Share this post


Link to post
Share on other sites

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