Hi I am making a top-down 2D shooter in D3D.
So what I want to do is have my character rotate towards my mouse icons. So that means there are 2 vectors involved, pos and mousepos.
Now calculating the angle wasn't a problem but the problem comes when I try to rotate around my sprite towards the angle.
It rotates towards the right direction but when the sprite rotates it isn't stuck at it's position.
The center at which it is being rotated around looks to be the actual position, and this goes hand in hand with where it initially is drawn which also is wrong.
Lets say I paint it out at (10,10) (x,y) in pixels. Then I move it to (10,0). It is now outside of the picture but when I rotate it 180 degrees it is painted slightly below (10,0).
So I'm thinking that it is a logical error with my drawing function and would appreciate any additional insight.
This is how my drawing function looks like atm:
float fix_x = 0.5f;
float fix_y = fix_x;
Matrix transform, scaling, rotation, translation;
D3DXMatrixIdentity(& transform);
// fix for rotation
D3DXMatrixTranslation(& translation, -fix_x, -fix_y, 0);
transform = translation;
D3DXMatrixScaling(& scaling, Surf->getScaleRateX(), Surf->getScaleRateY(), 1.0f);
D3DXMatrixRotationZ(& rotation, D3DXToRadian(Surf->getRotationAngle() ));
transform = transform * scaling * rotation;
// move back after rotation
D3DXMatrixTranslation(& translation, +fix_x, +fix_y, 0);
transform = transform * translation;
// Translation
Vector2D hotspot = Surf->getHotspot(),
position = Surf->getPosition();
float x_Adjust = position.x,
y_Adjust = position.y;
D3DXMatrixTranslation(& translation, x_Adjust, y_Adjust, 0);
transform = transform * translation;
hr = m_Sprite->SetTransform(& transform);
if(FAILED(hr) )
{
m_lastError = hr;
return false;
}
hr = m_Sprite->Draw( Surf->getTexture(),
PartOfPicture,
& Surf->getHotspot(),
NULL,
D3DCOLOR_ARGB(Alpha, R, G, B) );
if(FAILED(hr) )
{
m_lastError = hr;
return false;
}
return true;