scaling image

Started by
3 comments, last by mark-w 18 years, 7 months ago
Hi all, I've created a small app to display 2d images. So far I have panning the image around the screen supported. I also have scaling the image from its center point supported too. Instead of simply scaling the image from its center point wherever it happens to lie in space, I would like to achieve the effect of scaling looking like I'm actually moving the 'camera' into the viewport. I thought I could achieve this by introducing a fudged pan offset in the x/y directions, so that when you're zooming in, the image is shifted in the x/y directions to look like you're really zooming in, not just scaling the image from its center point. Opengl does this beautifully, however I cannot use opengl, any ideas? Thanks
Advertisement
maybe its just me, but im not sure what you mean by scaling from the center point or any other point. Scaling is normally defined simply by a scalar, not a scalar and a point.

Maybe you could explain or give some screen shots of what you want from each...
Hi Dwiel,

First thanks for the response. I took some screen shots about what I'm talking about. The screen shots are really small, like 2k each.

The first screen shot shows the 2D viewport I set up. The red cross hair is the origin of my viewport. The yellow wireframe quad is the image. Its center point is green.

first one

Now the next screen shot shows that if I scale the quad, it gets scaled about its center point, which happens to be the viewport centerpoint as well here.

second one

Now if I had first translated the quad up to the left a bit...

third one

And now I scale, you can see its just simply scaling still around the quad center point.

fourth one

I would like instead to introduce some pan offset to make it appear as if I'm not really just scaling the quad, but moving into the viewport. So in this last screen shot, the quad should have perfectly increased along the two axes instead, since the camera movement should really just be zooming into the center point of the viewport.

fifth one

[Edited by - mark-w on September 8, 2005 11:45:41 PM]
You have to scale the translation as well.. so if you have panned with (10,10) and after that you scale by 2 then your new panning is (20,20).
Ok Winograd you got me the rest of the way. Scaling the transform was the key to getting the illusion down. I actually ended up *not* scaling the transform, but keeping two additional variables that would act as the difference between unscaled and scaled transforms, then added this onto the unaltered transform. Scaling the transform directly resulted in a snowball effect of rounding errors. This way when I scale up and down I always get back to the starting point from which I started the scale.

Thanks everyone, it looks awesome!

This topic is closed to new replies.

Advertisement