Sign in to follow this  
zyrolasting

Sprite Rotation? (DirectX 9 C++)

Recommended Posts

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

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