Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

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.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!