Original Post
Ok I have been here before asking about rotation of sprites in 2D, I got some great suggestions and I took a long break and now I jumped back into it and got a rotation of my sprite and it rotates perfectly. Now my acceleration wont accelerate in the direction I am facing, anyone got an idea on how to resolve this without me ending up taking a long break again and coming back to it?? Here is my code
LPDIRECT3DTEXTURE9 sprite_image;
SPRITE image;
LPD3DXSPRITE sprite_handler;
image.position.x = 500.0f;
image.position.y = 600.0f;
image.position.z = 0.0f;
image.direction.x = 0;
image.direction.y = 0;
image.speed.x = 0.0f;
image.speed.y = 0.0f;
image.SPRITE_SPEED = 1;
image.MOVE_UP = -1;
image.MOVE_DOWN = 1;
image.MOVE_LEFT = -1;
image.MOVE_RIGHT = 1;
static float xrot = 0.0f;
static float yrot = 0.0f;
static float zrot = 0.0f;
if (GetTickCount() - start >= 30)
{
//reset timing
start = GetTickCount();
if(KEY_DOWN(VK_UP))
{
image.speed.y += image.SPRITE_SPEED;
image.direction.y = (float)image.MOVE_UP;
if(image.speed.y >= 8.0f)
image.speed.y = 8.0f;
}
else if(KEY_DOWN(VK_DOWN))
{
image.speed.y -= 0.20f;
if(image.speed.y <= 0)
image.speed.y = 0;
}
if(KEY_DOWN(VK_LEFT))
{
zrot -= 5.0f;
}
else if(KEY_DOWN(VK_RIGHT))
{
zrot += 5.0f;
}
image.position.y += image.direction.y * image.speed.y;
}
//start rendering
if (d3ddev->BeginScene())
{
//erase the entire background
d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE);
//start sprite handler
sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
D3DSURFACE_DESC desc;
sprite_image->GetLevelDesc(0, &desc);
const int centerX = desc.Width >> 1;
const int centerY = desc.Height >> 1;
D3DXMATRIX rotate, trans, scale, result;
D3DXMatrixIdentity(&result);
D3DXMatrixTranslation(&trans, (float)-centerX, (float)-centerY, 0);
D3DXMatrixMultiply(&result, &result, &trans);
D3DXMatrixScaling(&scale, 1, 1, 1);
D3DXMatrixMultiply(&result, &result, &scale);
D3DXMatrixRotationZ(&rotate, D3DXToRadian(zrot));
D3DXMatrixMultiply(&result, &result, &rotate);
D3DXMatrixTranslation(&trans, (float)+centerX, (float)+centerY, 0);
D3DXMatrixMultiply(&result, &result, &trans);
D3DXMatrixTranslation(&trans, image.position.x, image.position.y, 0);
D3DXMatrixMultiply(&result, &result, &trans);
sprite_handler->SetTransform(&result);
sprite_handler->Draw(sprite_image, NULL, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255));
//stop drawing
sprite_handler->End();
//stop rendering
d3ddev->EndScene();
}