Original Post
I decided to write my own rotation function for my sprites in dx8, i cant manage to get it working, i use a textured square
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** //
// Description : m_SetRotation sets the angle of the sprite.
// Parameters : angle - the angle to rotate to.
// Return Values: none.
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** //
void CSpriteInstance::m_setRotation(float angle)
{
if(m_VB)
{
m_VB->Release();
m_VB = NULL;
}
//convert to rads
angle = angle * (D3DX_PI/180);
//center of the sprite X and Y
float center_x, center_y;
center_x = m_Vertices[1].x - (m_width/2);
center_y = m_Vertices[3].y - (m_height/2);
//calculate the hypot
float hyp = (squ(m_width/2) + squ(m_height/2));
hyp = sqrt(hyp);
m_Vertices[0].x = center_x - sin(angle) * hyp;
m_Vertices[0].y = center_y - cos(angle) * hyp;
m_Vertices[1].x = center_x + sin(angle) * hyp;
m_Vertices[1].y = center_y - cos(angle) * hyp;
m_Vertices[2].x = center_x + sin(angle) * hyp;
m_Vertices[2].y = center_y + cos(angle) * hyp;
m_Vertices[3].x = center_x - sin(angle) * hyp;
m_Vertices[3].y = center_y + cos(angle) * hyp;
//create the vertex buffer
pTemplate->pDevice->CreateVertexBuffer(4*sizeof(FVF2D), 0, FVF2D_FORMAT,
D3DPOOL_DEFAULT, &m_VB);
VOID* pVertices = NULL;
//lock and copy the square
m_VB->Lock(0, sizeof(m_Vertices), (BYTE**)&pVertices, 0);
memcpy(pVertices, m_Vertices, sizeof(m_Vertices));
//unlock
m_VB->Unlock();
}
[code]
I calculate the center of the sprite, then using pythagorams threum i calculate the lenght of the hypotenuse, I then use the center to calculate the new positions of each vertex.
this is the order of the vertices
topleft[0]
topright[1]
bottomright[2]
bottomleft[3]
Before anyone starts saying use matrices, then id like to say "no"
i dont want to use them, this way I will learn more
Thanks for your help in advance