Sign in to follow this  

Scaling Matrix Scales position of sprite also?

This topic is 3098 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

Hi, in this situation I'm trying to apply a scaling matrix to sprite in the following order. Compute Scale Matrix Sprite->Begin Sprite->SetTransfor(Matrix) Sprote->Draw Sprite->End But the problem is that when I set the position of the sprite in the Draw call and apply the matrix, the position vector gets scaled also. For example: I have a matrix that does X axis * 4, Y axis * 0.5, Z axis * 1. And lets say I pass in a position as x = 100, y = 200. The sprite wouldend up at position 400, 50. How can I prevent that from happening? Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by programci_84
Hi,

Are you using D3DXMatrixTransformation2D () for that? If not, I recommend you to build your sprite's transformation matrix with this.


Ok, I tried it, but similar results. Any other ideas?


P.S Well technically I solved it by changing the position so that when it's scaled would give me the actual position I want. So lets say I want X to be 100 and my scaling factor is 1.5, I would make X 50, which would make it appear as thought its 100 after scaling. But are there any other less crude methods?

Share this post


Link to post
Share on other sites
Hi,

If you multiply your original matrix with a scale matrix that's been built up with D3DXMatrixScaling(), position data of the result matrix will be shifted as well.

So, I recommend you to use D3DXMatrixTransformation2D(). Change your code like this:
D3DXMATRIX spriteTransformation;
//assume XScaleFactor, YScaleFactor, XPos and YPos are defined for scaling and translating
D3DXVECTOR2 myScaleFactor (XScaleFactor, YScaleFactor);
D3DXVECTOR2 myTranslation (XPos, YPos);
D3DXMatrixTransformation2D (&spriteTransformation, NULL, 0, &myScaleFactor, NULL, 0, &myTranslation);

//...
Sprite->Begin(...);
Sprite->SetTransform (&spriteTransformation);
Sprite->Draw (...);
Sprite->End ();



Hope this helps.

Share this post


Link to post
Share on other sites
Just to expand on programci_84. The order of operations is commutative (the result differs for different orderings) so a translation followed by a scaling will not provide the correct results where a scaling followed by a translation will.

If you had an object with a matrix (so it already contains position, orientation, etc..) that you wanted to apply scaling to you would first need to translate it to the origin, apply the scaling matrix and translate back to its original position to make sure you don't move it when scaling.

To learn more you might want to read about linear transformations.

Share this post


Link to post
Share on other sites

This topic is 3098 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