Sprite offset after scaling...

Started by
3 comments, last by cozzie 10 years, 8 months ago

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

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

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.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

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.

You can use the GetSystemMetrics with SM_CXFIXEDFRAME / SM_CYFIXEDFRAME to get the size of the borders and take that into calculation.

Thanks,I'll dig into it.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement