Hi. I initially started up a thread at the Game Dev. section of the forums but it seems rather dead so I thought I'd try my luck here.
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. So I calculate the angle and then rotate the sprite towards the mousepos. It rotates towards the right direction but when the sprite rotates it isn't centered.
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).
I initially create my texture with the D3DXCreateTextureFromFileEx function with width and height at D3DX_DEFAULT_NONPOW2 so that isn't something causing the off-centre behaviour.
So I'm thinking that it is a logical error with my drawing function and would appreciate any additional insight.
I tried different ways of doing the Matrix such as D3DXTransformation2D function aswell as moving it before rotation/scaling and moving it back to finally move it where it belongs.
This is how my drawing function looks like atm:
Matrix transform, scaling, rotation, translation;
D3DXMatrixIdentity(& transform);
D3DXMatrixScaling(& scaling, Surf->getScaleRateX(), Surf->getScaleRateY(), 1.0f);
D3DXMatrixRotationZ(& rotation, D3DXToRadian(Surf->getRotationAngle() ));
Vector2D hotspot = Surf->getHotspot(),
position = Surf->getPosition();
float x_Adjust = position.x + hotspot.x,
y_Adjust = position.y + hotspot.y;
D3DXMatrixTranslation(& translation, position.x, position.y, 0);
transform = scaling * rotation * 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;