Does this code look right for centering an image on the screen (in this case a chess board):
int Chess::Board::Center(int width,int height)
{
if(m_texture == NULL)
return 0;
D3DXVECTOR2 center;
center.x = (float)width/2.0f;
center.y = (float)height/2.0f;
m_position.x = center.x - (m_texture->GetWidth())/2;
m_position.y = center.y - (m_texture->GetHeight())/2;
return 1;
}
Chess is a namesapce, Board is a class, and Center is a method of Board.
width and height are the width and height of the screen, and m_position is a 2-coordinate vector (D3DXVECTOR2, for any DirectX people) containing the coordinates of where the upper-left hand corner of the image is.
m_texture is a pointer to a Texture, a wrapper class for the IDirectTexture9 interface.
Any ideas? The board isn't centered when I run the program.