Sign in to follow this  

ID3DXSprite scaling question

This topic is 4090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working on a RTS game where the player can scroll around the world by moving the window. If I leave the scale set to 1.0f everything works perfectly, but when I scale the buildings to 0.5f or anything for that fact they seem to wander with the movement of the window. My question is how do determine the screen coordinates of a texture that has been scaled. I am basically keeping up with the current viewport location and modifying each object based on the window's position. I have to double the win.left and win.top coordinates to make a scale of 0.5f work, but when I have it set to a scale of 1.0f I don't have to modify anything. It could have something to do with the way I am scaling the building
	D3DXMATRIX temp;
	D3DXVECTOR2 scale(0.5f,0.5f);
	D3DXMatrixTransformation2D(&temp, NULL,0.0f,&scale, NULL, 0.0f, NULL);
	g_engine->GetSprite()->SetTransform(&temp); 

Thanks in advance for any tips

Share this post


Link to post
Share on other sites
The Sprite's screen location is also scaled by the same transformation matrix. That means that if you're are scaling by a factor of 0.5, and you want to Sprite to be at location X, you need to divide it by the scaling factor: newX = oldX / 0.5. This is then scaled by the scale factor, which is 0.5, and is thus eliminated, leaving the actual position the Sprite is drawn to as X.

Since you're using a 2D transformation matrix, you probably won't have to scale the Z value at all.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
The Sprite's screen location is also scaled by the same transformation matrix. That means that if you're are scaling by a factor of 0.5, and you want to Sprite to be at location X, you need to divide it by the scaling factor: newX = oldX / 0.5. This is then scaled by the scale factor, which is 0.5, and is thus eliminated, leaving the actual position the Sprite is drawn to as X.

Since you're using a 2D transformation matrix, you probably won't have to scale the Z value at all.

Hope this helps.


That makes a lot of sense!

Thank you


Share this post


Link to post
Share on other sites

This topic is 4090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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