Public Group

# rotating tank sprites using direct x and c++

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

## 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

And...?

##### 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.

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

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013758
×