Jump to content
  • Advertisement
Sign in to follow this  
zyrolasting

Sprite Rotation? (DirectX 9 C++)

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

Advertisement
If by DirectX you mean Direct3D, it depends how you are drawing sprites.

If you are using ID3DXSprite, you set a transform with ID3DXSprite::SetTransform prior to calling ID3DXSprite::Draw which allows you to specify the centre point.

If you are using an orthagonal projection, you can define your sprite vertices in local space around the centre, then multiply a rotation by a transformation to create the matrix to set the world transform before your render.

If you are using textured quads and pretransformed vertices, you need to manually rotate the vertices yourself with sin() and cos() prior to drawing.

If by DirectX you mean DirectDraw, hardware support for sprite rotating is limited. There are methods to do this but you need to check at runtime to see if it is supported. If not, your only option would be to rotate and draw the pixels manually by locking the buffer, which would be slow.

Share this post


Link to post
Share on other sites
This is my code to rotating projectiles:


D3DXMATRIX matRotate;
D3DXVECTOR2 vCenter(16.0f, 16.0f);
D3DXVECTOR2 vPosition(position.x, position.y);

D3DXMatrixTransformation2D(&matRotate, NULL, NULL, NULL, &vCenter, angle, &vPosition);
d3dspt->SetTransform(&matRotate);

d3dspt->Draw(artManager.getProjectile(iter->artId)->texture, NULL, NULL, NULL, fullColor);

D3DXMatrixRotationZ(&matRotate, 0);
d3dspt->SetTransform(&matRotate);



Position points to a vector of the location in screen coordinates of where you want the texture to be drawn at (after rotation), and put into vPosition

vCenter is the center of the texture (size is 32x32)

angle is a float for the angle in radians.

d3dspt is my sprite object.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!