Sprite Rotation Question

Started by
3 comments, last by Evil Steve 13 years, 6 months ago
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 spriteD3DXVECTOR2 trans=D3DXVECTOR2(50.0f,80.0f);// Rotate based on the time passedfloat rotation=timeGetTime()/500.0f;// Build our matrix to rotate, scale and position our spriteD3DXMATRIX mat;D3DXVECTOR2 scaling(2.0f,2.0f);// out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translationD3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling,&spriteCentre,rotation,&trans);// Tell the sprite about the matrixm_sprite->SetTransform(&mat);// Draw the sprite m_sprite->Draw(m_texture,NULL,NULL,NULL,0xFFFFFFFF));// Thats itm_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?
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?
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?
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;
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.

This topic is closed to new replies.

Advertisement