Sign in to follow this  
cozzie

Sprite offset after scaling...

Recommended Posts

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);

Edited by cozzie

Share this post


Link to post
Share on other sites

You've gotta be kinding me.... It was working all the time.

 

Guess what, I'm testing in windowed mode, where the say 5 or 10 pixels are used by the window border (I assume). Since it all works perfect in fullscreen.

Share this post


Link to post
Share on other sites
when you created your window did you use the AdjustWindowRect method? that will give you your screen with the borders and other window features accounted for.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this