Jump to content
  • Advertisement
Sign in to follow this  
nlraley

Sprite Rotation Question

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

I have a sprite that I need to rotate so I don't have to load up multiple textures and whatnot.

I have read that I need to define a transformation matrix for the sprite in order to do it. Similar to:
m_sprite->Begin(D3DXSPRITE_ALPHABLEND);

// Texture being used is 64 by 64:
D3DXVECTOR2 spriteCentre=D3DXVECTOR2(32.0f,32.0f);

// Screen position of the sprite
D3DXVECTOR2 trans=D3DXVECTOR2(50.0f,80.0f);

// Rotate based on the time passed
float rotation=timeGetTime()/500.0f;

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

D3DXVECTOR2 scaling(2.0f,2.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
m_sprite->SetTransform(&mat);

// Draw the sprite
m_sprite->Draw(m_texture,NULL,NULL,NULL,0xFFFFFFFF));

// Thats it
m_sprite->End();


However, I only want this particular sprite to be rotated, not all of them. So my question is, will this effect the other sprites as well, or should I create another instance of the LPD3DXSPRITE to handle the ones with the transformation matrix? Or should I use the same one and just reset the transformation matrix after I draw the sprites that need to be rotated, if so how? Or should I just use this transformation matrix like this and adjust the others accordingly.

I plan on having approximately 20 sprites that need to be rotated this way, but I don't want the sprites I use to compose my background to be affected or my sprite for my control to be affected. What would you guys recommend?

Share this post


Link to post
Share on other sites
Advertisement
I saw a reference to this post:
Quote:
http://www.gamedev.net/community/forums/topic.asp?topic_id=275443


Should I just call Sprite->Begin and End for each transformation of these? And use this formula:
D3DXMatrixRotationZ(&matRotation, (fDegrees * (D3DX_PI / 180)));

But replace the (fDegrees * (D3DX_PI / 180)) with the Degree of Rotation I need?

Or rather, use the:
Quote:
D3DXMatrixTransformation2D(&matRotation, NULL, NULL, NULL, &vCentre2D, (fDegrees * (D3DX_PI / 180)), &vPosition2D);


And set the values accordingly?

Share this post


Link to post
Share on other sites
Well I used the following and I rotate the sprite accordingly, but next call to render rotates everything else and messes up the map. Any idea how to reset the transformation matrix so this doesn't happen afterwards?

Share this post


Link to post
Share on other sites
Calling SetTransform afterwards passing NULLS appears to have fixed the issue.

Example:
D3DXMatrixTransformation2D(
&matRotation, // Pointer to the Matrix Structure
NULL, // Scaling Center
NULL, // Scaling Rotation
NULL, // Scale of the Image
NULL, // Rotation Center
NULL,
NULL // Location
);
hr = d3d9Sprite->SetTransform(&matRotation);
if ( FAILED(hr) )
return hr;

Share this post


Link to post
Share on other sites
Quote:
Original post by nlraley
Calling SetTransform afterwards passing NULLS appears to have fixed the issue.

Example:
D3DXMatrixTransformation2D(
&matRotation, // Pointer to the Matrix Structure
NULL, // Scaling Center
NULL, // Scaling Rotation
NULL, // Scale of the Image
NULL, // Rotation Center
NULL,
NULL // Location
);
hr = d3d9Sprite->SetTransform(&matRotation);
if ( FAILED(hr) )
return hr;
You could just use D3DXMatrixIdentity - a 2D transform with no rotation, scaling or translation is just an identity matrix after all.

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!