Sign in to follow this  
savail

Scaling image from the center of it

Recommended Posts

Hey,
Atm I'm scaling my sprite in this way:
[code] D3DXVECTOR2 position( pos_x, pos_z );
D3DXVECTOR2 scaling(Tex_scale_x,Tex_scale_y);
D3DXMATRIX mat;
D3DXMatrixTransformation2D(&mat, NULL, 0.0,&scaling,NULL,NULL,NULL);
Sprite->SetTransform(&mat);

Sprite->Draw(Texture, &rct, NULL, &pos, 0xFFFFFFFC);

D3DXMatrixIdentity(&mat);
Sprite->SetTransform(&mat);
if(Tex_scale_x < 1) Tex_scale_x+=0.1;
if(Tex_scale_y < 1) Tex_scale_y+=0.1;[/code]
I want to achieve a visual effect, very known and common - that an image from 0*0 size grows to its normal size very quickly. And the code above does what it was supposed everything is rendered from the left up corner and that's why only right and bottom part of image coordinates increase. Is such visual effect that sprite grows in all directions from 0*0 size to its normal size possible to achieve?

Share this post


Link to post
Share on other sites
I am finding your question difficult to understand. You want to know if it is possible to scale an image? By scaling, I mean increasing its size? Isn't that what you are already doing?

What exactly are you trying to accomplish?The code in your posts shows that you know how to scale an image, so what other type of scaling are you trying to do?
You know how to scale something to (0, 0), you know how to scale something to (.5, .5) What other information do you need?

Share this post


Link to post
Share on other sites
heh :P, sorry for that. What I want to achieve is a visual effect by the means of scaling. I want to grow image from 0*0 size to its original size. The scaling starts from the left top corner of image so left top corner of this image whatever the scale value is, remains with same coordinates. only right, bottom and right-bottom corner's coordinates change. That's becouse the centre of scaling is left top corner and I want to scale the image in all 4 directions so that all 4 corners change their coordinates (left part of image grows in left, right grows in right, down in down, up in up direction). I hope It's clearer :P

Share this post


Link to post
Share on other sites
You want the images top left corner to remain static while the image increases in scaling?

Easy enough. simply move the image before you preform the scaling to correct location, then preform the scaling.

For example, if the image is 40x40, and you want the top left corner of the image to remain at the screen position 100,100.

First move the images top left corner to 100,100. You know the size of the image 40 x 40, and you know moving an image moves its center. SOOO

the center of the image is 20x20, which you get by dividing the dimensions in half. So, to move the image to 100,100, simply move the image to 120,120. This will place the images top left corner at 100,100

Now, if you are scaling this, you have to a little bit more work.

Say, you scale the image by 1/4 on each dimension, meaning, the total size of the image is now, 40 * 1/4 = 10. So, 10x10
The center of the image is now, 10/2 = 5. So the center of the image is 5,5, simply add this onto 100,100, to get 105,105 as your new position to move the image to if the scaling is 1/4

I did not write it out completely using a bunch of math formulas, because its not that difficult.

That work for you?

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