Hi,
I'm trying to draw some simple sprites 'on top' of my 3d scene (sort of HUD idea).
But I've been struggling about 2 hours on the following:
- when the scale is 1.0f, the position is as expected.
I pass a screen position X/Y, of which I expect it to be the top left corner of the sprite
- when I take a lower scale, the scaling works, but the position is somehow altered too.
I suspect this is because of the scalingcenter
Conclusion; the more I adjust the scale, the more the sprite 'moves' on the screen.
Or better explained: the given pX and pY are no longer the resulting screen positions of the top left corner of the sprite.
I've been calculating and trying to find the equation to find out what's happening, but no success yet.
Do you have any idea?
Here's the code:
D3DXVECTOR2 trans((float)pX, (float)pY);
D3DXVECTOR2 spritecenter((float)(mWidth * mDefaultScale.x / 2.0f), (float)(mHeight * mDefaultScale.y / 2.0f));
D3DXMATRIX mat;
D3DXMatrixTransformation2D(&mat, &D3DXVECTOR2(0.0f, 0.0f), 0.0f, &mDefaultScale, &spritecenter, DEGTORAD(pRotationDeg), &trans);
// set matrix and draw sprite
mSpriteObj->SetTransform(&mat);
mSpriteObj->Draw(mTexture, NULL, NULL, NULL, mDefaultColor);