rotating tank sprites using direct x and c++

Started by
1 comment, last by TacticalPenguin 15 years, 5 months ago
//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, &center, &position, D3DCOLOR_XRGB(255,255,255)); sprite_handler->Draw( tank_image[6], NULL, &center, &position, D3DCOLOR_XRGB(255,255,255)); } I am trying to rotate a tank sprite
Advertisement
And...?
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.

This topic is closed to new replies.

Advertisement