• Advertisement
Sign in to follow this  

How to rotate a sprite using D3DXSprite

This topic is 4044 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
ID3DXSprite::SetTransform() allows you to specify a matrix to use as the sprite's world transform matrix.

To generate this matrix, use the D3DX function D3DXMatrixTransformation().

Share this post


Link to post
Share on other sites
If I am using the same sprite handler
//sprite handler
LPD3DXSPRITE sprite_handler;

will D3DXMatrixTransformation2D() take affect on both of them or just one?

Share this post


Link to post
Share on other sites
ID3DXSprite::SetTransform() will use the specified matrix for every ID3DXSprite::Draw() until SetTransform called again.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sc4Freak
ID3DXSprite::SetTransform() will use the specified matrix for every ID3DXSprite::Draw() until SetTransform called again.



I tryed it.


if (d3ddev->BeginScene())
{
//erase the entire background
d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE);

//start sprite handler
sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);

//draw the ball
position.x = 40;//(float)ball.x;
position.y = 100;//(float)ball.y;

sprite_handler->Draw(
ball_image,
NULL,
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));

// Texture being used is 64 by 64:
D3DXVECTOR2 spriteCentre=D3DXVECTOR2(45.0f,13.5f);
// Screen position of the sprite
D3DXVECTOR2 trans=D3DXVECTOR2(550.0f,200.0f);
// Rotate based on the time passed
float rotation=4.7;

// Build our matrix to rotate, scale and position our sprite
D3DXMATRIX mat;

D3DXVECTOR2 scaling(1.0f,1.0f);

// out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation
D3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling,&spriteCentre,rotation,&trans);

// Tell the sprite about the matrix
sprite_handler->SetTransform(&mat);

sprite_handler->Draw(
paddle_image,
NULL,
NULL,
NULL,
D3DCOLOR_XRGB(255,255,255));

//stop drawing
sprite_handler->End();

//stop rendering
d3ddev->EndScene();
}

//display the back buffer on the screen
d3ddev->Present(NULL, NULL, NULL, NULL);



so when I use SetTransform it changes all the sprites not just one that I want it to change.

How can I fix that?

Share this post


Link to post
Share on other sites
Quote:
Original post by Sc4Freak
Just before drawing your ball, try setting an identity matrix in SetTransform.


Doing that fixed the issue thanks for your help.
Just incase your wondering this is how I did it.

D3DXMATRIX mat;
D3DXMatrixIdentity(&mat);
sprite_handler->SetTransform(&mat);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement